-
Notifications
You must be signed in to change notification settings - Fork 0
164 lines (145 loc) · 4.86 KB
/
Lint.yml
File metadata and controls
164 lines (145 loc) · 4.86 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
name: Lint
on:
pull_request:
types:
- opened
- review_requested
- ready_for_review
- reopened
- synchronize
- edited
workflow_dispatch:
permissions:
contents: read
pull-requests: read
jobs:
pre-commit:
name: Run pre-commit checks
runs-on: ubuntu-latest
if: ${{ !github.event.pull_request.draft }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Install pre-commit and hooks
run: |
uv tool install pre-commit
pre-commit install-hooks -c .config/pre-commit.yaml
- name: Run pre-commit on all files
run: pre-commit run -a -c .config/pre-commit.yaml
validate-pr-title:
name: Validate squash commit message
runs-on: ubuntu-latest
if: ${{ github.event.pull_request && github.event.pull_request.draft == false }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Cache pre-commit
uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ hashFiles('.config/pre-commit.yaml') }}
restore-keys: |
pre-commit-
- name: Install pre-commit and hooks
run: |
uv tool install pre-commit
pre-commit install-hooks -c .config/pre-commit.yaml
- name: Create commit message from PR
run: |
cat > /tmp/commit-msg.txt << 'EOF'
${{ github.event.pull_request.title }}
${{ github.event.pull_request.body }}
EOF
echo "--- Commit message to validate ---"
cat /tmp/commit-msg.txt
echo "--- End of commit message ---"
- name: Find and validate with committed
run: |
# Find the committed binary in pre-commit cache
COMMITTED_BIN=$(find ~/.cache/pre-commit -type f -name committed | head -n 1)
if [ -z "$COMMITTED_BIN" ]; then
echo "Error: committed binary not found in pre-commit cache"
exit 1
fi
echo "Using committed binary: $COMMITTED_BIN"
"$COMMITTED_BIN" --config .config/committed.toml --commit-file /tmp/commit-msg.txt
cargo-deny:
name: Run cargo-deny
runs-on: ubuntu-latest
if: ${{ !github.event.pull_request.draft }}
strategy:
matrix:
checks:
- advisories
- bans licenses sources
continue-on-error: ${{ matrix.checks == 'advisories' }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Run cargo-deny
uses: EmbarkStudios/cargo-deny-action@v2
with:
arguments: --all-features
command: check
command-arguments: ${{ matrix.checks }} -c .config/deny.toml
semver-checks:
name: Semver checks
runs-on: ubuntu-latest
if: |
startsWith(github.head_ref, 'release-please--') &&
!github.event.pull_request.draft
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
cache: true
- name: Install cargo-semver-checks
uses: taiki-e/install-action@v2
with:
tool: cargo-semver-checks
- name: Run semver checks for published crates
run: |
crate_names=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[].name')
published_pkgs=()
for crate in $crate_names; do
status=$(curl -s -o /dev/null -w "%{http_code}" \
-H "User-Agent: github-actions-semver-check" \
"https://crates.io/api/v1/crates/$crate")
if [ "$status" = "200" ]; then
echo "✓ '$crate' is published — will run semver-checks"
published_pkgs+=("--package" "$crate")
else
echo "✗ '$crate' is not yet published (HTTP $status) — skipping"
fi
done
if [ "${#published_pkgs[@]}" -gt 0 ]; then
cargo semver-checks "${published_pkgs[@]}"
else
echo "No crates are published yet — skipping semver checks entirely."
fi
lint:
name: Lint
if: ${{ always() && !github.event.pull_request.draft }}
needs: [pre-commit, validate-pr-title, cargo-deny, semver-checks]
runs-on: ubuntu-latest
steps:
- run: |
result="${{ (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) && 'failure' || 'success' }}"
echo "result: $result"
[[ "$result" == "success" ]] || exit 1