| Philip Zeyliger | 4de80d2 | 2025-04-23 12:33:31 -0700 | [diff] [blame] | 1 | name: Code Formatting |
| 2 | on: |
| 3 | workflow_call: |
| Josh Bleecher Snyder | bd6c168 | 2025-04-25 12:04:07 -0700 | [diff] [blame] | 4 | inputs: |
| 5 | auto_fix: |
| 6 | description: "Automatically fix formatting issues instead of just checking" |
| 7 | required: false |
| 8 | type: boolean |
| 9 | default: false |
| Philip Zeyliger | 4de80d2 | 2025-04-23 12:33:31 -0700 | [diff] [blame] | 10 | push: |
| 11 | branches-ignore: |
| 12 | - "queue-main-**" |
| 13 | pull_request: |
| 14 | |
| 15 | jobs: |
| 16 | formatting: |
| 17 | runs-on: ubuntu-latest |
| 18 | steps: |
| 19 | - uses: actions/checkout@v4 |
| Josh Bleecher Snyder | bd6c168 | 2025-04-25 12:04:07 -0700 | [diff] [blame] | 20 | with: |
| 21 | ref: ${{ github.head_ref || github.ref }} |
| 22 | # Need full history for queue-main pushes |
| 23 | fetch-depth: 0 |
| Philip Zeyliger | 4de80d2 | 2025-04-23 12:33:31 -0700 | [diff] [blame] | 24 | |
| 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 Zeyliger | 2032b1c | 2025-04-23 19:40:42 -0700 | [diff] [blame] | 31 | cache-dependency-path: webui/package-lock.json |
| Philip Zeyliger | 4de80d2 | 2025-04-23 12:33:31 -0700 | [diff] [blame] | 32 | |
| 33 | - name: Install dependencies |
| Philip Zeyliger | 2032b1c | 2025-04-23 19:40:42 -0700 | [diff] [blame] | 34 | working-directory: ./webui |
| Philip Zeyliger | 4de80d2 | 2025-04-23 12:33:31 -0700 | [diff] [blame] | 35 | run: npm ci |
| 36 | |
| Philip Zeyliger | 4de80d2 | 2025-04-23 12:33:31 -0700 | [diff] [blame] | 37 | # 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 Zeyliger | 8b00db1 | 2025-04-25 18:41:38 +0000 | [diff] [blame] | 49 | - name: Check formatting |
| Josh Bleecher Snyder | bd6c168 | 2025-04-25 12:04:07 -0700 | [diff] [blame] | 50 | if: inputs.auto_fix != true |
| Philip Zeyliger | 8b00db1 | 2025-04-25 18:41:38 +0000 | [diff] [blame] | 51 | run: bin/run-formatters.sh check |
| Josh Bleecher Snyder | bd6c168 | 2025-04-25 12:04:07 -0700 | [diff] [blame] | 52 | |
| 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 |