Skip to content

Commit

Permalink
Merge pull request #254 from alphagov/workflow-to-test-app
Browse files Browse the repository at this point in the history
Create a GitHub workflow to make it easy to test a repo against rubocop-govuk changes
  • Loading branch information
kevindew authored Nov 25, 2022
2 parents 31fe1cf + 76e3347 commit e939f94
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/run-against-project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# GitHub Workflow to allow running rubocop-govuk against an alphagov repo
# to test the effects of linting rules prior to releasing the gem.
#
# This is expected to be called manually via the GitHub UI (https://github.com/alphagov/rubocop-govuk/actions/workflows/run-against-project.yml)
# or via the GitHub CLI.
name: Run against project
run-name: Running rubocop-govuk (${{ inputs.git_ref }}) against ${{ inputs.alphagov_repo }}

on:
workflow_dispatch:
inputs:
alphagov_repo:
description: 'The alphagov repository to run rubocop-govuk against'
required: true
type: string
git_ref:
description: 'Commit, tag or branch name of rubocop-govuk to use'
required: true
type: string
default: 'main'

jobs:
lint_project:
runs-on: ubuntu-latest
steps:
- name: Cloning alphagov/${{ inputs.alphagov_repo }}
uses: actions/checkout@v3
with:
repository: alphagov/${{ inputs.alphagov_repo }}
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
# We need to turn off deployment mode so that we can modify the gems
- run: bundle config unset deployment
- run: bundle remove rubocop-govuk
# There is a `bundle add --github --ref` command we could have used,
# however the output of that falls foul of our linter (how ironic).
# Instead of fighting/correcting/accepting that we have this work
# around of amending the gemfile ourselves and running bundle install
# again.
- name: Amending gemfile for rubocop-govuk (${{ inputs.git_ref }})
run: |
printf '\ngem "rubocop-govuk", github: "alphagov/rubocop-govuk", ref: "${{ inputs.git_ref }}"\n' >> Gemfile
- name: Install rubcop-govuk gem
run: bundle install
- name: Run rubocop
run: |
# preserve exit code if rubocop fails
set -o pipefail
# use tee to output to stdout and populate GitHub summary
bundle exec rubocop --format markdown | tee $GITHUB_STEP_SUMMARY
6 changes: 1 addition & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ RuboCop GOV.UK is a styleguide, so each rule in each YAML file should have a com

Find out how much effort it will be to adopt your changes in typical GOV.UK repos. This could just be running `rubocop -A` to autocorrect new issues, or it could involve significant manual effort.

You can test changes locally by tweaking the Gemfile or `.gemspec` for the repo e.g.

```
gem "rubocop-govuk", path: "/govuk/rubocop-govuk"
```
You can test changes against an alphagov repo by [running the GitHub worflow](https://github.com/alphagov/rubocop-govuk/actions/workflows/run-against-project.yml) we have configured.

This is a rough list of typical GOV.UK repos we recommend testing against:

Expand Down

0 comments on commit e939f94

Please sign in to comment.