-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c22110
commit 5a1ce8f
Showing
12 changed files
with
163 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: "Gem Version Checker" | ||
|
||
on: | ||
workflow_dispatch: {} | ||
schedule: | ||
- cron: '00 13 * * 3' # Runs at 13:00 UTC, Every Wednesday. | ||
|
||
env: | ||
SEAL_ORGANISATION: alphagov | ||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | ||
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | ||
|
||
jobs: | ||
gem-version-checker: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
bundler-cache: true | ||
|
||
- name: Gem Version Checker | ||
id: gem_version_checker | ||
run: | | ||
./bin/seal_runner.rb gems |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require "uri" | ||
require "net/http" | ||
require "json" | ||
require_relative "slack_poster" | ||
|
||
class GemVersionChecker | ||
def print_version_discrepancies(gems) | ||
gems.filter_map { |gem| | ||
repo_name = gem["app_name"] | ||
repo_url = gem["links"]["repo_url"] | ||
rubygems_version = fetch_rubygems_version(repo_name) | ||
if rubygems_version && change_is_significant?(repo_name, rubygems_version) | ||
"<#{repo_url}|#{repo_name}> has unreleased changes since v#{rubygems_version}" | ||
end | ||
}.join("\n") | ||
end | ||
|
||
def fetch_rubygems_version(gem_name) | ||
uri = URI("https://rubygems.org/api/v1/gems/#{gem_name}.json") | ||
res = Net::HTTP.get_response(uri) | ||
|
||
JSON.parse(res.body)["version"] if res.is_a?(Net::HTTPSuccess) | ||
end | ||
|
||
def files_changed_since_tag(repo, tag) | ||
Dir.mktmpdir do |path| | ||
Dir.chdir(path) do | ||
if system("git clone --recursive --depth 1 --shallow-submodules --no-single-branch https://github.com/alphagov/#{repo}.git > /dev/null 2>&1") | ||
Dir.chdir(repo) { `git diff --name-only #{tag}`.split("\n") } | ||
else | ||
puts "Warning: Failed to clone #{repo}" | ||
[] | ||
end | ||
end | ||
end | ||
end | ||
|
||
def change_is_significant?(repo_name, previous_version) | ||
files_changed_since_tag(repo_name, "v#{previous_version}").any? do |path| | ||
path.start_with?("app/", "lib/") || path == "CHANGELOG.md" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require "./lib/gem_version_checker" | ||
|
||
RSpec.describe GemVersionChecker do | ||
subject(:gem_version_checker) { described_class.new } | ||
|
||
let(:slack_poster) { instance_double(SlackPoster, send_request: nil) } | ||
|
||
before do | ||
allow(SlackPoster).to receive(:new).and_return(slack_poster) | ||
end | ||
|
||
it "fetches version number of a gem from rubygems" do | ||
stub_rubygems_call("6.0.1") | ||
|
||
expect(gem_version_checker.fetch_rubygems_version("example")).to eq("6.0.1") | ||
end | ||
|
||
it "detects when there are no files changed since the last release that are built into the gem" do | ||
stub_devdocs_call | ||
stub_rubygems_call("1.2.3") | ||
stub_files_changed_since_tag(["README.md"]) | ||
|
||
expect { gem_version_checker.print_version_discrepancies }.to output("team: #platform-security-reliability-team\n").to_stdout | ||
end | ||
|
||
it "detects when there are files changed since the last release that are built into the gem" do | ||
stub_devdocs_call | ||
stub_rubygems_call("1.2.2") | ||
stub_files_changed_since_tag(["lib/foo.rb"]) | ||
|
||
expect { gem_version_checker.print_version_discrepancies }.to output( | ||
"team: #platform-security-reliability-team\n<https://example.com|example> has unreleased changes since v1.2.2\n", | ||
).to_stdout | ||
end | ||
|
||
def stub_files_changed_since_tag(files) | ||
allow(gem_version_checker).to receive(:files_changed_since_tag) do | ||
files | ||
end | ||
end | ||
|
||
def stub_rubygems_call(version) | ||
repo = { "version": version } | ||
stub_request(:get, "https://rubygems.org/api/v1/gems/example.json") | ||
.to_return(status: 200, body: repo.to_json, headers: {}) | ||
end | ||
|
||
def stub_devdocs_call | ||
repo = [{ "app_name": "example", "team": "#platform-security-reliability-team", "links": { "repo_url": "https://example.com" } }] | ||
stub_request(:get, "https://docs.publishing.service.gov.uk/gems.json") | ||
.to_return(status: 200, body: repo.to_json, headers: {}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= @message %> |