Skip to content

CI: GitHub Actions

Jason Karns edited this page May 8, 2024 · 3 revisions

Configuration for GitHub Actions

Auto-Fix

This is a functioning GitHub Actions workflow that runs standard (via its rake task or bin-stub). It runs in fix mode, so any fixable errors are fixed immediately and committed back to the branch.

The standardrb command will error if there are any unfixable violations. The git-diff command will error if there are any fixes that weren't already in the branch. That means this job can be used as part of a merge-blocking PR workflow.

The autofix commits are made via git commit --fixup which enables them to be autosquashed during a rebase. (see git-config rebase.autoSquash and pull.rebase) Authorship is attributed to the most recent (HEAD) commit's author; with GitHub Actions bot as the committer.

# .github/workflows/format.yml
name: Format
on:
  push:
    branches-ignore: [main]
  workflow_dispatch:

env:
  RAILS_ENV: test

jobs:
  standardrb:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: ruby/setup-ruby@v1
        with:
          bundler-cache: true


      - run: bin/rake standard:fix && git diff --quiet
      # or 
      # run: bin/standardrb --fix && git diff --quiet

      # Commit & push any autoformatted changes
      # using most recent authorship and in an autosquash-friendly format.
      - if: failure()
        run: git commit -a --fixup=HEAD --author=. && git push
        env:
          GIT_COMMITTER_NAME: "github-actions[bot]"
          GIT_COMMITTER_EMAIL: "41898282+github-actions[bot]@users.noreply.github.com"
Clone this wiki locally