From 5901c3b1455488820c4be367531e07c3c3e82538 Mon Sep 17 00:00:00 2001 From: Techassi Date: Tue, 3 Dec 2024 13:55:02 +0100 Subject: [PATCH] feat(run-pre-commit): Add support to install nix (#19) Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com> --- run-pre-commit/README.md | 9 ++++++--- run-pre-commit/action.yml | 20 ++++++++++++++++++++ 2 files changed, 26 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 diff --git a/run-pre-commit/action.yml b/run-pre-commit/action.yml index 3b11d88..fb6a43e 100644 --- a/run-pre-commit/action.yml +++ b/run-pre-commit/action.yml @@ -17,6 +17,12 @@ 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) + 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: @@ -50,6 +56,20 @@ runs: echo "$LOCATION_DIR" | tee -a "$GITHUB_PATH" + - name: Abort if nix-github-token input is not set + 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: ${{ inputs.nix-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 }}'"