-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: standardize ci; version bump spec (#136)
- Loading branch information
Showing
7 changed files
with
100 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
name: Default | ||
|
||
on: | ||
push: | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build_and_publish: | ||
name: Build and Publish | ||
uses: wealthsimple/public-github-workflows/.github/workflows/ruby-gem-build.yaml@main | ||
secrets: inherit |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Pheme | ||
VERSION = '5.3.3'.freeze | ||
VERSION = '5.3.4'.freeze | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,87 @@ | ||
require 'git' | ||
require 'parse_a_changelog' | ||
|
||
describe Pheme do | ||
RSpec.describe 'a published gem' do # rubocop:disable RSpec/DescribeClass | ||
def get_version(git, branch = 'HEAD') | ||
git.grep('VERSION = ', 'lib/*/version.rb', { object: branch }). | ||
map { |_sha, matches| matches.first[1] }. | ||
filter_map { |version_string| parse_version(version_string) }. | ||
filter_map { |str| parse_version(str) }. | ||
first | ||
rescue Git::GitExecuteError | ||
# Catches failures for branch name being master | ||
nil | ||
end | ||
|
||
def parse_version(string) | ||
string.match(/VERSION = ['"](.*)['"]/)[1] | ||
end | ||
|
||
def main_branch | ||
@main_branch ||= | ||
if git.branches['origin/main'] | ||
'origin/main' | ||
elsif git.branches['origin/master'] | ||
'origin/master' | ||
else | ||
raise StandardError, | ||
<<~ERROR | ||
Couldn't determine main branch. | ||
Does 'origin/main' or 'origin/master' need to be fetched? | ||
ERROR | ||
end | ||
end | ||
|
||
def needs_version_bump? | ||
base = git.merge_base(main_branch, 'HEAD').first&.sha | ||
base ||= main_branch | ||
git.diff(base, 'HEAD').any? { |diff| | ||
not_gemfile?(diff) && not_dotfile?(diff) && not_docs?(diff) && not_spec?(diff) | ||
} | ||
end | ||
|
||
def not_gemfile?(diff) | ||
['Gemfile', 'Gemfile.lock'].exclude?(diff.path) | ||
end | ||
|
||
def not_docs?(diff) | ||
!diff.path.end_with?('.md') | ||
end | ||
|
||
def not_spec?(diff) | ||
!diff.path.start_with?('spec/') | ||
end | ||
|
||
def not_dotfile?(diff) | ||
# Ignore dotfiles, like .gitignore and CI files like .github/... | ||
!diff.path.start_with?('.') | ||
end | ||
|
||
let(:git) { Git.open('.') } | ||
let(:head_version) { get_version(git, 'HEAD') } | ||
|
||
it 'has a version number' do | ||
git = Git.open('.') | ||
head_version = get_version(git, 'HEAD') | ||
expect(head_version).not_to be_nil | ||
end | ||
|
||
it 'has a bumped version' do | ||
git = Git.open('.') | ||
main_version = get_version(git, 'origin/main') | ||
it 'has a bumped version committed' do | ||
main_version = get_version(git, main_branch) | ||
skip('first time publishing, no need to compare versions') if main_version.nil? | ||
|
||
is_main_branch = git.current_branch == 'main' | ||
is_main_branch = git.current_branch == main_branch | ||
skip('already on main branch, no need to compare versions') if is_main_branch | ||
|
||
head_version = get_version(git, 'HEAD') | ||
puts "head_version " + head_version | ||
raise 'no version.rb file found on the current branch' if head_version.nil? | ||
skip('Diff only contains non-code changes, no need to bump version') unless needs_version_bump? | ||
|
||
expect(Gem::Version.new(head_version)).to be > Gem::Version.new(main_version) | ||
end | ||
|
||
it 'has a CHANGELOG.md file' do | ||
expect(File).to exist('CHANGELOG.md') | ||
end | ||
|
||
it 'has changelog entry for current version' do | ||
parser = ParseAChangelog.parse('CHANGELOG.md') | ||
versions = parser.elements[2].elements.map { |element| element.elements[1].text_value } | ||
expect(versions.first).to include(head_version) | ||
end | ||
end |