Skip to content

Merge pull request #1681 from alphagov/whi-tw/pre-commit #25

Merge pull request #1681 from alphagov/whi-tw/pre-commit

Merge pull request #1681 from alphagov/whi-tw/pre-commit #25

Workflow file for this run

name: pre-commit
on:
pull_request:
types:
- opened
- reopened
- ready_for_review
- synchronize
push:
branches:
- main
merge_group:
jobs:
noop-on-merge-group:
if: github.event_name == 'merge_group'
runs-on: ubuntu-latest
name: Run pre-commit # Replace with '&job_name Run pre-commit' once actionlint supports anchors
steps:
- name: 🛑 Skip Pre-commit Checks for Merge Group
run: echo "This is a merge group event. Skipping pre-commit checks."; true
shell: bash
pre-commit:
# This job will run on all pull requests and pushes to main, but not on merge groups
# We run it on merge to main to ensure that pre-commit's cache is up to date
if: github.event_name != 'merge_group'
runs-on: ubuntu-latest
name: Run pre-commit # Replace with '*job_name' once actionlint supports anchors
steps:
- name: 📦 Check Out Repository Code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: 🏗️ Set Up Terraform
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
- name: 🏗️ Install Pre-commit
run: python -m pip install pre-commit
shell: bash
- name: 🛠️ Freeze Python Dependencies
run: python -m pip freeze --local
shell: bash
- name: 📦 Cache Pre-commit tools
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
path: ~/.cache/pre-commit
key: pre-commit-3|${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: |
pre-commit-3|
- name: ✅ Run Pre-commit Hooks
env:
SKIP: "checkov,tflint,rubocop,terraform-fmt"
run: |
# shellcheck disable=SC2296
pre-commit run --show-diff-on-failure --color=always \
--from-ref "${{ github.event.pull_request.base.sha }}" \
--to-ref "${{ github.event.pull_request.head.sha }}"
shell: bash
- name: 🧹 Cache Cleanup
run: pre-commit gc
shell: bash