Skip to content

Commit 3bbbd34

Browse files
committed
try again
1 parent 8f3f254 commit 3bbbd34

File tree

2 files changed

+77
-88
lines changed

2 files changed

+77
-88
lines changed

.github/workflows/auto-format.yaml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Auto-format PR
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, synchronize, reopened]
6+
branches:
7+
- main
8+
- release
9+
10+
concurrency:
11+
group: auto-format-${{ github.event.pull_request.number }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
auto_format:
16+
if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip:ci') }}
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: write
20+
pull-requests: write
21+
steps:
22+
- name: Checkout PR branch
23+
uses: actions/checkout@v5
24+
with:
25+
ref: ${{ github.event.pull_request.head.sha }}
26+
repository: ${{ github.event.pull_request.head.repo.full_name }}
27+
token: ${{ secrets.AUTO_FORMAT_PAT }}
28+
fetch-depth: 0
29+
30+
- name: Setup Rust
31+
uses: dtolnay/rust-toolchain@stable
32+
with:
33+
components: rustfmt
34+
35+
- name: Run cargo fmt
36+
run: cargo fmt --all
37+
38+
- name: Configure git
39+
run: |
40+
git config user.name "github-actions[bot]"
41+
git config user.email "github-actions[bot]@users.noreply.github.com"
42+
43+
- name: Check for changes
44+
id: check-changes
45+
run: |
46+
if [ -n "$(git status --porcelain)" ]; then
47+
echo "has_changes=true" >> $GITHUB_OUTPUT
48+
else
49+
echo "has_changes=false" >> $GITHUB_OUTPUT
50+
fi
51+
52+
- name: Commit and push
53+
if: steps.check-changes.outputs.has_changes == 'true'
54+
run: |
55+
git add -u
56+
git commit -m "Auto-format: cargo fmt --all"
57+
git push origin HEAD:${{ github.event.pull_request.head.ref }}
58+
59+
- name: Comment on PR
60+
if: steps.check-changes.outputs.has_changes == 'true'
61+
uses: marocchino/sticky-pull-request-comment@v2
62+
with:
63+
number: ${{ github.event.pull_request.number }}
64+
message: |
65+
**Code has been automatically formatted**
66+
67+
The code in this PR has been formatted using `cargo fmt --all`.
68+
Please pull the latest changes before pushing again:
69+
```bash
70+
git pull origin ${{ github.event.pull_request.head.ref }}
71+
```

.github/workflows/ci.yaml

Lines changed: 6 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -108,81 +108,11 @@ env:
108108
PYTHON_VERSION: "3.13.1"
109109

110110
jobs:
111-
auto_format_pr:
112-
if: ${{ github.event_name == 'pull_request' }}
113-
runs-on: ubuntu-latest
114-
permissions:
115-
contents: write
116-
pull-requests: write
117-
checks: read
118-
steps:
119-
- name: Checkout PR branch
120-
uses: actions/checkout@v5
121-
with:
122-
ref: ${{ github.event.pull_request.head.ref }}
123-
repository: ${{ github.event.pull_request.head.repo.full_name }}
124-
token: ${{ github.token }}
125-
fetch-depth: 0
126-
127-
- name: Setup Rust
128-
uses: dtolnay/rust-toolchain@stable
129-
with:
130-
components: rustfmt
131-
132-
- name: Run cargo fmt
133-
run: cargo fmt --all
134-
135-
- name: Configure git
136-
run: |
137-
git config user.name "github-actions[bot]"
138-
git config user.email "github-actions[bot]@users.noreply.github.com"
139-
140-
- name: git add
141-
run: git add -u
142-
143-
- name: git commit
144-
id: git-commit
145-
run: git commit -m "run `cargo fmt --all`"
146-
continue-on-error: true # Will fail if nothing to commit
147-
148-
- name: Comment on PR
149-
if: ${{ steps.git-commit.outcome == 'success' }}
150-
uses: marocchino/sticky-pull-request-comment@v2
151-
with:
152-
number: ${{ github.event.pull_request.number }}
153-
message: |
154-
**Code has been automatically formatted**
155-
156-
The code in this PR has been formatted using `cargo fmt --all`.
157-
158-
You may need to pull the latest changes before pushing again:
159-
```bash
160-
git pull origin ${{ github.event.pull_request.head.ref }}
161-
```
162-
163-
**Triggered by commit:** `${{ github.event.pull_request.head.sha }}`
164-
**Last formatted:** ${{ github.event.pull_request.updated_at }}
165-
**Run**: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
166-
167-
- name: git push
168-
run: git push origin HEAD:${{ env.HEAD_REF }}
169-
env:
170-
HEAD_REF: ${{ github.event.pull_request.head.ref }}
171-
if: steps.git-commit.outcome == 'success'
172-
173-
# This step is not really needed as the earlier push should cancel this run anyways.
174-
# But we are making sure that we abort if we had badly formatted files.
175-
- name: Exit if changed
176-
run: exit 1
177-
if: ${{ steps.git-commit.outcome == 'success' }}
178-
179111
rust_tests:
180-
if: ${{ !cancelled() && !contains(github.event.pull_request.labels.*.name, 'skip:ci') }}
112+
if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip:ci') }}
181113
env:
182114
RUST_BACKTRACE: full
183115
name: Run rust tests
184-
needs:
185-
- auto_format_pr
186116
runs-on: ${{ matrix.os }}
187117
timeout-minutes: ${{ contains(matrix.os, 'windows') && 45 || 35 }}
188118
strategy:
@@ -244,10 +174,8 @@ jobs:
244174
if: runner.os == 'macOS'
245175

246176
exotic_targets:
247-
if: ${{ !cancelled() && !contains(github.event.pull_request.labels.*.name, 'skip:ci') }}
177+
if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip:ci') }}
248178
name: Ensure compilation on various targets
249-
needs:
250-
- auto_format_pr
251179
runs-on: ubuntu-latest
252180
timeout-minutes: 30
253181
steps:
@@ -307,12 +235,10 @@ jobs:
307235
# args: --ignore-rust-version
308236

309237
snippets_cpython:
310-
if: ${{ !cancelled() && !contains(github.event.pull_request.labels.*.name, 'skip:ci') }}
238+
if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip:ci') }}
311239
env:
312240
RUST_BACKTRACE: full
313241
name: Run snippets and cpython tests
314-
needs:
315-
- auto_format_pr
316242
runs-on: ${{ matrix.os }}
317243
timeout-minutes: ${{ contains(matrix.os, 'windows') && 45 || 35 }}
318244
strategy:
@@ -383,8 +309,6 @@ jobs:
383309

384310
lint:
385311
name: Check Rust code with clippy
386-
needs:
387-
- auto_format_pr
388312
runs-on: ubuntu-latest
389313
steps:
390314
- uses: actions/checkout@v6
@@ -419,10 +343,8 @@ jobs:
419343
incremental_files_only: true
420344

421345
miri:
422-
if: ${{ !cancelled() && !contains(github.event.pull_request.labels.*.name, 'skip:ci') }}
346+
if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip:ci') }}
423347
name: Run tests under miri
424-
needs:
425-
- auto_format_pr
426348
runs-on: ubuntu-latest
427349
timeout-minutes: 30
428350
env:
@@ -445,10 +367,8 @@ jobs:
445367
MIRIFLAGS: '-Zmiri-ignore-leaks'
446368

447369
wasm:
448-
if: ${{ !cancelled() && !contains(github.event.pull_request.labels.*.name, 'skip:ci') }}
370+
if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip:ci') }}
449371
name: Check the WASM package and demo
450-
needs:
451-
- auto_format_pr
452372
runs-on: ubuntu-latest
453373
timeout-minutes: 30
454374
steps:
@@ -510,10 +430,8 @@ jobs:
510430
PUBLISH_BRANCH: master
511431

512432
wasm-wasi:
513-
if: ${{ !cancelled() && !contains(github.event.pull_request.labels.*.name, 'skip:ci') }}
433+
if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip:ci') }}
514434
name: Run snippets and cpython tests on wasm-wasi
515-
needs:
516-
- auto_format_pr
517435
runs-on: ubuntu-latest
518436
timeout-minutes: 30
519437
steps:

0 commit comments

Comments
 (0)