From b50711718245fd71318ec5ddee3ef203c8371c97 Mon Sep 17 00:00:00 2001 From: Daniel Salazar Date: Wed, 18 Dec 2024 18:45:19 -0500 Subject: [PATCH] feat(cross): #1223 use jobs approach - Migrate tests - Migrate makes root job - Adapt CI jobs Signed-off-by: Daniel Salazar --- .github/workflows/dev.yml | 12 ++++---- .github/workflows/prod.yml | 12 ++++---- default.nix | 2 +- makes.nix | 7 +---- makes/main.nix | 16 ---------- makes/makes.nix | 29 +++++++++++++++++++ makes/tests/commitlint/main.nix | 13 --------- makes/tests/commitlint/makes.nix | 14 +++++++++ makes/tests/computeOnAwsBatch/main.nix | 20 ------------- makes/tests/computeOnAwsBatch/makes.nix | 21 ++++++++++++++ .../{scriptWithHelp => makeScript}/README.md | 4 +-- makes/tests/makeScript/makes.nix | 7 +++++ makes/tests/makeSearchPaths/main.nix | 6 ---- makes/tests/makeSearchPaths/makes.nix | 7 +++++ makes/tests/makeTemplate/main.nix | 13 --------- makes/tests/makeTemplate/makes.nix | 15 ++++++++++ makes/tests/scriptWithHelp/main.nix | 6 ---- makes/tests/secretsForGpgFromEnv/main.nix | 10 ------- makes/tests/secretsForGpgFromEnv/makes.nix | 11 +++++++ makes/utils/makePythonLock/main.nix | 12 -------- makes/utils/makePythonLock/makes.nix | 13 +++++++++ makes/utils/makeRubyLock/main.nix | 12 -------- makes/utils/makeRubyLock/makes.nix | 13 +++++++++ 23 files changed, 146 insertions(+), 129 deletions(-) delete mode 100644 makes/main.nix create mode 100644 makes/makes.nix delete mode 100644 makes/tests/commitlint/main.nix create mode 100644 makes/tests/commitlint/makes.nix delete mode 100644 makes/tests/computeOnAwsBatch/main.nix create mode 100644 makes/tests/computeOnAwsBatch/makes.nix rename makes/tests/{scriptWithHelp => makeScript}/README.md (63%) create mode 100644 makes/tests/makeScript/makes.nix delete mode 100644 makes/tests/makeSearchPaths/main.nix create mode 100644 makes/tests/makeSearchPaths/makes.nix delete mode 100644 makes/tests/makeTemplate/main.nix create mode 100644 makes/tests/makeTemplate/makes.nix delete mode 100644 makes/tests/scriptWithHelp/main.nix delete mode 100644 makes/tests/secretsForGpgFromEnv/main.nix create mode 100644 makes/tests/secretsForGpgFromEnv/makes.nix delete mode 100644 makes/utils/makePythonLock/main.nix create mode 100644 makes/utils/makePythonLock/makes.nix delete mode 100644 makes/utils/makeRubyLock/main.nix create mode 100644 makes/utils/makeRubyLock/makes.nix diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 7e9edb3a..3370b93d 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -340,21 +340,21 @@ jobs: - name: /tests/makeTemplate run: nix-env -if . && m . /tests/makeTemplate - linux_tests_scriptWithHelp: + linux_tests_makeScript: runs-on: ubuntu-latest steps: - uses: actions/checkout@f095bcc56b7c2baf48f3ac70d6d6782f4f553222 - uses: docker://docker.io/nixos/nix@sha256:c3db4c484f6b1ee6c9bb8ca90307cfbeca8ef88156840911356a677eeaff4845 - name: /tests/scriptWithHelp + name: /tests/makeScript with: - args: sh -c "chown -R root:root /github/workspace && nix-env -if . && m . /tests/scriptWithHelp" - macos_tests_scriptWithHelp: + args: sh -c "chown -R root:root /github/workspace && nix-env -if . && m . /tests/makeScript" + macos_tests_makeScript: runs-on: macos-latest steps: - uses: actions/checkout@f095bcc56b7c2baf48f3ac70d6d6782f4f553222 - uses: cachix/install-nix-action@6ed004b9ccb68dbc28e7c85bee15fa93dbd214ac - - name: /tests/scriptWithHelp - run: nix-env -if . && m . /tests/scriptWithHelp + - name: /tests/makeScript + run: nix-env -if . && m . /tests/makeScript linux_tests_secretsForGpgFromEnv: runs-on: ubuntu-latest diff --git a/.github/workflows/prod.yml b/.github/workflows/prod.yml index 3d809f8b..a55c85f8 100644 --- a/.github/workflows/prod.yml +++ b/.github/workflows/prod.yml @@ -496,23 +496,23 @@ jobs: env: CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} - linux_tests_scriptWithHelp: + linux_tests_makeScript: runs-on: ubuntu-latest steps: - uses: actions/checkout@f095bcc56b7c2baf48f3ac70d6d6782f4f553222 - uses: docker://docker.io/nixos/nix@sha256:c3db4c484f6b1ee6c9bb8ca90307cfbeca8ef88156840911356a677eeaff4845 - name: /tests/scriptWithHelp + name: /tests/makeScript with: - args: sh -c "chown -R root:root /github/workspace && nix-env -if . && m . /tests/scriptWithHelp" + args: sh -c "chown -R root:root /github/workspace && nix-env -if . && m . /tests/makeScript" env: CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} - macos_tests_scriptWithHelp: + macos_tests_makeScript: runs-on: macos-latest steps: - uses: actions/checkout@f095bcc56b7c2baf48f3ac70d6d6782f4f553222 - uses: cachix/install-nix-action@v15 - - name: /tests/scriptWithHelp - run: nix-env -if . && m . /tests/scriptWithHelp + - name: /tests/makeScript + run: nix-env -if . && m . /tests/makeScript env: CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} diff --git a/default.nix b/default.nix index d07c1d95..37919102 100644 --- a/default.nix +++ b/default.nix @@ -9,4 +9,4 @@ let projectPath = import ./src/args/project-path args; projectSrc = ./.; }; -in import ./makes/main.nix args +in (import ./makes/makes.nix args).jobs."/" diff --git a/makes.nix b/makes.nix index e60b725f..6a320ff5 100644 --- a/makes.nix +++ b/makes.nix @@ -1,11 +1,6 @@ { fetchNixpkgs, fetchUrl, makeScript, outputs, projectPath, __nixpkgs__, ... }: { - jobs = { - "/test" = makeScript { - name = "test/job"; - entrypoint = "echo Hello test"; - }; - }; + imports = [ ./makes/makes.nix ]; projectIdentifier = "makes-repo"; cache = { readNixos = true; diff --git a/makes/main.nix b/makes/main.nix deleted file mode 100644 index dbec1a1a..00000000 --- a/makes/main.nix +++ /dev/null @@ -1,16 +0,0 @@ -{ __nixpkgs__, makeScript, outputs, projectPath, ... }: -let makesVersion = "24.12"; -in makeScript { - aliases = [ "m-v${makesVersion}" "makes" "makes-v${makesVersion}" ]; - replace = { - __argMakesSrc__ = projectPath "/"; - __argNix__ = __nixpkgs__.nixVersions.nix_2_15; - }; - entrypoint = '' - __MAKES_SRC__=__argMakesSrc__ \ - __NIX__=__argNix__ \ - python -u __argMakesSrc__/src/cli/main/__main__.py "$@" - ''; - searchPaths.source = [ outputs."/cli/env/runtime" ]; - name = "m"; -} diff --git a/makes/makes.nix b/makes/makes.nix new file mode 100644 index 00000000..6587900c --- /dev/null +++ b/makes/makes.nix @@ -0,0 +1,29 @@ +{ __nixpkgs__, makeScript, outputs, projectPath, ... }: +let makesVersion = "24.12"; +in { + imports = [ + ./tests/commitlint/makes.nix + ./tests/computeOnAwsBatch/makes.nix + ./tests/makeScript/makes.nix + ./tests/makeSearchPaths/makes.nix + ./tests/makeTemplate/makes.nix + ./tests/secretsForGpgFromEnv/makes.nix + ./utils/makePythonLock/makes.nix + ./utils/makeRubyLock/makes.nix + ]; + + jobs."/" = makeScript { + aliases = [ "m-v${makesVersion}" "makes" "makes-v${makesVersion}" ]; + replace = { + __argMakesSrc__ = projectPath "/"; + __argNix__ = __nixpkgs__.nixVersions.nix_2_15; + }; + entrypoint = '' + __MAKES_SRC__=__argMakesSrc__ \ + __NIX__=__argNix__ \ + python -u __argMakesSrc__/src/cli/main/__main__.py "$@" + ''; + searchPaths.source = [ outputs."/cli/env/runtime" ]; + name = "m"; + }; +} diff --git a/makes/tests/commitlint/main.nix b/makes/tests/commitlint/main.nix deleted file mode 100644 index 59cb54b4..00000000 --- a/makes/tests/commitlint/main.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ makeScript, __nixpkgs__, ... }: -makeScript { - name = "commitlint"; - entrypoint = '' - pushd makes/tests/commitlint - - commit_hash="$(git --no-pager log --pretty=%h origin/main..HEAD)" - - info "Linting commit $commit_hash" - git log -1 --pretty=%B $commit_hash | commitlint --parser-preset ./parser.js --config ./config.js - ''; - searchPaths.bin = [ __nixpkgs__.commitlint __nixpkgs__.git ]; -} diff --git a/makes/tests/commitlint/makes.nix b/makes/tests/commitlint/makes.nix new file mode 100644 index 00000000..effe267f --- /dev/null +++ b/makes/tests/commitlint/makes.nix @@ -0,0 +1,14 @@ +{ makeScript, __nixpkgs__, ... }: { + jobs."/tests/commitlint" = makeScript { + name = "commitlint"; + entrypoint = '' + pushd makes/tests/commitlint + + commit_hash="$(git --no-pager log --pretty=%h origin/main..HEAD)" + + info "Linting commit $commit_hash" + git log -1 --pretty=%B $commit_hash | commitlint --parser-preset ./parser.js --config ./config.js + ''; + searchPaths.bin = [ __nixpkgs__.commitlint __nixpkgs__.git ]; + }; +} diff --git a/makes/tests/computeOnAwsBatch/main.nix b/makes/tests/computeOnAwsBatch/main.nix deleted file mode 100644 index 7b264aa0..00000000 --- a/makes/tests/computeOnAwsBatch/main.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ computeOnAwsBatch, ... }: -computeOnAwsBatch { - dryRun = true; - allowDuplicates = true; - attempts = 1; - attemptDurationSeconds = 60; - command = [ "foo" ]; - definition = "foo"; - environment = [ ]; - includePositionalArgsInName = true; - name = "foo"; - nextJob = { }; - memory = 1; - parallel = 1; - propagateTags = true; - queue = "foo"; - setup = [ ]; - tags = { }; - vcpus = 1; -} diff --git a/makes/tests/computeOnAwsBatch/makes.nix b/makes/tests/computeOnAwsBatch/makes.nix new file mode 100644 index 00000000..1f85fb14 --- /dev/null +++ b/makes/tests/computeOnAwsBatch/makes.nix @@ -0,0 +1,21 @@ +{ computeOnAwsBatch, ... }: { + jobs."/tests/computeOnAwsBatch" = computeOnAwsBatch { + dryRun = true; + allowDuplicates = true; + attempts = 1; + attemptDurationSeconds = 60; + command = [ "foo" ]; + definition = "foo"; + environment = [ ]; + includePositionalArgsInName = true; + name = "foo"; + nextJob = { }; + memory = 1; + parallel = 1; + propagateTags = true; + queue = "foo"; + setup = [ ]; + tags = { }; + vcpus = 1; + }; +} diff --git a/makes/tests/scriptWithHelp/README.md b/makes/tests/makeScript/README.md similarity index 63% rename from makes/tests/scriptWithHelp/README.md rename to makes/tests/makeScript/README.md index 8ef7496e..8d63dad3 100644 --- a/makes/tests/scriptWithHelp/README.md +++ b/makes/tests/makeScript/README.md @@ -1,7 +1,7 @@ # A Script With a Help -- This is `makes/tests/scriptWithHelp/README.md` +- This is `makes/tests/makeScript/README.md` - You might be looking at it beautifully rendered on GitHub / GitLab / etc. - You also might be looking at it beautifully rendedred on the CLI\*. -\* `m . /tests/scriptWithHelp -h` (or `--help`) +\* `m . /tests/makeScript -h` (or `--help`) diff --git a/makes/tests/makeScript/makes.nix b/makes/tests/makeScript/makes.nix new file mode 100644 index 00000000..8e502bcf --- /dev/null +++ b/makes/tests/makeScript/makes.nix @@ -0,0 +1,7 @@ +{ makeScript, ... }: { + jobs."/tests/makeScript" = makeScript { + entrypoint = "echo A script with a help, call with --help or -h to see it!"; + name = "help"; + help = ./README.md; + }; +} diff --git a/makes/tests/makeSearchPaths/main.nix b/makes/tests/makeSearchPaths/main.nix deleted file mode 100644 index 54686637..00000000 --- a/makes/tests/makeSearchPaths/main.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ makeDerivation, ... }: -makeDerivation { - builder = "touch $out"; - name = "test-make-search-paths"; - searchPaths.source = [[ ./template.sh "a" "b" "c" ]]; -} diff --git a/makes/tests/makeSearchPaths/makes.nix b/makes/tests/makeSearchPaths/makes.nix new file mode 100644 index 00000000..f3e2d5f3 --- /dev/null +++ b/makes/tests/makeSearchPaths/makes.nix @@ -0,0 +1,7 @@ +{ makeDerivation, ... }: { + jobs."/tests/makeSearchPaths" = makeDerivation { + builder = "touch $out"; + name = "test-make-search-paths"; + searchPaths.source = [[ ./template.sh "a" "b" "c" ]]; + }; +} diff --git a/makes/tests/makeTemplate/main.nix b/makes/tests/makeTemplate/main.nix deleted file mode 100644 index 4ab4e828..00000000 --- a/makes/tests/makeTemplate/main.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ fromYaml, makeTemplate, ... }: -let - testFile = fromYaml (builtins.readFile ./test.yaml); - testString = testFile.testTitle; -in makeTemplate { - replace = { - __argFirst__ = "aaaaaaaaa"; - __argSecond__ = "bbbb"; - __argThird__ = testString; - }; - name = "test-make-template"; - template = ./template.txt; -} diff --git a/makes/tests/makeTemplate/makes.nix b/makes/tests/makeTemplate/makes.nix new file mode 100644 index 00000000..da860363 --- /dev/null +++ b/makes/tests/makeTemplate/makes.nix @@ -0,0 +1,15 @@ +{ fromYaml, makeTemplate, ... }: +let + testFile = fromYaml (builtins.readFile ./test.yaml); + testString = testFile.testTitle; +in { + jobs."/tests/makeTemplate" = makeTemplate { + replace = { + __argFirst__ = "aaaaaaaaa"; + __argSecond__ = "bbbb"; + __argThird__ = testString; + }; + name = "test-make-template"; + template = ./template.txt; + }; +} diff --git a/makes/tests/scriptWithHelp/main.nix b/makes/tests/scriptWithHelp/main.nix deleted file mode 100644 index dce70090..00000000 --- a/makes/tests/scriptWithHelp/main.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ makeScript, ... }: -makeScript { - entrypoint = "echo A script with a help, call with --help or -h to see it!"; - name = "help"; - help = ./README.md; -} diff --git a/makes/tests/secretsForGpgFromEnv/main.nix b/makes/tests/secretsForGpgFromEnv/main.nix deleted file mode 100644 index 3373a941..00000000 --- a/makes/tests/secretsForGpgFromEnv/main.nix +++ /dev/null @@ -1,10 +0,0 @@ -{ makeScript, outputs, ... }: -makeScript { - entrypoint = "echo $secret"; - name = "tests-secrets-for-gpg-from-env"; - searchPaths.source = [ - outputs."/envVars/example" - outputs."/secretsForGpgFromEnv/example" - outputs."/secretsForEnvFromSops/example" - ]; -} diff --git a/makes/tests/secretsForGpgFromEnv/makes.nix b/makes/tests/secretsForGpgFromEnv/makes.nix new file mode 100644 index 00000000..88f5ebe4 --- /dev/null +++ b/makes/tests/secretsForGpgFromEnv/makes.nix @@ -0,0 +1,11 @@ +{ makeScript, outputs, ... }: { + jobs."/tests/secretsForGpgFromEnv" = makeScript { + entrypoint = "echo $secret"; + name = "tests-secrets-for-gpg-from-env"; + searchPaths.source = [ + outputs."/envVars/example" + outputs."/secretsForGpgFromEnv/example" + outputs."/secretsForEnvFromSops/example" + ]; + }; +} diff --git a/makes/utils/makePythonLock/main.nix b/makes/utils/makePythonLock/main.nix deleted file mode 100644 index 34d30976..00000000 --- a/makes/utils/makePythonLock/main.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ __nixpkgs__, makeScript, ... }: -makeScript { - entrypoint = ./entrypoint.sh; - name = "make-python-lock"; - searchPaths.bin = [ - __nixpkgs__.poetry - __nixpkgs__.python39 - __nixpkgs__.python310 - __nixpkgs__.python311 - __nixpkgs__.python312 - ]; -} diff --git a/makes/utils/makePythonLock/makes.nix b/makes/utils/makePythonLock/makes.nix new file mode 100644 index 00000000..42bacd54 --- /dev/null +++ b/makes/utils/makePythonLock/makes.nix @@ -0,0 +1,13 @@ +{ __nixpkgs__, makeScript, ... }: { + jobs."/utils/makePythonLock" = makeScript { + entrypoint = ./entrypoint.sh; + name = "make-python-lock"; + searchPaths.bin = [ + __nixpkgs__.poetry + __nixpkgs__.python39 + __nixpkgs__.python310 + __nixpkgs__.python311 + __nixpkgs__.python312 + ]; + }; +} diff --git a/makes/utils/makeRubyLock/main.nix b/makes/utils/makeRubyLock/main.nix deleted file mode 100644 index 2ad0e7df..00000000 --- a/makes/utils/makeRubyLock/main.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ __nixpkgs__, makeScript, ... }: -makeScript { - entrypoint = ./entrypoint.sh; - name = "make-ruby-lock"; - replace = { - __argParser__ = ./parser.rb; - __argRuby31__ = __nixpkgs__.ruby_3_1; - __argRuby32__ = __nixpkgs__.ruby_3_2; - __argRuby33__ = __nixpkgs__.ruby_3_3; - }; - searchPaths.bin = [ __nixpkgs__.nixVersions.nix_2_15 __nixpkgs__.yj ]; -} diff --git a/makes/utils/makeRubyLock/makes.nix b/makes/utils/makeRubyLock/makes.nix new file mode 100644 index 00000000..e7d45f9a --- /dev/null +++ b/makes/utils/makeRubyLock/makes.nix @@ -0,0 +1,13 @@ +{ __nixpkgs__, makeScript, ... }: { + jobs."/utils/makeRubyLock" = makeScript { + entrypoint = ./entrypoint.sh; + name = "make-ruby-lock"; + replace = { + __argParser__ = ./parser.rb; + __argRuby31__ = __nixpkgs__.ruby_3_1; + __argRuby32__ = __nixpkgs__.ruby_3_2; + __argRuby33__ = __nixpkgs__.ruby_3_3; + }; + searchPaths.bin = [ __nixpkgs__.nixVersions.nix_2_15 __nixpkgs__.yj ]; + }; +}