mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
replace auto commit to format suggestion (#7375)
This commit is contained in:
1 parent
46642272e7
commit
2bdc2315ef
2 files changed
+56
-122
No files matched your search
@@ -1,122 +0,0 @@
|
||||
name: Auto-format PR
|
||||
|
||||
# This workflow triggers when a PR is opened/updated
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [opened, synchronize, reopened]
|
||||
branches:
|
||||
- main
|
||||
- release
|
||||
|
||||
concurrency:
|
||||
group: auto-format-${{ github.event.pull_request.number }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
auto_format:
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
steps:
|
||||
- name: Checkout PR branch
|
||||
uses: actions/checkout@v6.0.2
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
repository: ${{ github.event.pull_request.head.repo.full_name }}
|
||||
token: ${{ secrets.AUTO_COMMIT_PAT }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup Rust
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
components: rustfmt
|
||||
|
||||
- name: Configure git
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
echo "" > /tmp/committed_commands.txt
|
||||
|
||||
- name: Run cargo fmt
|
||||
run: |
|
||||
echo "Running cargo fmt --all on PR #${{ github.event.pull_request.number }}"
|
||||
cargo fmt --all
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
git add -u
|
||||
git commit -m "Auto-format: cargo fmt --all"
|
||||
echo "- \`cargo fmt --all\`" >> /tmp/committed_commands.txt
|
||||
fi
|
||||
|
||||
- name: Install ruff
|
||||
uses: astral-sh/ruff-action@4919ec5cf1f49eff0871dbcea0da843445b837e6 # v3.6.1
|
||||
with:
|
||||
version: "0.15.4"
|
||||
args: "--version"
|
||||
|
||||
- name: Run ruff format
|
||||
run: |
|
||||
ruff format
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
git add -u
|
||||
git commit -m "Auto-format: ruff format"
|
||||
echo "- \`ruff format\`" >> /tmp/committed_commands.txt
|
||||
fi
|
||||
|
||||
- name: Run ruff check import sorting
|
||||
run: |
|
||||
ruff check --select I --fix
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
git add -u
|
||||
git commit -m "Auto-format: ruff check --select I --fix"
|
||||
echo "- \`ruff check --select I --fix\`" >> /tmp/committed_commands.txt
|
||||
fi
|
||||
|
||||
- name: Run generate_opcode_metadata.py
|
||||
run: |
|
||||
python scripts/generate_opcode_metadata.py
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
git add -u
|
||||
git commit -m "Auto-generate: generate_opcode_metadata.py"
|
||||
echo "- \`python scripts/generate_opcode_metadata.py\`" >> /tmp/committed_commands.txt
|
||||
fi
|
||||
|
||||
- name: Check for changes
|
||||
id: check-changes
|
||||
run: |
|
||||
if [ "$(git rev-parse HEAD)" != "${{ github.event.pull_request.head.sha }}" ]; then
|
||||
echo "has_changes=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "has_changes=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Push formatting changes
|
||||
if: steps.check-changes.outputs.has_changes == 'true'
|
||||
env:
|
||||
HEAD_REF: ${{ github.event.pull_request.head.ref }}
|
||||
run: |
|
||||
git push origin "HEAD:${HEAD_REF}"
|
||||
|
||||
- name: Read committed commands
|
||||
id: committed-commands
|
||||
if: steps.check-changes.outputs.has_changes == 'true'
|
||||
run: |
|
||||
echo "list<<EOF" >> $GITHUB_OUTPUT
|
||||
cat /tmp/committed_commands.txt >> $GITHUB_OUTPUT
|
||||
echo "EOF" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Comment on PR
|
||||
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:
|
||||
${{ steps.committed-commands.outputs.list }}
|
||||
Please pull the latest changes before pushing again:
|
||||
```bash
|
||||
git pull origin ${{ github.event.pull_request.head.ref }}
|
||||
```
|
||||
@@ -0,0 +1,56 @@
|
||||
name: Format Check
|
||||
|
||||
# This workflow triggers when a PR is opened/updated
|
||||
# Posts inline suggestion comments instead of auto-committing
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
branches:
|
||||
- main
|
||||
- release
|
||||
|
||||
concurrency:
|
||||
group: format-check-${{ github.event.pull_request.number }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
format_check:
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
steps:
|
||||
- name: Checkout PR branch
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Rust
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
components: rustfmt
|
||||
|
||||
- name: Run cargo fmt
|
||||
run: cargo fmt --all
|
||||
|
||||
- name: Install ruff
|
||||
uses: astral-sh/ruff-action@4919ec5cf1f49eff0871dbcea0da843445b837e6 # v3.6.1
|
||||
with:
|
||||
version: "0.15.4"
|
||||
args: "--version"
|
||||
|
||||
- name: Run ruff format
|
||||
run: ruff format
|
||||
|
||||
- name: Run ruff check import sorting
|
||||
run: ruff check --select I --fix
|
||||
|
||||
- name: Run generate_opcode_metadata.py
|
||||
run: python scripts/generate_opcode_metadata.py
|
||||
|
||||
- name: Post formatting suggestions
|
||||
uses: reviewdog/action-suggester@v1
|
||||
with:
|
||||
tool_name: auto-format
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
level: warning
|
||||
filter_mode: diff_context
|
||||
Reference in new issue
Block a user