coder/.github/workflows/pr-format.yaml

55 lines
1.5 KiB
YAML

name: Format a PR
on:
issue_comment:
types: [created]
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
fmt:
if: github.event.issue.pull_request && contains(github.event.comment.body, '\fmt') || github.event_name == 'workflow_dispatch'
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
timeout-minutes: 7
steps:
- name: PR comment with reactions
uses: thollander/actions-comment-pull-request@v2
with:
reactions: eyes
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.issue.pull_request.head.ref }}
- name: Setup Node
uses: ./.github/actions/setup-node
- name: Setup Go
uses: buildjet/setup-go@v5
with:
# This doesn't need caching. It's super fast anyways!
cache: false
go-version: 1.21.9
- name: Install shfmt
run: go install mvdan.cc/sh/v3/cmd/shfmt@v3.7.0
- name: make fmt
run: |
export PATH=${PATH}:$(go env GOPATH)/bin
make --output-sync -j -B fmt
- name: Commit and push changes
run: |
git config --global user.name "cdrci"
git config --global user.email "ci@coder.com"
git add -A
git commit -m "Automated formatting by make fmt"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}