From c88330076cc068bb97d5447cda8807e21e6daa19 Mon Sep 17 00:00:00 2001 From: Rebecca Phuonghanh Dang Date: Mon, 17 Jun 2024 20:38:15 -0700 Subject: [PATCH 1/7] Rename reviewdog.yml to linters.yml and add Rubocop job --- .../workflows/{reviewdog.yml => linters.yml} | 19 ++++++++++++++++++- .rubocop.yml | 0 Gemfile | 5 +++++ 3 files changed, 23 insertions(+), 1 deletion(-) rename .github/workflows/{reviewdog.yml => linters.yml} (75%) create mode 100644 .rubocop.yml diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/linters.yml similarity index 75% rename from .github/workflows/reviewdog.yml rename to .github/workflows/linters.yml index 93951da..accf639 100644 --- a/.github/workflows/reviewdog.yml +++ b/.github/workflows/linters.yml @@ -1,4 +1,4 @@ -name: reviewdog +name: Linters on: [pull_request] jobs: pylint: @@ -42,3 +42,20 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} reporter: github-pr-check + + rubocop: + name: runner / rubocop + runs-on: ubuntu-latest + env: + BUNDLE_ONLY: rubocop + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.3' + bundler-cache: true + - uses: reviewdog/action-rubocop@v2 + with: + reporter: github-pr-check + skip_install: true + use_bundler: true diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..e69de29 diff --git a/Gemfile b/Gemfile index 3040e60..9d28ee8 100644 --- a/Gemfile +++ b/Gemfile @@ -11,3 +11,8 @@ group :development, :test do gem "axe-core-rspec" gem "axe-core-capybara" end + +group :development, :rubocop do + gem "rubocop", require: false + gem "rubocop-rspec", require: false +end From 0d4bbed55e57ddbdb9509d0ca46d56f80b3ba7e3 Mon Sep 17 00:00:00 2001 From: Rebecca Phuonghanh Dang Date: Mon, 17 Jun 2024 20:39:35 -0700 Subject: [PATCH 2/7] Make rspec.yml workflow name more specific, run on all pushes --- .github/workflows/rspec.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index 0eef58b..00098ea 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -1,6 +1,6 @@ -name: Run rspec tests +name: Run all page tests -on: [pull_request] +on: [pull_request, push] jobs: build: From a5308a31d4db5b985eb03f1b434c759f6ff138a9 Mon Sep 17 00:00:00 2001 From: Rebecca Phuonghanh Dang Date: Mon, 17 Jun 2024 20:52:31 -0700 Subject: [PATCH 3/7] Add PR write permissions on linters.yml --- .github/workflows/linters.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index accf639..3cdaeca 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -1,5 +1,8 @@ name: Linters on: [pull_request] +permissions: + contents: read + pull-requests: write jobs: pylint: name: runner / pylint From 8c64d48ddccc2a3a8530ceca5716542ee27b0b07 Mon Sep 17 00:00:00 2001 From: Rebecca Phuonghanh Dang Date: Mon, 17 Jun 2024 20:52:40 -0700 Subject: [PATCH 4/7] Enable new cops in .rubocop.yml --- .rubocop.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index e69de29..3b64504 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -0,0 +1,2 @@ +AllCops: + NewCops: enable From c6ffc3c20d3e746f5458964b53889535b4ebc640 Mon Sep 17 00:00:00 2001 From: Rebecca Phuonghanh Dang Date: Mon, 17 Jun 2024 20:53:25 -0700 Subject: [PATCH 5/7] Run `bundle exec rubocop --autocorrect` --- Gemfile | 16 ++++++++-------- spec/accessibility_spec.rb | 12 ++++++------ spec/spec_helper.rb | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Gemfile b/Gemfile index 9d28ee8..d0b2ede 100644 --- a/Gemfile +++ b/Gemfile @@ -4,15 +4,15 @@ gem 'jekyll-sitemap' gem 'webrick' group :development, :test do - gem "rspec" - gem "selenium-webdriver" - gem "capybara" - gem "rack-jekyll" - gem "axe-core-rspec" - gem "axe-core-capybara" + gem 'axe-core-capybara' + gem 'axe-core-rspec' + gem 'capybara' + gem 'rack-jekyll' + gem 'rspec' + gem 'selenium-webdriver' end group :development, :rubocop do - gem "rubocop", require: false - gem "rubocop-rspec", require: false + gem 'rubocop', require: false + gem 'rubocop-rspec', require: false end diff --git a/spec/accessibility_spec.rb b/spec/accessibility_spec.rb index 96c6f16..ee1ab1e 100644 --- a/spec/accessibility_spec.rb +++ b/spec/accessibility_spec.rb @@ -1,21 +1,21 @@ -describe "course website", type: :feature, js: true do +describe 'course website', type: :feature, js: true do before :all do visit('/sitemap.xml') - sitemap_links = page.html.scan(/.+<\/loc>/) + sitemap_links = page.html.scan(%r{.+}) @links = [] sitemap_links.each do |link| - # TODO don't hardcode base url + # TODO: don't hardcode base url first_removed = link.sub('https://phrdang.github.io/berkeley-class-site', '') last_removed = first_removed.sub('', '') @links.push(last_removed) end end - # TODO run each page's axe check separately so it doesn't exit on first failure - it "is accessible" do + # TODO: run each page's axe check separately so it doesn't exit on first failure + it 'is accessible' do @links.each do |link| visit(link) expect(page).to be_axe_clean.according_to :wcag2a, "path: #{link} not accessible" end end -end \ No newline at end of file +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9a7d4f1..ddd9c32 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -72,7 +72,7 @@ # https://stackoverflow.com/questions/52506822/testing-a-jekyll-site-with-rspec-and-capybara-getting-a-bizarre-race-case-on-rs sleep 0.1 while jekyll_app.compiling? - + Capybara.app = jekyll_app # Configure Capybara server (otherwise it will error and say to use webrick or puma) From 71007728bc17b015639fdd5cd31278c088f24542 Mon Sep 17 00:00:00 2001 From: Rebecca Phuonghanh Dang Date: Mon, 17 Jun 2024 21:08:41 -0700 Subject: [PATCH 6/7] Add rubocop instructions to CONTRIBUTING.md --- .github/CONTRIBUTING.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 0eb011b..ff3cc43 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -6,6 +6,10 @@ TODO write docs for staff here TODO Info here about workflows and links +Most of the linters in `.github/workflows/linters.yml` are powered by [reviewdog](https://github.com/reviewdog/reviewdog). + +Run `bundle exec rubocop` to run [Rubocop](https://rubocop.org/). To autocorrect certain errors, run `bundle exec rubocop --autocorrect`. + ## Testing To run tests, run `bundle exec rspec` From 30ef534653d1f600765c3ac0d2cb577e4a67b0f1 Mon Sep 17 00:00:00 2001 From: Rebecca Phuonghanh Dang Date: Mon, 17 Jun 2024 21:09:39 -0700 Subject: [PATCH 7/7] Set filter_mode: nofilter and fail_on_error: true for reviewdog linters - `nofilter` means it will check the entire repository not just the stuff added in the most recent commit of the PR - `fail_on_error` means the github action fails (e.g. shows up red instead of green) --- .github/workflows/linters.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 3cdaeca..fb90c8e 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -18,6 +18,8 @@ jobs: # GitHub Status Check won't become failure with warning. level: warning glob_pattern: "**/*.py" + filter_mode: nofilter + fail_on_error: true black: name: runner / black @@ -29,11 +31,13 @@ jobs: id: action_black with: black_args: "." + fail_on_error: true - name: Annotate diff changes using reviewdog if: steps.action_black.outputs.is_formatted == 'true' uses: reviewdog/action-suggester@v1 with: tool_name: blackfmt + # NOTE: the reviewdog filter_mode is diff_context - this is the only thing supported by GitHub suggestions markdownlint: name: runner / markdownlint @@ -45,6 +49,8 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} reporter: github-pr-check + filter_mode: nofilter + fail_on_error: true rubocop: name: runner / rubocop @@ -62,3 +68,5 @@ jobs: reporter: github-pr-check skip_install: true use_bundler: true + filter_mode: nofilter + fail_on_error: true