From 842361ef3210d999a5bcb0991f02fe37309438d7 Mon Sep 17 00:00:00 2001 From: Patrick Cherry Date: Thu, 4 Jul 2024 13:06:11 +0100 Subject: [PATCH 1/6] Update workflows to check Changelog and build gem --- .github/workflows/build_publish.yml | 62 +++++++++++++++++++++++++++++ .github/workflows/changelog.yml | 29 ++++++++++++++ .github/workflows/ci.yml | 17 +++++--- .github/workflows/code_quality.yml | 11 +++++ .github/workflows/test.yml | 6 +-- 5 files changed, 116 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/build_publish.yml create mode 100644 .github/workflows/changelog.yml create mode 100644 .github/workflows/code_quality.yml diff --git a/.github/workflows/build_publish.yml b/.github/workflows/build_publish.yml new file mode 100644 index 0000000..407d068 --- /dev/null +++ b/.github/workflows/build_publish.yml @@ -0,0 +1,62 @@ +name: Build and publish + +on: + workflow_call: {} + +jobs: + build: + name: Build + runs-on: ubuntu-latest + permissions: + contents: read + packages: read + + steps: + - uses: actions/checkout@v3 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + + - name: Build gem + run: rake build + + - name: Archive coverage + if: success() + uses: actions/upload-artifact@v3 + with: + name: gem-pkg + path: pkg/*.gem + + publish: + name: Publish + needs: build + if: github.ref_type == 'tag' + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.2' + + - uses: actions/download-artifact@v3 + with: + name: gem-pkg + path: pkg/ + + - name: Publish to GPR + run: | + mkdir -p $HOME/.gem + touch $HOME/.gem/credentials + chmod 0600 $HOME/.gem/credentials + printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials + gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} pkg/*.gem + env: + GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}" + OWNER: ${{ github.repository_owner }} + diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml new file mode 100644 index 0000000..2d0d659 --- /dev/null +++ b/.github/workflows/changelog.yml @@ -0,0 +1,29 @@ +name: Changelog + +on: + pull_request: + branches: + - '**' + +jobs: + changelog-updated: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 1 + - name: Check if changelog updated + id: changed-files-specific + uses: tj-actions/changed-files@v44 + with: + base_sha: ${{ github.event.pull_request.base.sha }} + files: | + CHANGELOG.md + env: + GITHUB_TOKEN: ${{ github.token }} + + - name: Fail job if changelog not updated + if: steps.changed-files-specific.outputs.any_changed == 'false' + run: | + exit 1 + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4063259..df8fdc9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,14 +2,19 @@ name: CI on: push: - branches: [ main ] - pull_request: - branches: [ main ] + branches: + - '**' + tags: + - '**' jobs: test: if: github.ref_type == 'branch' && github.ref_name != 'main' uses: ./.github/workflows/test.yml - # code_quality: - # if: github.ref_type == 'branch' && github.ref_name != 'main' - # uses: ./.github/workflows/code_quality.yml + + code_quality: + if: github.ref_type == 'branch' && github.ref_name != 'main' + uses: ./.github/workflows/code_quality.yml + + build_publish: + uses: ./.github/workflows/build_publish.yml diff --git a/.github/workflows/code_quality.yml b/.github/workflows/code_quality.yml new file mode 100644 index 0000000..8516ba6 --- /dev/null +++ b/.github/workflows/code_quality.yml @@ -0,0 +1,11 @@ +name: 'Code quality' +on: + workflow_call + +jobs: + rubocop: + runs-on: ubuntu-latest + steps: + - name: Inspecting with Rubocop + run: rubocop + diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f1b7861..e13ba47 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: env: BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: @@ -32,7 +32,7 @@ jobs: - name: Archive coverage if: ${{ success() || failure() }} - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: code-coverage-report-ruby_${{ matrix.ruby-version }}-${{ matrix.gemfile }} path: ${{ github.workspace }}/coverage/ @@ -43,7 +43,7 @@ jobs: permissions: pull-requests: write steps: - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: code-coverage-report-ruby_3.2-rails_7.1 path: coverage/ From 41e8e740247df61096e79f2734746aa733a1caec Mon Sep 17 00:00:00 2001 From: Patrick Cherry Date: Thu, 4 Jul 2024 13:13:26 +0100 Subject: [PATCH 2/6] Fix up rubocop and gem builds --- .github/workflows/build_publish.yml | 2 +- .github/workflows/code_quality.yml | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_publish.yml b/.github/workflows/build_publish.yml index 407d068..c1415c3 100644 --- a/.github/workflows/build_publish.yml +++ b/.github/workflows/build_publish.yml @@ -20,7 +20,7 @@ jobs: bundler-cache: true - name: Build gem - run: rake build + run: bundle exec rake build - name: Archive coverage if: success() diff --git a/.github/workflows/code_quality.yml b/.github/workflows/code_quality.yml index 8516ba6..8895fb0 100644 --- a/.github/workflows/code_quality.yml +++ b/.github/workflows/code_quality.yml @@ -1,11 +1,18 @@ name: 'Code quality' on: - workflow_call + workflow_call: {} jobs: rubocop: + name: Rubocop runs-on: ubuntu-latest steps: + - uses: actions/checkout@v4 + + - uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + - name: Inspecting with Rubocop - run: rubocop + run: bundle exec rubocop From a779aa7b773ddf6daa438e2a461e50e6a187a1ec Mon Sep 17 00:00:00 2001 From: Patrick Cherry Date: Thu, 4 Jul 2024 13:16:20 +0100 Subject: [PATCH 3/6] Set gemfile location --- .github/workflows/build_publish.yml | 3 ++- .github/workflows/code_quality.yml | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_publish.yml b/.github/workflows/build_publish.yml index c1415c3..959490b 100644 --- a/.github/workflows/build_publish.yml +++ b/.github/workflows/build_publish.yml @@ -10,7 +10,8 @@ jobs: permissions: contents: read packages: read - + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_6.1.gemfile steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/code_quality.yml b/.github/workflows/code_quality.yml index 8895fb0..8c3e3fb 100644 --- a/.github/workflows/code_quality.yml +++ b/.github/workflows/code_quality.yml @@ -6,6 +6,8 @@ jobs: rubocop: name: Rubocop runs-on: ubuntu-latest + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_6.1.gemfile steps: - uses: actions/checkout@v4 From c4d9aa9050922f522755302160ed947f156deb9d Mon Sep 17 00:00:00 2001 From: Patrick Cherry Date: Thu, 4 Jul 2024 13:20:44 +0100 Subject: [PATCH 4/6] Update GH actions versions --- .github/workflows/build_publish.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_publish.yml b/.github/workflows/build_publish.yml index 959490b..9435188 100644 --- a/.github/workflows/build_publish.yml +++ b/.github/workflows/build_publish.yml @@ -13,7 +13,7 @@ jobs: env: BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_6.1.gemfile steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 @@ -25,7 +25,7 @@ jobs: - name: Archive coverage if: success() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: gem-pkg path: pkg/*.gem @@ -45,7 +45,7 @@ jobs: with: ruby-version: '3.2' - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: gem-pkg path: pkg/ From 86afab3cf3a905b25aa3058a2e4a65480fd53fe9 Mon Sep 17 00:00:00 2001 From: Patrick Cherry Date: Thu, 4 Jul 2024 13:29:03 +0100 Subject: [PATCH 5/6] Updated changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b196a46..cb846c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +* Workflow to automatically lint, check the changelog, and build & publish the gem (#73) + ## [v3.6.0] ### Added From f4a23ca3f661cb25ff3c4ac20dedc17f2dcf25f6 Mon Sep 17 00:00:00 2001 From: Patrick Cherry Date: Mon, 14 Apr 2025 11:55:54 +0100 Subject: [PATCH 6/6] Regenerate todo --- .github/workflows/code_quality.yml | 2 +- .rubocop_todo.yml | 6 +++--- lib/rpi_auth/spec_helpers.rb | 2 +- spec/dummy/spec/requests/auth_request_spec.rb | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/code_quality.yml b/.github/workflows/code_quality.yml index 8c3e3fb..7443081 100644 --- a/.github/workflows/code_quality.yml +++ b/.github/workflows/code_quality.yml @@ -7,7 +7,7 @@ jobs: name: Rubocop runs-on: ubuntu-latest env: - BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_6.1.gemfile + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_7.2.gemfile steps: - uses: actions/checkout@v4 diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 701fff0..7664846 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2024-07-02 19:48:59 UTC using RuboCop version 1.64.1. +# on 2025-04-14 10:55:46 UTC using RuboCop version 1.75.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -14,7 +14,7 @@ Gemspec/DevelopmentDependencies: Exclude: - 'rpi_auth.gemspec' -# Offense count: 1 +# Offense count: 2 # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: Max: 23 @@ -33,7 +33,7 @@ RSpec/MultipleExpectations: RSpec/MultipleMemoizedHelpers: Max: 6 -# Offense count: 10 +# Offense count: 12 # Configuration parameters: AllowedGroups. RSpec/NestedGroups: Max: 5 diff --git a/lib/rpi_auth/spec_helpers.rb b/lib/rpi_auth/spec_helpers.rb index f371d26..8d9e4a4 100644 --- a/lib/rpi_auth/spec_helpers.rb +++ b/lib/rpi_auth/spec_helpers.rb @@ -5,7 +5,7 @@ module SpecHelpers # This sets up the OmniAuth mock for the given user. It assumes the User # model has an `:user_id` method which returns the users ID, but this can # be changed by setting the `id_param` option. - def stub_auth_for(user:, id_param: :user_id) # rubocop:disable Metrics/AbcSize + def stub_auth_for(user:, id_param: :user_id) expires_in = user.respond_to?(:expires_at) ? user.expires_at.to_i - Time.zone.now.to_i : 3600 token = user.respond_to?(:access_token) ? user.access_token : SecureRandom.hex(16) refresh_token = user.respond_to?(:refresh_token) ? user.refresh_token : SecureRandom.hex(16) diff --git a/spec/dummy/spec/requests/auth_request_spec.rb b/spec/dummy/spec/requests/auth_request_spec.rb index 1eafd3b..b397395 100644 --- a/spec/dummy/spec/requests/auth_request_spec.rb +++ b/spec/dummy/spec/requests/auth_request_spec.rb @@ -256,7 +256,7 @@ expect(response).to redirect_to('/') end - context 'when the proc resolves to something other than nil' do # rubocop:disable RSpec/NestedGroups + context 'when the proc resolves to something other than nil' do # We use `current_user` and `request.env` here as they're available # in the context of the controller. We use `let!` to make sure the # proc is defined straightaway, rather than later, when `request` and @@ -274,7 +274,7 @@ end end - context 'when the proc raises an exception' do # rubocop:disable RSpec/NestedGroups + context 'when the proc raises an exception' do # We use `current_user` and `request.env` here as they're available # in the context of the controller. We use `let!` to make sure the # proc is defined straightaway, rather than later, when `request` and