From 842361ef3210d999a5bcb0991f02fe37309438d7 Mon Sep 17 00:00:00 2001 From: Patrick Cherry Date: Thu, 4 Jul 2024 13:06:11 +0100 Subject: [PATCH 1/5] 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/5] 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/5] 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/5] 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/5] 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