Skip to content

Commit

Permalink
fix: standardize ci; version bump spec (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
rperryng authored Jul 2, 2024
1 parent 8487866 commit 2659eb5
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 75 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/default.yaml
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
58 changes: 0 additions & 58 deletions .github/workflows/main.yml

This file was deleted.

17 changes: 13 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

## 5.3.4 - 2024-06-14
### Changed
- Updated dependencies

## 5.3.3 - 2024-06-14
### Changed
- Updated dependencies
Expand Down Expand Up @@ -169,7 +175,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Updated dependencies

### 5.0.4 - 2022-04-01
## 5.0.4 - 2022-04-01
### Changed
- Updated workflows

Expand Down Expand Up @@ -246,17 +252,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Migrate CI from CircleCI to GitHub Actions

## 4.0.3 - 2021-03-08
### Changed
- Update documentation to include instructions on directly publishing to SQS

## 4.0.2 - 2020-12-17
### Changed
- Bump local dev version, rubocop fixes, add backstage catalog file + sonarqube project settings

## 4.0.1 - 2020-03-23
### Fixes
### Fixed
- Fixes 4.0.0. Instead of expecting message attributes in the message from `poll`, retrieves them from the right place.

## 4.0.0 - 2020-03-18
### Breaking Changes
### Changed
- Add the ability for SQS to receive message attributes
- `handle` function of `QueuePoller` now takes a third parameter `message_attributes`
- blocks or `MessageHandler`s passed to `QueuePoller` can use this `message_attributes`
Expand Down Expand Up @@ -302,6 +310,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## 2.0.1 - 2019-01-03
### Changed
- add internal gem spec to test standard gem behavior, reduces unnecessary copy and pasting

### Fixed
- namespace for the VERSION constant was incorrectly set to Ws::Ws

Expand Down
8 changes: 7 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
pheme (5.3.3)
pheme (5.3.4)
activesupport (>= 4)
aws-sdk-sns (~> 1.1)
aws-sdk-sqs (~> 1.3)
Expand Down Expand Up @@ -63,9 +63,12 @@ GEM
minitest (5.23.1)
mutex_m (0.2.0)
parallel (1.25.1)
parse_a_changelog (1.3.0)
treetop (~> 1.6)
parser (3.3.3.0)
ast (~> 2.4.1)
racc
polyglot (0.3.5)
process_executer (1.1.0)
public_suffix (5.0.5)
racc (1.8.0)
Expand Down Expand Up @@ -149,6 +152,8 @@ GEM
rubocop-rails (~> 2.23.1)
strscan (3.1.0)
thor (1.3.1)
treetop (1.6.12)
polyglot (~> 0.3)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
Expand All @@ -167,6 +172,7 @@ DEPENDENCIES
bundler
bundler-audit
git
parse_a_changelog
pheme!
rake
rspec
Expand Down
2 changes: 1 addition & 1 deletion lib/pheme/version.rb
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
1 change: 1 addition & 0 deletions pheme.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Gem::Specification.new do |s|

s.add_development_dependency 'bundler'
s.add_development_dependency 'git'
s.add_development_dependency "parse_a_changelog"
s.add_development_dependency 'rake'
s.add_development_dependency 'rspec'
s.add_development_dependency 'rspec-collection_matchers'
Expand Down
74 changes: 63 additions & 11 deletions spec/version_spec.rb
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

0 comments on commit 2659eb5

Please sign in to comment.