Repository navigation
96 lines (80 loc) · 3.63 KB
/
Copy pathpre-commit.yml
File metadata and controls
96 lines (80 loc) · 3.63 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
name: Pre-commit
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read
env:
# No `|direct` fallback: under harden-runner's block mode a direct fetch
# only fans out to blocked vanity-import hosts and burns minutes; see the
# GOPROXY comment in test.yml.
GOPROXY: "https://proxy.golang.org"
jobs:
pre-commit:
name: Run pre-commit hooks
runs-on: ubuntu-24.04
# Source-built runners and pinned tools are prepared before any checks.
timeout-minutes: 30
steps:
- name: Checkout Code
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
persist-credentials: false
# Check the PR head itself. Its merge base with the current parent
# excludes newer trunk changes and avoids stale event base SHAs.
ref: ${{ github.event.pull_request.head.sha }}
# Fetch full history for proper diff checking.
fetch-depth: 0
- name: Verify bundled allowlist parser
run: |
npm ci --ignore-scripts --prefix .github/actions/harden-runner
npm run build --prefix .github/actions/harden-runner
git diff --exit-code -- .github/actions/harden-runner/runtime/yaml.cjs
- name: Test CI helper scripts
run: >-
node --test
.github/scripts/*.test.mjs
.github/actions/harden-runner/runtime/*.test.cjs
.github/actions/harden-runner/diagnostics/*.test.cjs
- name: Set up Go
uses: ./.github/actions/setup-go-cache
with:
go-version-file: go.mod
- name: Install Go tools
env:
GOBIN: ${{ github.workspace }}/build/check-tools
run: |
# Pin check tools consistently with atmos dev setup.
# Pin to the gofumpt bundled by golangci-lint v2.5.0 (the gofumpt formatter in
# .golangci.yml) so the standalone hook and the linter stay in lockstep. Floating
# @latest drifted to v0.10.0, which reformats v0.9.x-clean code and broke unrelated
# files that fell into the PR diff range.
go install mvdan.cc/gofumpt@v0.9.1
# Install golangci-lint v2
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.5.0
go install github.com/zricethezav/gitleaks/v8@v8.30.1
# Add Go bin to PATH
echo "$GOBIN" >> "$GITHUB_PATH"
# Pre-download dependencies to prevent go mod tidy from trying to fetch
# internal packages. With retry: GOPROXY no longer falls back to direct
# fetches (they only hit blocked vanity hosts under harden-runner's block
# mode), so transient proxy errors are handled by retrying instead.
- name: Download Go module dependencies
uses: ./.github/actions/go-mod-download-retry
- name: Build repository check runners
env:
CGO_ENABLED: "0"
run: |
go build -o build/ .
- name: Test native sandbox and repository checks
run: CGO_ENABLED=0 go test ./pkg/git/sandbox ./pkg/script/starlark ./pkg/git/hooks ./cmd/git/hooks
- name: Run Atmos repository checks
env:
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
# Native stack updates can deliver a synchronize event with an old base
# SHA after the new parent is published. Fetch the branch and calculate
# the review scope from the checked-out head's current merge base.
run: |
git fetch --no-tags origin "refs/heads/$PR_BASE_REF"
pr_merge_base="$(git merge-base HEAD FETCH_HEAD)"
./build/atmos check pr --base-ref "$pr_merge_base" --skip golangci-lint