Skip to content

Commit

Permalink
Merge pull request #1093 from dsalaza4/main
Browse files Browse the repository at this point in the history
feat(build): #1092 test pull request builtin
  • Loading branch information
dsalaza4 authored May 24, 2023
2 parents 726a521 + a78216b commit b643ebd
Show file tree
Hide file tree
Showing 11 changed files with 2,546 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,27 @@ jobs:
- name: /tests/secretsForGpgFromEnv
run: nix-env -if . && m . /tests/secretsForGpgFromEnv

linux_testPullRequest_default:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@f095bcc56b7c2baf48f3ac70d6d6782f4f553222
- uses: docker://docker.io/nixos/nix@sha256:c3db4c484f6b1ee6c9bb8ca90307cfbeca8ef88156840911356a677eeaff4845
name: /testPullRequest/default
with:
set-safe-directory: /github/workspace
args: sh -c "nix-env -if . && m . /testPullRequest/default"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
macos_testPullRequest_default:
runs-on: macos-latest
steps:
- uses: actions/checkout@f095bcc56b7c2baf48f3ac70d6d6782f4f553222
- uses: cachix/install-nix-action@67e9fd765dbe63fabe0ce2bd72f56f9a417696a0
- name: /testPullRequest/default
run: nix-env -if . && m . /testPullRequest/default
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

linux_testTerraform_module:
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ David Arnold <david.arnold@iohk.io> David Arnold <dgx.arnold@gmail.com>
Diego Restrepo <drestrepo@fluidattacks.com> Diego Restrepo Mesa <36453706+drestrepom@users.noreply.github.com>
Diego Restrepo <drestrepo@fluidttacks.com> Diego Restrepo <drestrepo@fluidttacks.com>
Diego Restrepo <restrepomesadiego@gmail.com> Diego Restrepo Mesa <36453706+drestrepom@users.noreply.github.com>
Elver Tobo <elvertobo2017@gmail.com> Elver Tobo <elvertobo2017@gmail.com>
Fluid Attacks <help@fluidattacks.com> Fluid Attacks <help@fluidattacks.com>
Github Dependabot <49699333+dependabot[bot]@users.noreply.github.com> dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Github Octocat <noreply@github.com> GitHub <noreply@github.com>
Expand Down
61 changes: 61 additions & 0 deletions docs/src/api/builtins/test.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,64 @@
## testPullRequest

Test a pull request
on any of the [supported platforms](https://danger.systems/js/guides/getting_started.html#setting-up-danger-to-run-on-your-ci)
using [Danger.js](https://danger.systems/js/guides/getting_started.html).

For more information
on how to use Danger.js,
please refer to its
[Gettings started guide](https://danger.systems/js/guides/getting_started.html).

Types:

- testPullRequest:
- modules (`attrsOf moduleType`): Optional.
Danger configurations to use.
Defaults to `{ }`.
- moduleType (`submodule`):
- dangerfile (`path`):
Path to a Javascript or Typescript dangerfile.
- extraArgs (`listOf str`):
Extra arguments to pass
to the danger executable.
- setup (`listOf package`): Optional.
[Makes Environment](./environment.md)
or [Makes Secrets](./secrets.md)
to `source` (as in Bash's `source`)
before anything else.
Defaults to `[ ]`.

Example:

=== "makes.nix"

```nix
{
testPullRequest = {
modules = {
github = {
dangerfile = projectPath "/dangerfiles/github.ts";
extraArgs = [
# Extra arguments for my dangerfile
"--config"
"strict"
];
};
gitlab = {
dangerfile = projectPath "/dangerfiles/gitlab.ts";
};
};
};
}
```

=== "Invocation"

```bash
$ m . /testPullRequest/github
```


## testPython

Test Python code
Expand Down
15 changes: 15 additions & 0 deletions makes.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
fetchNixpkgs,
fetchUrl,
inputs,
outputs,
projectPath,
Expand Down Expand Up @@ -278,6 +279,20 @@
src = "/src/cli";
};
};
testPullRequest = {
modules = {
default = {
dangerfile = fetchUrl {
url = "https://gitlab.com/fluidattacks/universe/-/raw/7012ee63b6ba5ffebfc82425deb4390cb1d4a1ca/common/test/mr/src/dangerfile.ts";
sha256 = "sha256-OegMHRXwgkRItyxW5SZfcQr21VRIINKhC5mlYa/Rphw=";
};
extraArgs = [
"--config"
(builtins.toJSON {tests = ["onlyOneCommit"];})
];
};
};
};
testTerraform = {
modules = {
module = {
Expand Down
1 change: 1 addition & 0 deletions src/args/agnostic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
sublist = import ./sublist/default.nix self;
taintTerraform = import ./taint-terraform/default.nix self;
testTerraform = import ./test-terraform/default.nix self;
testPullRequest = import ./test-pull-request/default.nix self;
testPython = import ./test-python/default.nix self;
toDerivationName = self.__nixpkgs__.lib.strings.sanitizeDerivationName;
toBashArray = import ./to-bash-array/default.nix self;
Expand Down
28 changes: 28 additions & 0 deletions src/args/test-pull-request/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
escapeShellArgs,
makeNodeJsEnvironment,
makeScript,
...
}: {
dangerfile,
extraArgs,
name,
setup,
...
}: let
env = makeNodeJsEnvironment {
name = "danger";
nodeJsVersion = "18";
packageJson = ./package.json;
packageLockJson = ./package-lock.json;
};
in
makeScript {
entrypoint = ./entrypoint.sh;
replace = {
__argDangerfile__ = dangerfile;
__argExtraArgs__ = escapeShellArgs extraArgs;
};
name = "test-pull-request-for-${name}";
searchPaths.source = [env] ++ setup;
}
18 changes: 18 additions & 0 deletions src/args/test-pull-request/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# shellcheck shell=bash

function main {
local args=(
--dangerfile __argDangerfile__
__argExtraArgs__
"${@}"
)

: \
&& if test -n "${CI-}"; then
danger ci "${args[@]}"
else
danger pr "${args[@]}"
fi
}

main "${@}"
Loading

0 comments on commit b643ebd

Please sign in to comment.