From cb3971e981dda574f668e3dd36ebe49214f1fcc5 Mon Sep 17 00:00:00 2001 From: Robin Quintero Date: Sun, 11 Jun 2023 16:58:29 -0500 Subject: [PATCH] feat(build): #1099 licensing builtin with reuse - Create `testLicense` builtin with reuse. - Add job to dev pipeline Signed-off-by: Robin Quintero --- .github/workflows/dev.yml | 17 +++++++++++++ docs/src/api/builtins/test.md | 24 +++++++++++++++++++ makes.nix | 1 + src/args/agnostic.nix | 1 + src/args/test-license/default.nix | 13 ++++++++++ src/args/test-license/entrypoint.sh | 9 +++++++ src/evaluator/modules/default.nix | 1 + .../modules/test-license/default.nix | 17 +++++++++++++ 8 files changed, 83 insertions(+) create mode 100644 src/args/test-license/default.nix create mode 100644 src/args/test-license/entrypoint.sh create mode 100644 src/evaluator/modules/test-license/default.nix diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 99f83cae..3817c767 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -489,6 +489,23 @@ jobs: - uses: cachix/install-nix-action@67e9fd765dbe63fabe0ce2bd72f56f9a417696a0 - name: /taintTerraform/module run: nix-env -if . && m . /taintTerraform/module + + linux_testLicense: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@f095bcc56b7c2baf48f3ac70d6d6782f4f553222 + - uses: docker://docker.io/nixos/nix@sha256:c3db4c484f6b1ee6c9bb8ca90307cfbeca8ef88156840911356a677eeaff4845 + name: /testLicense + with: + set-safe-directory: /github/workspace + args: sh -c "nix-env -if . && m . /testLicense" + macos_testLicense: + runs-on: macos-latest + steps: + - uses: actions/checkout@f095bcc56b7c2baf48f3ac70d6d6782f4f553222 + - uses: cachix/install-nix-action@67e9fd765dbe63fabe0ce2bd72f56f9a417696a0 + - name: /testLicense + run: nix-env -if . && m . /testLicense linux_testPython_cliMain: runs-on: ubuntu-latest diff --git a/docs/src/api/builtins/test.md b/docs/src/api/builtins/test.md index 00edb168..3a8bad96 100644 --- a/docs/src/api/builtins/test.md +++ b/docs/src/api/builtins/test.md @@ -1,3 +1,27 @@ +## testLicense + +Test the license of a project using [reuse](https://reuse.software/). + +Types: + +- testLicense: Empty attribute set. + +Example: + +=== "makes.nix" + + ```nix + { + testLicense = {}; + } + ``` + +=== "Invocation" + + ```bash + m . /testLicense + ``` + ## testPullRequest Test a pull request diff --git a/makes.nix b/makes.nix index db46e176..24e256ea 100644 --- a/makes.nix +++ b/makes.nix @@ -252,6 +252,7 @@ }; }; }; + testLicense = {}; testPython = { example = { python = "3.11"; diff --git a/src/args/agnostic.nix b/src/args/agnostic.nix index c83eb2ba..129830ba 100644 --- a/src/args/agnostic.nix +++ b/src/args/agnostic.nix @@ -107,6 +107,7 @@ stringCapitalize = import ./string-capitalize/default.nix self; sublist = import ./sublist/default.nix self; taintTerraform = import ./taint-terraform/default.nix self; + testLicense = import ./test-license/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; diff --git a/src/args/test-license/default.nix b/src/args/test-license/default.nix new file mode 100644 index 00000000..a0db5076 --- /dev/null +++ b/src/args/test-license/default.nix @@ -0,0 +1,13 @@ +{ + __nixpkgs__, + makeScript, + ... +}: +makeScript { + name = "test-license"; + entrypoint = ./entrypoint.sh; + searchPaths.bin = [ + __nixpkgs__.git + __nixpkgs__.reuse + ]; +} diff --git a/src/args/test-license/entrypoint.sh b/src/args/test-license/entrypoint.sh new file mode 100644 index 00000000..4e62b5f2 --- /dev/null +++ b/src/args/test-license/entrypoint.sh @@ -0,0 +1,9 @@ +# shellcheck shell=bash + +function main { + if ! reuse lint; then + error "Some files are not properly licensed. Please adapt .reuse/dep5" + fi +} + +main "${@}" diff --git a/src/evaluator/modules/default.nix b/src/evaluator/modules/default.nix index 316a71c1..44c67099 100644 --- a/src/evaluator/modules/default.nix +++ b/src/evaluator/modules/default.nix @@ -50,6 +50,7 @@ (import ./secure-kubernetes-with-rbac-police/default.nix args) (import ./secure-python-with-bandit/default.nix args) (import ./taint-terraform/default.nix args) + (import ./test-license/default.nix args) (import ./test-pull-request/default.nix args) (import ./test-python/default.nix args) (import ./test-terraform/default.nix args) diff --git a/src/evaluator/modules/test-license/default.nix b/src/evaluator/modules/test-license/default.nix new file mode 100644 index 00000000..d420c424 --- /dev/null +++ b/src/evaluator/modules/test-license/default.nix @@ -0,0 +1,17 @@ +{ + testLicense, + ... +}: { + config, + lib, + ... +}: { + options = { + testLicense = {}; + }; + config = { + outputs = { + "/testLicense" = testLicense; + }; + }; +}