Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 18 additions & 42 deletions .github/workflows/pr-auto-commit.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PR Auto-format
name: Auto-format PR

# This workflow triggers when a PR is opened/updated
on:
Expand All @@ -9,42 +9,26 @@ on:
- release

concurrency:
group: pr-fmt-${{ github.event.pull_request.number }}
group: auto-format-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
auto_format:
if: |
!contains(github.event.pull_request.labels.*.name, 'skip:ci') &&
!contains(github.event.pull_request.head.sha, '[skip ci]')
if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip:ci') }}
permissions:
contents: write
pull-requests: write
checks: read
runs-on: ubuntu-latest
timeout-minutes: 60

steps:
- name: Checkout PR branch
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.ref }}
ref: ${{ github.event.pull_request.head.sha }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.AUTO_COMMIT_PAT }}
fetch-depth: 0

# Wait for all PR check runs to complete
- name: Wait for all checks to complete
uses: poseidon/wait-for-status-checks@v0.6.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
delay: 60
interval: 30
timeout: 7200

- name: CI completed successfully
run: echo "CI workflow completed successfully - proceeding with auto-format"

- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
Expand All @@ -55,8 +39,13 @@ jobs:
echo "Running cargo fmt --all on PR #${{ github.event.pull_request.number }}"
cargo fmt --all

- name: Check for formatting changes
id: check_changes
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- name: Check for changes
id: check-changes
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
Expand All @@ -65,35 +54,22 @@ jobs:
fi

- name: Commit and push formatting changes
if: steps.check_changes.outputs.has_changes == 'true'
if: steps.check-changes.outputs.has_changes == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

git add -u
git commit -m "Auto-format code [skip ci]"

git commit -m "Auto-format: cargo fmt --all"
git push origin HEAD:${{ github.event.pull_request.head.ref }}

- name: Comment on PR
if: steps.check_changes.outputs.has_changes == 'true'
if: steps.check-changes.outputs.has_changes == 'true'
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ github.event.pull_request.number }}
message: |
**Code has been automatically formatted**

The code in this PR has been formatted using `cargo fmt`.
The changes have been committed with `[skip ci]` to avoid triggering another CI run.

**Triggered by commit:** `${{ github.event.pull_request.head.sha }}`
**Last formatted:** ${{ github.event.pull_request.updated_at }}

You may need to pull the latest changes before pushing again:

The code in this PR has been formatted using `cargo fmt --all`.
Please pull the latest changes before pushing again:
```bash
git pull origin ${{ github.event.pull_request.head.ref }}
```

- name: No formatting needed
if: steps.check_changes.outputs.has_changes == 'false'
run: echo "Code is already properly formatted"
Loading