Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a GitHub workflow to lint a repo
This is an attempt to automate a frequent source of toil (and a classic example of spending 20 times as long automating a task as it would take to do it) where we test [rubocop-govuk against a few repos on local machines][1] before releasing a new version. The approach to reduce this toil is create a GitHub Action Workflow that can be [executed manually][2] that will clone an alphagov repo, switch the rubocop-govuk version to the git reference provided by the workflow, and run rubocop against it. As this will only be executed manually there are some risks it may degrade with time. There is also a risk that it won't work for some alphagov projects, should they have extra system dependency needs to install gems. These are some examples of the job running against projects: - [Whitehall](https://github.com/alphagov/rubocop-govuk/actions/runs/3543847135) - [Content Publisher](https://github.com/alphagov/rubocop-govuk/actions/runs/3543848200) - [GDS API Adapters](https://github.com/alphagov/rubocop-govuk/actions/runs/3543849527) - [Search API](https://github.com/alphagov/rubocop-govuk/actions/runs/3543850013) --- There were a few quirks/decisions when putting this together: The first was whether to utilise bundler cache or not and whether it was problematic to share a cache with different apps. I decided it'd be useful as there's probably a lot of cross-over between the gems of apps. However setting bundler-cache on ruby/setup-ruby does put bundler into deployment mode and I couldn't work out how to disable that with env vars (BUNDLE_DEPLOYMENT=false failed) so I had to add an extra step to resolve this. The second issue was using `bundle add rubocop-govuk --github=alphagov/rubocop-govuk --ref=main` to add the git reference of the gem. This added a line like: `gem "rubocop-govuk", "~> 4.8", :github => "alphagov/rubocop-govuk", :ref => "main"` which fails linting 🤦. I consider adding a step of `bundle exec rubocop -A Gemfile` which would fix the issue but this seemed a bit contrived. I instead went for the rather janky looking printf step. Another issue was thinking how best to communicate the results. I thought it would be nice to use the [GitHub Action summary][3] as a way to output it to the action summary screen and avoid a few clicks. However I didn't want to lose the information in the run output. Hence I used `tee` as a way to do both. Using the markdown formatter for Rubocop allowed this summary to be nicely formatted for GitHub. Finally, I was pondering whether we want a job to fail when linting fails. In theory if the linting fails the job isn't an error because we're running it to just see the linting output and just managing to lint is a success. However I felt that doing this was potentially misleading and could lead to missing problematic rules. Ideally it'd be nice to have a neutral exit state (such as unstable for Jenkins) to indicate the item ran without error but wasn't a success. [1]: https://github.com/alphagov/rubocop-govuk/blob/e6d5c03ad5cbbac1fc5a711731e79af0d8a2fbc7/CONTRIBUTING.md#1-check-what-the-impact-is-going-to-be [2]: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch [3]: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary
- Loading branch information