base-org/op-viem

Format hook

wilsoncusack opened this issue · 2 comments

we should have pnpm format as a commit hook or github workflow

viem does this in a github workflow, requires using someone's github key though to sign the commit.

I do this via this autofix workflow at OP

name: Autofix PR

on:
  issue_comment:
    types: [created]

# Down scope as necessary via https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token
permissions:
  checks: write
  contents: write
  pull-requests: write

jobs:
  run-linters:
    name: Run linters
    if: github.event.issue.pull_request && ${{ github.event.comment.body == 'AUTOFIX' }}
    runs-on: ubuntu-latest

    steps:
      - name: GetBranch
        id: 'get-branch'
        run: echo ::set-output name=branch::$(gh pr view $PR_NO --repo $REPO --json headRefName --jq '.headRefName')
        env:
          REPO: ${{ github.repository }}
          PR_NO: ${{ github.event.issue.number }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Check out Git repository
        uses: actions/checkout@v3
        with:
          ref: ${{ steps.get-branch.outputs.branch }}

      - name: Setup
        uses: ./.github/actions/setup

      - name: Run linters
        run: |
          pnpm run lint:fix

      - name: Commit changes
        uses: stefanzweifel/git-auto-commit-action@v4
        with:
          commit_message: 'Autofix was triggerd to automatically fix linter'

      - name: Run jest -u
        run: |
          pnpm nx test:update @gateway/frontend

      - name: Commit changes
        uses: stefanzweifel/git-auto-commit-action@v4
        with:
          commit_message: 'Autofix was triggerd to automatically fix jest snapshots'