blob: 2920665c8ea99d8f642738e9791318572f56471a [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
Josh Bleecher Snydereda2a8c2025-04-25 21:24:11 +000010 outputs:
11 commit_sha:
12 description: "The SHA of the commit with formatting fixes"
13 value: ${{ jobs.formatting.outputs.commit_sha }}
Philip Zeyliger4de80d22025-04-23 12:33:31 -070014 push:
15 branches-ignore:
16 - "queue-main-**"
17 pull_request:
18
Josh Bleecher Snyderae772262025-04-25 20:02:22 +000019permissions:
20 contents: write
21
Philip Zeyliger4de80d22025-04-23 12:33:31 -070022jobs:
23 formatting:
Josh Bleecher Snyderc3391a92025-04-25 21:03:33 +000024 outputs:
25 commit_sha: ${{ steps.get_commit.outputs.commit_sha }}
Philip Zeyliger4de80d22025-04-23 12:33:31 -070026 runs-on: ubuntu-latest
27 steps:
28 - uses: actions/checkout@v4
Josh Bleecher Snyderbd6c1682025-04-25 12:04:07 -070029 with:
30 ref: ${{ github.head_ref || github.ref }}
31 # Need full history for queue-main pushes
32 fetch-depth: 0
Philip Zeyliger4de80d22025-04-23 12:33:31 -070033
34 # Setup for Prettier
35 - name: Setup Node.js
36 uses: actions/setup-node@v4
37 with:
Josh Bleecher Snyder6e42f322025-04-25 13:18:36 -070038 node-version: "20"
39 cache: "npm"
Philip Zeyliger2032b1c2025-04-23 19:40:42 -070040 cache-dependency-path: webui/package-lock.json
Philip Zeyliger4de80d22025-04-23 12:33:31 -070041
42 - name: Install dependencies
Philip Zeyliger2032b1c2025-04-23 19:40:42 -070043 working-directory: ./webui
Philip Zeyliger4de80d22025-04-23 12:33:31 -070044 run: npm ci
45
Philip Zeyliger4de80d22025-04-23 12:33:31 -070046 # Setup for gofumpt
47 - name: Setup Go
48 uses: actions/setup-go@v4
49 with:
50 go-version: stable
51 cache: true
52
53 - name: Install gofumpt v0.8.0
54 run: |
55 go install mvdan.cc/gofumpt@v0.8.0
56 echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
57
Philip Zeyliger8b00db12025-04-25 18:41:38 +000058 - name: Check formatting
Josh Bleecher Snyderbd6c1682025-04-25 12:04:07 -070059 if: inputs.auto_fix != true
Philip Zeyliger8b00db12025-04-25 18:41:38 +000060 run: bin/run-formatters.sh check
Josh Bleecher Snyderbd6c1682025-04-25 12:04:07 -070061
62 - name: Fix formatting
63 if: inputs.auto_fix == true
64 run: bin/run-formatters.sh fix
65
66 # Commit formatting fixes if auto_fix is true
67 - name: Commit and push formatting fixes if needed
68 if: inputs.auto_fix == true
69 run: |
70 # Only proceed if there are changes to commit
71 if [[ -z $(git status --porcelain) ]]; then
72 echo "No formatting changes detected, skipping commit"
73 exit 0
74 fi
75
76 git config --global user.name "Autoformatter"
77 git config --global user.email "bot@sketch.dev"
78 git add .
Josh Bleecher Snyder15a4db72025-04-25 13:18:06 -070079 git commit -m "all: fix formatting"
Josh Bleecher Snyderbd6c1682025-04-25 12:04:07 -070080
81 # If this is a queue-main branch, push the changes
82 if [[ "${{ github.ref }}" == refs/heads/queue-main-* ]]; then
Josh Bleecher Snyderae772262025-04-25 20:02:22 +000083 git push -f https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/boldsoftware/sketch.git HEAD
Josh Bleecher Snyderbd6c1682025-04-25 12:04:07 -070084 fi
Josh Bleecher Snyderc3391a92025-04-25 21:03:33 +000085
86 - name: Get commit SHA
87 id: get_commit
88 run: echo "commit_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT