Skip to content

Commit 5901c3b

Browse files
feat(run-pre-commit): Add support to install nix (#19)
Co-authored-by: Nick <[email protected]>
1 parent 9198f72 commit 5901c3b

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

run-pre-commit/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
> Manifest: [run-pre-commit/action.yml][run-pre-commit]
44
5-
This action runs pre-commit by setting up Python and optionally the Rust toolchain and Hadolint in
6-
the requested version. It requires a checkout with depth 0. It does the following work:
5+
This action runs pre-commit by setting up Python and optionally installing the Rust toolchain,
6+
Hadolint, and Nix in the requested version. It requires a checkout with depth 0. It does the
7+
following work:
78

89
1. Installs Python. The version can be configured via the `python-version` input.
9-
2. Optionally sets up the Rust toolchain and Hadolint.
10+
2. Optionally sets up the Rust toolchain, Hadolint, and Nix.
1011
3. Runs pre-commit on changed files.
1112

1213
Example usage (workflow):
@@ -40,6 +41,8 @@ jobs:
4041
- `rust` (eg: `1.80.1`. Disabled if not specified)
4142
- `rust-components` (defaults to `rustfmt,clippy`)
4243
- `hadolint` (eg: `v2.12.0`. Disabled if not specified)
44+
- `nix` (eg: `2.25.2`. Disabled if not specified)
45+
- `nix-github-token` (eg: `secrets.GITHUB_TOKEN`. Required when `nix` is set)
4346

4447
### Outputs
4548

run-pre-commit/action.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ inputs:
1717
default: rustfmt,clippy
1818
hadolint:
1919
description: Whether to install hadolint (and which version to use)
20+
nix:
21+
description: Whether to install nix (and which version to use)
22+
nix-github-token:
23+
description: |
24+
The GitHub token is used by Nix to pull from GitHub with higher rate-limits. Required when
25+
the 'nix' input is used.
2026
runs:
2127
using: composite
2228
steps:
@@ -50,6 +56,20 @@ runs:
5056
5157
echo "$LOCATION_DIR" | tee -a "$GITHUB_PATH"
5258
59+
- name: Abort if nix-github-token input is not set
60+
if: inputs.nix && !inputs.nix-github-token
61+
shell: bash
62+
run: |
63+
echo "nix-github-token input must be set when nix input is set"
64+
exit 1
65+
66+
- name: Setup nix
67+
if: inputs.nix
68+
uses: cachix/install-nix-action@08dcb3a5e62fa31e2da3d490afc4176ef55ecd72 #v30
69+
with:
70+
github_access_token: ${{ inputs.nix-github-token }}
71+
install_url: https://releases.nixos.org/nix/nix-${{ inputs.nix }}/install
72+
5373
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
5474
with:
5575
extra_args: "--from-ref '${{ github.event.pull_request.base.sha }}' --to-ref '${{ github.event.pull_request.head.sha }}'"

0 commit comments

Comments
 (0)