-
-
Notifications
You must be signed in to change notification settings - Fork 127
88 lines (71 loc) · 2.64 KB
/
Copy pathformat.yml
File metadata and controls
88 lines (71 loc) · 2.64 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: Format Code
on:
workflow_dispatch:
env:
NODE_VERSION: "24.15.0"
jobs:
format:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v7.0.0
- name: Set up Go
uses: actions/setup-go@v6.4.0
with:
go-version-file: 'go.mod'
cache: true
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
- name: Set up pnpm
uses: pnpm/action-setup@v6.0.9
with:
package_json_file: web/package.json
- name: Install frontend dependencies
run: cd web && pnpm install
- name: Format code
run: make fmt || true
- name: Commit and create PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Check if there are any changes to commit
if [ -n "$(git status --porcelain)" ]; then
echo "Setting up git configuration..."
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Check if PR already exists
EXISTING_PR=$(gh pr list --head chore/auto-format --state open --json number --jq '.[0].number' 2>/dev/null || echo "")
if [ -n "$EXISTING_PR" ]; then
echo "Existing PR #$EXISTING_PR found, updating it..."
git fetch origin chore/auto-format || true
git checkout -B chore/auto-format
else
echo "Creating new branch and PR..."
git checkout -b chore/auto-format
fi
# Stage changes and exclude lockfile
git add .
git reset HEAD web/pnpm-lock.yaml 2>/dev/null || true
if git diff --staged --quiet; then
echo "No staged changes after excluding web/pnpm-lock.yaml; skipping commit/PR creation"
exit 0
fi
git commit -m "chore(fmt): auto-format code"
# Force push to ensure clean state (removes any unwanted previous commits)
git push --force-with-lease origin chore/auto-format
if [ -z "$EXISTING_PR" ]; then
echo "Creating pull request..."
gh pr create \
--title "chore(fmt): Auto-format code" \
--body "Auto-generated PR to format code using \`make fmt\` via \`.github/workflows/format.yml\`"
else
echo "Pull request #$EXISTING_PR updated successfully"
fi
else
echo "No formatting changes needed"
fi