Skip to content

Commit

Permalink
feat(run-pre-commit): Add support to install nix (#19)
Browse files Browse the repository at this point in the history
Co-authored-by: Nick <[email protected]>
  • Loading branch information
Techassi and NickLarsenNZ authored Dec 3, 2024
1 parent 9198f72 commit 5901c3b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
9 changes: 6 additions & 3 deletions run-pre-commit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down
20 changes: 20 additions & 0 deletions run-pre-commit/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 }}'"

0 comments on commit 5901c3b

Please sign in to comment.