blob: 5cc77e3745ffe81f07c873a7d4c598d6c1555eb8 [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:
Josh Bleecher Snyderc3391a92025-04-25 21:03:33 +000020 outputs:
21 commit_sha: ${{ steps.get_commit.outputs.commit_sha }}
Philip Zeyliger4de80d22025-04-23 12:33:31 -070022 runs-on: ubuntu-latest
23 steps:
24 - uses: actions/checkout@v4
Josh Bleecher Snyderbd6c1682025-04-25 12:04:07 -070025 with:
26 ref: ${{ github.head_ref || github.ref }}
27 # Need full history for queue-main pushes
28 fetch-depth: 0
Philip Zeyliger4de80d22025-04-23 12:33:31 -070029
30 # Setup for Prettier
31 - name: Setup Node.js
32 uses: actions/setup-node@v4
33 with:
Josh Bleecher Snyder6e42f322025-04-25 13:18:36 -070034 node-version: "20"
35 cache: "npm"
Philip Zeyliger2032b1c2025-04-23 19:40:42 -070036 cache-dependency-path: webui/package-lock.json
Philip Zeyliger4de80d22025-04-23 12:33:31 -070037
38 - name: Install dependencies
Philip Zeyliger2032b1c2025-04-23 19:40:42 -070039 working-directory: ./webui
Philip Zeyliger4de80d22025-04-23 12:33:31 -070040 run: npm ci
41
Philip Zeyliger4de80d22025-04-23 12:33:31 -070042 # Setup for gofumpt
43 - name: Setup Go
44 uses: actions/setup-go@v4
45 with:
46 go-version: stable
47 cache: true
48
49 - name: Install gofumpt v0.8.0
50 run: |
51 go install mvdan.cc/gofumpt@v0.8.0
52 echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
53
Philip Zeyliger8b00db12025-04-25 18:41:38 +000054 - name: Check formatting
Josh Bleecher Snyderbd6c1682025-04-25 12:04:07 -070055 if: inputs.auto_fix != true
Philip Zeyliger8b00db12025-04-25 18:41:38 +000056 run: bin/run-formatters.sh check
Josh Bleecher Snyderbd6c1682025-04-25 12:04:07 -070057
58 - name: Fix formatting
59 if: inputs.auto_fix == true
60 run: bin/run-formatters.sh fix
61
62 # Commit formatting fixes if auto_fix is true
63 - name: Commit and push formatting fixes if needed
64 if: inputs.auto_fix == true
65 run: |
66 # Only proceed if there are changes to commit
67 if [[ -z $(git status --porcelain) ]]; then
68 echo "No formatting changes detected, skipping commit"
69 exit 0
70 fi
71
72 git config --global user.name "Autoformatter"
73 git config --global user.email "bot@sketch.dev"
74 git add .
Josh Bleecher Snyder15a4db72025-04-25 13:18:06 -070075 git commit -m "all: fix formatting"
Josh Bleecher Snyderbd6c1682025-04-25 12:04:07 -070076
77 # If this is a queue-main branch, push the changes
78 if [[ "${{ github.ref }}" == refs/heads/queue-main-* ]]; then
Josh Bleecher Snyderae772262025-04-25 20:02:22 +000079 git push -f https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/boldsoftware/sketch.git HEAD
Josh Bleecher Snyderbd6c1682025-04-25 12:04:07 -070080 fi
Josh Bleecher Snyderc3391a92025-04-25 21:03:33 +000081
82 - name: Get commit SHA
83 id: get_commit
84 run: echo "commit_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT