-
Notifications
You must be signed in to change notification settings - Fork 0
57 lines (51 loc) · 2.04 KB
/
Copy pathauto-format.yml
File metadata and controls
57 lines (51 loc) · 2.04 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
# Repo-owned auto-format: label a pull request `fix-lint` (the label ships
# with the template's settings.yml) and this workflow pushes a formatting
# commit to the PR branch, then removes the label. Generated once by
# Vivswan/repo-platform and never overwritten by template
# sync: adjust the format commands to this repository's tooling.
name: Auto Format
on:
pull_request:
types: [labeled]
permissions:
contents: read
jobs:
format:
# Same-repo PRs only: GITHUB_TOKEN cannot push to a fork's branch, and
# PR-controlled tool configuration should not run next to write
# credentials (checkout below persists none; the push step scopes them).
if: github.event.label.name == 'fix-lint' && github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v7
with:
ref: ${{ github.event.pull_request.head.ref }}
persist-credentials: false
- uses: oven-sh/setup-bun@v2
- name: Format (biome)
run: bun x @biomejs/biome check --write .
- name: Commit and push changes
env:
GH_TOKEN: ${{ github.token }}
HEAD_REF: ${{ github.event.pull_request.head.ref }}
run: |
if git diff --quiet; then
echo "nothing to format"
else
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "style: apply automated formatting"
git push "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" HEAD:"$HEAD_REF"
fi
# The label is a one-shot request: remove it even when a step failed,
# so a broken run cannot loop.
- name: Remove the fix-lint label
if: always()
env:
GH_TOKEN: ${{ github.token }}
PR_URL: ${{ github.event.pull_request.html_url }}
run: gh pr edit "$PR_URL" --remove-label fix-lint