blob: b4dc41e4a119881ff71a90a1ea7409b1be51a11d [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
Josh Bleecher Snyderae772262025-04-25 20:02:22 +000015permissions:
16 contents: write
17
Philip Zeyliger4de80d22025-04-23 12:33:31 -070018jobs:
19 formatting:
20 runs-on: ubuntu-latest
21 steps:
22 - uses: actions/checkout@v4
Josh Bleecher Snyderbd6c1682025-04-25 12:04:07 -070023 with:
24 ref: ${{ github.head_ref || github.ref }}
25 # Need full history for queue-main pushes
26 fetch-depth: 0
Philip Zeyliger4de80d22025-04-23 12:33:31 -070027
28 # Setup for Prettier
29 - name: Setup Node.js
30 uses: actions/setup-node@v4
31 with:
Josh Bleecher Snyder6e42f322025-04-25 13:18:36 -070032 node-version: "20"
33 cache: "npm"
Philip Zeyliger2032b1c2025-04-23 19:40:42 -070034 cache-dependency-path: webui/package-lock.json
Philip Zeyliger4de80d22025-04-23 12:33:31 -070035
36 - name: Install dependencies
Philip Zeyliger2032b1c2025-04-23 19:40:42 -070037 working-directory: ./webui
Philip Zeyliger4de80d22025-04-23 12:33:31 -070038 run: npm ci
39
Philip Zeyliger4de80d22025-04-23 12:33:31 -070040 # Setup for gofumpt
41 - name: Setup Go
42 uses: actions/setup-go@v4
43 with:
44 go-version: stable
45 cache: true
46
47 - name: Install gofumpt v0.8.0
48 run: |
49 go install mvdan.cc/gofumpt@v0.8.0
50 echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
51
Philip Zeyliger8b00db12025-04-25 18:41:38 +000052 - name: Check formatting
Josh Bleecher Snyderbd6c1682025-04-25 12:04:07 -070053 if: inputs.auto_fix != true
Philip Zeyliger8b00db12025-04-25 18:41:38 +000054 run: bin/run-formatters.sh check
Josh Bleecher Snyderbd6c1682025-04-25 12:04:07 -070055
56 - name: Fix formatting
57 if: inputs.auto_fix == true
58 run: bin/run-formatters.sh fix
59
60 # Commit formatting fixes if auto_fix is true
61 - name: Commit and push formatting fixes if needed
62 if: inputs.auto_fix == true
63 run: |
64 # Only proceed if there are changes to commit
65 if [[ -z $(git status --porcelain) ]]; then
66 echo "No formatting changes detected, skipping commit"
67 exit 0
68 fi
69
70 git config --global user.name "Autoformatter"
71 git config --global user.email "bot@sketch.dev"
72 git add .
Josh Bleecher Snyder15a4db72025-04-25 13:18:06 -070073 git commit -m "all: fix formatting"
Josh Bleecher Snyderbd6c1682025-04-25 12:04:07 -070074
75 # If this is a queue-main branch, push the changes
76 if [[ "${{ github.ref }}" == refs/heads/queue-main-* ]]; then
Josh Bleecher Snyderae772262025-04-25 20:02:22 +000077 git push -f https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/boldsoftware/sketch.git HEAD
Josh Bleecher Snyderbd6c1682025-04-25 12:04:07 -070078 fi