-
Notifications
You must be signed in to change notification settings - Fork 2
79 lines (70 loc) · 3.14 KB
/
pre-commit.yaml
File metadata and controls
79 lines (70 loc) · 3.14 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
name: Pre-commit
on:
workflow_call:
inputs:
python-version:
description: 'What version of python'
type: string
required: true
setup-node:
description: 'Whether to set up Node'
type: boolean
default: false
node-version:
description: 'What version of node'
type: string
required: false
default: 'notUsing'
env:
PYTHONUNBUFFERED: True
PRE_COMMIT_HOME: ${{ github.workspace }}/.precommit_cache
permissions:
contents: write # needed for mutex
id-token: write # needed to assume OIDC roles (e.g. for downloading from CodeArtifact)
jobs:
pre-commit:
runs-on: ubuntu-24.04
timeout-minutes: 8
name: Pre-commit
steps:
- name: Checkout code during push
if: ${{ github.event_name == 'push' }}
uses: actions/checkout@v6.0.1
with:
ref: ${{ github.ref_name }} # explicitly get the head of the branch, which will include any new commits pushed if this is a dependabot branch
persist-credentials: false
- name: Checkout code not during push
if: ${{ github.event_name != 'push' }}
uses: actions/checkout@v6.0.1
with:
persist-credentials: false
- name: Install latest versions of packages
uses: ./.github/actions/install_deps
with:
python-version: ${{ inputs.python-version }}
node-version: ${{ inputs.node-version }}
skip-installing-ssm-plugin-manager: true
- name: Set up mutex # Github concurrency management is horrible, things get arbitrarily cancelled if queued up. So using mutex until github fixes itself. When multiple jobs are modifying cache at once, weird things can happen. possible issue is https://github.com/actions/toolkit/issues/658
if: ${{ runner.os != 'Windows' }} # we're just gonna have to YOLO on Windows, because this action doesn't support it yet https://github.com/ben-z/gh-action-mutex/issues/14
uses: ben-z/gh-action-mutex@1ebad517141198e08d47cf72f3c0975316620a65 # v1.0.0-alpha.10
with:
branch: mutex-venv-ubuntu-24.04-py${{ inputs.python-version }}-nodejs-${{ inputs.node-version }}
timeout-minutes: 8 # this is the amount of time this action will wait to attempt to acquire the mutex lock before failing, e.g. if other jobs are queued up in front of it
- name: Cache Pre-commit hooks
uses: actions/cache@v4.3.0
env:
cache-name: cache-pre-commit-hooks
with:
path: ${{ env.PRE_COMMIT_HOME }}
key: ubuntu-24.04-py${{ inputs.python-version }}-node-${{ inputs.node-version}}-${{ env.cache-name }}-${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: |
ubuntu-24.04-py${{ inputs.python-version }}-node-${{ inputs.node-version}}-${{ env.cache-name }}-
- name: Run pre-commit
run: |
pre-commit run -a || PRE_COMMIT_EXIT_CODE=$?
if [ -n "$PRE_COMMIT_EXIT_CODE" ]; then
echo "Pre-commit failed with exit code $PRE_COMMIT_EXIT_CODE"
echo "Showing git diff:"
git --no-pager diff
exit $PRE_COMMIT_EXIT_CODE
fi