This commit is contained in:
70
.github/workflows/fix-formatting.yml
vendored
Normal file
70
.github/workflows/fix-formatting.yml
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
name: Fix formatting
|
||||
|
||||
env:
|
||||
PNPM_VERSION: "10.28.1"
|
||||
NODE_VERSION: "24.11.0"
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [labeled]
|
||||
|
||||
jobs:
|
||||
format:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event.label.name == 'format'
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: ${{ github.event.pull_request.head.repo.full_name}}
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
|
||||
- name: Setup pnpm
|
||||
uses: pnpm/action-setup@v4
|
||||
with:
|
||||
version: ${{ env.PNPM_VERSION }}
|
||||
|
||||
- name: Install formatter
|
||||
run: pnpm install -D -w oxfmt --ignore-scripts
|
||||
|
||||
- name: Get changed files
|
||||
id: get-changed-files
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const changedFiles = await github.paginate(
|
||||
github.rest.pulls.listFiles,
|
||||
{
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
pull_number: context.payload.pull_request.number,
|
||||
}
|
||||
);
|
||||
return changedFiles.filter(file=> file.status !== "removed").map(file => file.filename).join(' ');
|
||||
|
||||
- name: Fix formatting
|
||||
env:
|
||||
CHANGED_FILES: ${{ steps.get-changed-files.outputs.result }}
|
||||
run: |
|
||||
if [ -n "$CHANGED_FILES" ]; then
|
||||
echo "$CHANGED_FILES" | tr ' ' '\n' | xargs pnpm oxfmt --no-error-on-unmatched-pattern
|
||||
fi
|
||||
|
||||
- name: Commit changes
|
||||
uses: stefanzweifel/git-auto-commit-action@v5
|
||||
with:
|
||||
commit_message: "fix formatting"
|
||||
|
||||
- name: Remove label
|
||||
uses: actions-ecosystem/action-remove-labels@v1
|
||||
with:
|
||||
labels: format
|
||||
Reference in New Issue
Block a user