-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yaml
More file actions
132 lines (116 loc) · 4.6 KB
/
action.yaml
File metadata and controls
132 lines (116 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
---
name: Run prek
description: |
This action sets up the prek tool, and additional tools required for various
hooks. It then runs prek against the changed files. This actions expects
checkouts with depth 0.
inputs:
# See https://github.com/j178/prek/releases for latest version
prek-version:
description: prek version to install
default: latest
rust:
description: Whether to install the Rust toolchain (and which version to use)
rust-components:
description: |
Override which Rust components are installed. Only takes effect when Rust
is installed.
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.
jinja2-cli:
description: Whether to install jinja2-cli (and which version to use)
runs:
using: composite
steps:
# Immediately abort without setting up any other tooling to avoid unnecessary workflow runtime.
- 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@4e002c8ec80594ecd40e759629461e26c8abed15 # v31.9.0
with:
github_access_token: ${{ inputs.nix-github-token }}
install_url: https://releases.nixos.org/nix/nix-${{ inputs.nix }}/install
- name: Install prek (${{ env.PRE_COMMIT_VERSION }})
shell: bash
env:
PREK_VERSION: ${{ inputs.prek-version }}
GITHUB_DEBUG: ${{ runner.debug }}
run: "$GITHUB_ACTION_PATH/../.scripts/actions/install_prek.sh"
# This caches downloaded prek hook artifacts and results in faster
# workflow runs after an initial hydration run with the exact same hooks
- name: Setup prek Cache
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
with:
path: ~/.cache/prek
key: prek-${{ inputs.prek-version }}-${{ hashFiles('.pre-commit-config.yaml') }}
- name: Format Rust Toolchain Cache Key
id: rust-toolchain-cache-key
if: ${{ inputs.rust }}
shell: bash
env:
RUST_COMPONENTS: ${{ inputs.rust-components }}
run: |
RUST_COMPONENTS=${RUST_COMPONENTS//,/_}
echo "RUST_COMPONENTS=$RUST_COMPONENTS" | tee -a "$GITHUB_OUTPUT"
- name: Setup Rust Toolchain Cache
id: rust-toolchain-cache
if: ${{ inputs.rust }}
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
with:
path: ~/.rustup/toolchains
key: rust-toolchains-${{ inputs.rust }}-components-${{ steps.rust-toolchain-cache-key.outputs.RUST_COMPONENTS }}
- name: Setup Rust Toolchain
uses: dtolnay/rust-toolchain@f7ccc83f9ed1e5b9c81d8a67d7ad1a747e22a561
if: ${{ inputs.rust && steps.rust-toolchain-cache.outputs.cache-hit != 'true' }}
with:
toolchain: ${{ inputs.rust }}
components: ${{ inputs.rust-components }}
- name: Setup Rust Cache
if: ${{ inputs.rust }}
uses: Swatinem/rust-cache@23869a5bd66c73db3c0ac40331f3206eb23791dc # v2.9.1
# TODO (@Techassi): Move this into a script
- name: Install Hadolint
if: ${{ inputs.hadolint }}
shell: bash
env:
HADOLINT_VERSION: ${{ inputs.hadolint }}
run: | # zizmor: ignore[github-env] Using GITHUB_PATH is fine here, because the path is not user-controlled.
set -euo pipefail
LOCATION_DIR="$HOME/.local/bin"
LOCATION_BIN="$LOCATION_DIR/hadolint"
SYSTEM=$(uname -s)
ARCH=$(uname -m)
mkdir -p "$LOCATION_DIR"
curl -sL -o "$LOCATION_BIN" "https://github.com/hadolint/hadolint/releases/download/${HADOLINT_VERSION}/hadolint-$SYSTEM-$ARCH"
chmod 700 "$LOCATION_BIN"
echo "$LOCATION_DIR" | tee -a "$GITHUB_PATH"
- name: Install jinja2-cli
if: ${{ inputs.jinja2-cli }}
shell: bash
env:
JINJA2_CLI_VERSION: ${{ inputs.jinja2-cli }}
run: pip install jinja2-cli==${JINJA2_CLI_VERSION}
- name: Run prek
shell: bash
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
prek run \
--verbose \
--show-diff-on-failure \
--color always \
--from-ref "$BASE_SHA" \
--to-ref "$HEAD_SHA"