git-ents.gitmain
⌘K
foforge
Lint.yml171 lines · 5.0 KB · yamlhistorycomment on this file
1name: Lint
2
3on:
4 pull_request:
5 types:
6 - opened
7 - review_requested
8 - ready_for_review
9 - reopened
10 - synchronize
11 - edited
12 workflow_dispatch:
13
14permissions:
15 contents: read
16 pull-requests: read
17
18jobs:
19 pre-commit:
20 name: Run pre-commit checks
21 runs-on: ubuntu-latest
22 if: ${{ !github.event.pull_request.draft }}
23 steps:
24 - name: Checkout
25 uses: actions/checkout@v6
26
27 - uses: mlugg/setup-zig@v2
28 with:
29 version: 0.15.2
30
31 - name: Set up Python
32 uses: actions/setup-python@v5
33 with:
34 python-version: "3.x"
35
36 - name: Install uv
37 uses: astral-sh/setup-uv@v7
38 with:
39 enable-cache: true
40
41 - name: Install pre-commit and hooks
42 run: |
43 uv tool install pre-commit
44 pre-commit install-hooks -c .config/pre-commit.yaml
45
46 - name: Run pre-commit on all files
47 run: pre-commit run -a -c .config/pre-commit.yaml
48
49 validate-pr-title:
50 name: Validate squash commit message
51 runs-on: ubuntu-latest
52 if: ${{ github.event.pull_request && github.event.pull_request.draft == false }}
53 steps:
54 - name: Checkout
55 uses: actions/checkout@v6
56
57 - name: Set up Python
58 uses: actions/setup-python@v5
59 with:
60 python-version: "3.x"
61
62 - name: Install uv
63 uses: astral-sh/setup-uv@v7
64 with:
65 enable-cache: true
66
67 - name: Cache pre-commit
68 uses: actions/cache@v4
69 with:
70 path: ~/.cache/pre-commit
71 key: pre-commit-${{ hashFiles('.config/pre-commit.yaml') }}
72 restore-keys: |
73 pre-commit-
74
75 - name: Install pre-commit and hooks
76 run: |
77 uv tool install pre-commit
78 pre-commit install-hooks -c .config/pre-commit.yaml
79
80 - name: Create commit message from PR
81 run: |
82 cat > /tmp/commit-msg.txt << 'EOF'
83 ${{ github.event.pull_request.title }}
84
85 ${{ github.event.pull_request.body }}
86 EOF
87 echo "--- Commit message to validate ---"
88 cat /tmp/commit-msg.txt
89 echo "--- End of commit message ---"
90
91 - name: Find and validate with committed
92 run: |
93 # Find the committed binary in pre-commit cache
94 COMMITTED_BIN=$(find ~/.cache/pre-commit -type f -name committed | head -n 1)
95 if [ -z "$COMMITTED_BIN" ]; then
96 echo "Error: committed binary not found in pre-commit cache"
97 exit 1
98 fi
99 echo "Using committed binary: $COMMITTED_BIN"
100 "$COMMITTED_BIN" --config .config/committed.toml --commit-file /tmp/commit-msg.txt
101
102 cargo-deny:
103 name: Run cargo-deny
104 runs-on: ubuntu-latest
105 if: ${{ !github.event.pull_request.draft }}
106 strategy:
107 matrix:
108 checks:
109 - advisories
110 - bans licenses sources
111 continue-on-error: ${{ matrix.checks == 'advisories' }}
112 steps:
113 - name: Checkout
114 uses: actions/checkout@v6
115
116 - name: Run cargo-deny
117 uses: EmbarkStudios/cargo-deny-action@v2
118 with:
119 arguments: --all-features
120 command: check
121 command-arguments: ${{ matrix.checks }} -c .config/deny.toml
122
123 semver-checks:
124 name: Semver checks
125 runs-on: ubuntu-latest
126 if: |
127 startsWith(github.head_ref, 'release-please--') &&
128 !github.event.pull_request.draft
129 steps:
130 - uses: actions/checkout@v4
131 - uses: mlugg/setup-zig@v2
132 with:
133 version: 0.15.2
134 - uses: actions-rust-lang/setup-rust-toolchain@v1
135 with:
136 cache: true
137 - name: Install cargo-semver-checks
138 uses: taiki-e/install-action@v2
139 with:
140 tool: cargo-semver-checks
141 - name: Run semver checks for published crates
142 run: |
143 crate_names=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[].name')
144 published_pkgs=()
145 for crate in $crate_names; do
146 status=$(curl -s -o /dev/null -w "%{http_code}" \
147 -H "User-Agent: github-actions-semver-check" \
148 "https://crates.io/api/v1/crates/$crate")
149 if [ "$status" = "200" ]; then
150 echo "✓ '$crate' is published — will run semver-checks"
151 published_pkgs+=("--package" "$crate")
152 else
153 echo "✗ '$crate' is not yet published (HTTP $status) — skipping"
154 fi
155 done
156 if [ "${#published_pkgs[@]}" -gt 0 ]; then
157 cargo semver-checks "${published_pkgs[@]}"
158 else
159 echo "No crates are published yet — skipping semver checks entirely."
160 fi
161
162 lint:
163 name: Lint
164 if: ${{ always() && !github.event.pull_request.draft }}
165 needs: [pre-commit, validate-pr-title, cargo-deny, semver-checks]
166 runs-on: ubuntu-latest
167 steps:
168 - run: |
169 result="${{ (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) && 'failure' || 'success' }}"
170 echo "result: $result"
171 [[ "$result" == "success" ]] || exit 1