From 1eee303c09a428f860da87f19eeb2caa78570f06 Mon Sep 17 00:00:00 2001 From: Techassi Date: Mon, 2 Dec 2024 11:45:37 +0100 Subject: [PATCH 1/7] feat(run-pre-commit): Add support to install nix --- run-pre-commit/action.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/run-pre-commit/action.yml b/run-pre-commit/action.yml index 70c9968..ea7897c 100644 --- a/run-pre-commit/action.yml +++ b/run-pre-commit/action.yml @@ -17,6 +17,8 @@ inputs: default: rustfmt,clippy hadolint: description: Whether to install hadolint (and which version to use) + nix: + description: Whether to install nix (and which version to use) runs: using: composite steps: @@ -50,6 +52,13 @@ runs: echo "$LOCATION_DIR" | tee -a "$GITHUB_PATH" + - name: Setup nix + if: ${{ inputs.nix }} + uses: cachix/install-nix-action@08dcb3a5e62fa31e2da3d490afc4176ef55ecd72 #v30 + with: + github_access_token: ${{ secrets.GITHUB_TOKEN }} + install_url: https://releases.nixos.org/nix/nix-${{ inputs.nix }}/install + - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 with: extra_args: "--from-ref '${{ github.event.pull_request.base.sha }}' --to-ref '${{ github.event.pull_request.head.sha }}'" From c0ee483ee36f2b365b1af379fb8ea99a1522c826 Mon Sep 17 00:00:00 2001 From: Techassi Date: Mon, 2 Dec 2024 12:19:50 +0100 Subject: [PATCH 2/7] feat(run-pre-commit): Add nix-github-token input --- run-pre-commit/action.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/run-pre-commit/action.yml b/run-pre-commit/action.yml index ea7897c..2a821fe 100644 --- a/run-pre-commit/action.yml +++ b/run-pre-commit/action.yml @@ -19,6 +19,10 @@ inputs: description: Whether to install hadolint (and which version to use) nix: description: Whether to install nix (and which version to use) + nix-github-token: + description: | + The GitHub token is used by Nix to pull from GitHub with higher rate-limits. Required when + the 'nix' input is used. runs: using: composite steps: @@ -52,11 +56,18 @@ runs: echo "$LOCATION_DIR" | tee -a "$GITHUB_PATH" + - name: Abort nix-github-token input is unset + if: ${{ inputs.nix }} && !${{ inputs.nix-github-token }} + shell: bash + run: | + echo "nix-github-token input must be set when nix input is set" + exit 1 + - name: Setup nix if: ${{ inputs.nix }} uses: cachix/install-nix-action@08dcb3a5e62fa31e2da3d490afc4176ef55ecd72 #v30 with: - github_access_token: ${{ secrets.GITHUB_TOKEN }} + github_access_token: ${{ inputs.nix-github-token }} install_url: https://releases.nixos.org/nix/nix-${{ inputs.nix }}/install - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 From 7121279f0feed2a531ff42f5828709983a854e3c Mon Sep 17 00:00:00 2001 From: Techassi Date: Mon, 2 Dec 2024 12:22:24 +0100 Subject: [PATCH 3/7] chore: Adjust expression --- run-pre-commit/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-pre-commit/action.yml b/run-pre-commit/action.yml index 2a821fe..9498da3 100644 --- a/run-pre-commit/action.yml +++ b/run-pre-commit/action.yml @@ -57,7 +57,7 @@ runs: echo "$LOCATION_DIR" | tee -a "$GITHUB_PATH" - name: Abort nix-github-token input is unset - if: ${{ inputs.nix }} && !${{ inputs.nix-github-token }} + if: ${{ inputs.nix && !inputs.nix-github-token }} shell: bash run: | echo "nix-github-token input must be set when nix input is set" From d8b7a978ef68be0b68e74dab6b65e4d4e0e60209 Mon Sep 17 00:00:00 2001 From: Techassi Date: Mon, 2 Dec 2024 13:01:33 +0100 Subject: [PATCH 4/7] chore(run-pre-commit): Update README --- run-pre-commit/README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/run-pre-commit/README.md b/run-pre-commit/README.md index cc3d1b6..001b77f 100644 --- a/run-pre-commit/README.md +++ b/run-pre-commit/README.md @@ -2,11 +2,12 @@ > Manifest: [run-pre-commit/action.yml][run-pre-commit] -This action runs pre-commit by setting up Python and optionally the Rust toolchain and Hadolint in -the requested version. It requires a checkout with depth 0. It does the following work: +This action runs pre-commit by setting up Python and optionally installing the Rust toolchain, +Hadolint, and Nix in the requested version. It requires a checkout with depth 0. It does the +following work: 1. Installs Python. The version can be configured via the `python-version` input. -2. Optionally sets up the Rust toolchain and Hadolint. +2. Optionally sets up the Rust toolchain, Hadolint, and Nix. 3. Runs pre-commit on changed files. Example usage (workflow): @@ -40,6 +41,8 @@ jobs: - `rust` (eg: `1.80.1`. Disabled if not specified) - `rust-components` (defaults to `rustfmt,clippy`) - `hadolint` (eg: `v2.12.0`. Disabled if not specified) +- `nix` (eg: `2.25.2`. Disabled if not specified) +- `nix-github-token` (eg: `secrets.GITHUB_TOKEN`. Required when `nix` is set) ### Outputs From 25d52143d9955e99f6565b7abd61e6ae83038f53 Mon Sep 17 00:00:00 2001 From: Techassi Date: Tue, 3 Dec 2024 12:42:00 +0100 Subject: [PATCH 5/7] chore(run-pre-commit): Update if expression Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com> --- run-pre-commit/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-pre-commit/action.yml b/run-pre-commit/action.yml index 79d47d4..79a1ea4 100644 --- a/run-pre-commit/action.yml +++ b/run-pre-commit/action.yml @@ -57,7 +57,7 @@ runs: echo "$LOCATION_DIR" | tee -a "$GITHUB_PATH" - name: Abort nix-github-token input is unset - if: ${{ inputs.nix && !inputs.nix-github-token }} + if: inputs.nix && !inputs.nix-github-token shell: bash run: | echo "nix-github-token input must be set when nix input is set" From 4f921eaf6f4e56f1a1ef9bbe30292a4d143e23a0 Mon Sep 17 00:00:00 2001 From: Techassi Date: Tue, 3 Dec 2024 12:42:38 +0100 Subject: [PATCH 6/7] chore(run-pre-commit): Update if expression Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com> --- run-pre-commit/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-pre-commit/action.yml b/run-pre-commit/action.yml index 79a1ea4..e3fcb54 100644 --- a/run-pre-commit/action.yml +++ b/run-pre-commit/action.yml @@ -64,7 +64,7 @@ runs: exit 1 - name: Setup nix - if: ${{ inputs.nix }} + if: inputs.nix uses: cachix/install-nix-action@08dcb3a5e62fa31e2da3d490afc4176ef55ecd72 #v30 with: github_access_token: ${{ inputs.nix-github-token }} From f3b555e3f166ecceb10c55cbe5726c44b0923558 Mon Sep 17 00:00:00 2001 From: Techassi Date: Tue, 3 Dec 2024 12:42:57 +0100 Subject: [PATCH 7/7] chore(run-pre-commit): Update step name Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com> --- run-pre-commit/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-pre-commit/action.yml b/run-pre-commit/action.yml index e3fcb54..fb6a43e 100644 --- a/run-pre-commit/action.yml +++ b/run-pre-commit/action.yml @@ -56,7 +56,7 @@ runs: echo "$LOCATION_DIR" | tee -a "$GITHUB_PATH" - - name: Abort nix-github-token input is unset + - name: Abort if nix-github-token input is not set if: inputs.nix && !inputs.nix-github-token shell: bash run: |