blob: 1d9cc8d6793d1a686fb9a12acec4108ad8366837 [file] [log] [blame]
Philip Zeyliger4de80d22025-04-23 12:33:31 -07001name: Code Formatting
2on:
3 workflow_call:
Josh Bleecher Snyderbd6c1682025-04-25 12:04:07 -07004 inputs:
5 auto_fix:
6 description: "Automatically fix formatting issues instead of just checking"
7 required: false
8 type: boolean
9 default: false
Philip Zeyliger4de80d22025-04-23 12:33:31 -070010 push:
11 branches-ignore:
12 - "queue-main-**"
13 pull_request:
14
15jobs:
16 formatting:
17 runs-on: ubuntu-latest
18 steps:
19 - uses: actions/checkout@v4
Josh Bleecher Snyderbd6c1682025-04-25 12:04:07 -070020 with:
21 ref: ${{ github.head_ref || github.ref }}
22 # Need full history for queue-main pushes
23 fetch-depth: 0
Philip Zeyliger4de80d22025-04-23 12:33:31 -070024
25 # Setup for Prettier
26 - name: Setup Node.js
27 uses: actions/setup-node@v4
28 with:
29 node-version: '20'
30 cache: 'npm'
Philip Zeyliger2032b1c2025-04-23 19:40:42 -070031 cache-dependency-path: webui/package-lock.json
Philip Zeyliger4de80d22025-04-23 12:33:31 -070032
33 - name: Install dependencies
Philip Zeyliger2032b1c2025-04-23 19:40:42 -070034 working-directory: ./webui
Philip Zeyliger4de80d22025-04-23 12:33:31 -070035 run: npm ci
36
Philip Zeyliger4de80d22025-04-23 12:33:31 -070037 # Setup for gofumpt
38 - name: Setup Go
39 uses: actions/setup-go@v4
40 with:
41 go-version: stable
42 cache: true
43
44 - name: Install gofumpt v0.8.0
45 run: |
46 go install mvdan.cc/gofumpt@v0.8.0
47 echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
48
Philip Zeyliger8b00db12025-04-25 18:41:38 +000049 - name: Check formatting
Josh Bleecher Snyderbd6c1682025-04-25 12:04:07 -070050 if: inputs.auto_fix != true
Philip Zeyliger8b00db12025-04-25 18:41:38 +000051 run: bin/run-formatters.sh check
Josh Bleecher Snyderbd6c1682025-04-25 12:04:07 -070052
53 - name: Fix formatting
54 if: inputs.auto_fix == true
55 run: bin/run-formatters.sh fix
56
57 # Commit formatting fixes if auto_fix is true
58 - name: Commit and push formatting fixes if needed
59 if: inputs.auto_fix == true
60 run: |
61 # Only proceed if there are changes to commit
62 if [[ -z $(git status --porcelain) ]]; then
63 echo "No formatting changes detected, skipping commit"
64 exit 0
65 fi
66
67 git config --global user.name "Autoformatter"
68 git config --global user.email "bot@sketch.dev"
69 git add .
70 git commit -m "Automatic formatting fixes" -m "Applied automatic formatting with bin/run-formatters.sh"
71
72 # If this is a queue-main branch, push the changes
73 if [[ "${{ github.ref }}" == refs/heads/queue-main-* ]]; then
74 git push -f origin HEAD
75 fi