Repository navigation
Automate RubyGems releases from version tags #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,42 @@ | ||
| name: Release | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - "[0-9]+.[0-9]+.[0-9]+" | ||
|
|
||
| permissions: | ||
| contents: write | ||
| id-token: write | ||
|
|
||
| jobs: | ||
| release: | ||
| name: Release | ||
| runs-on: ubuntu-latest | ||
| environment: release | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
|
|
||
| - name: Set up Ruby | ||
| uses: ruby/setup-ruby@7f797815d8adceb1c412e7abefdd1ab4abc47a5f # v1.335.0 | ||
| with: | ||
| bundler-cache: true | ||
|
|
||
| - name: Check tag matches version.rb | ||
| run: | | ||
| version="$(ruby -Ilib -remailable/version -e 'print Emailable::VERSION')" | ||
| if [ "$GITHUB_REF_NAME" != "$version" ]; then | ||
| echo "::error::Tag $GITHUB_REF_NAME does not match version.rb version $version. Run 'bundle exec rake release:prepare[x.y.z]'." | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Run tests | ||
| run: bundle exec rake test | ||
|
|
||
| - name: Publish to RubyGems | ||
| uses: rubygems/release-gem@7f9650160c1a4e7989fdc9855807bdbd421d8b6b # v1.4.1 | ||
|
|
||
| - name: Create GitHub release | ||
| run: gh release create "$GITHUB_REF_NAME" --verify-tag --generate-notes | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} |
This file contains hidden or 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 hidden or 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,10 +1,45 @@ | ||
| require 'bundler/gem_tasks' | ||
| require 'rake/testtask' | ||
|
|
||
| # Tags are bare versions like 4.2.3, not Bundler's default v4.2.3. | ||
| Bundler::GemHelper.instance.define_singleton_method(:version_tag) do | ||
| version.to_s | ||
| end | ||
|
|
||
| Rake::TestTask.new(:test) do |t| | ||
| t.libs << 'test' | ||
| t.libs << 'lib' | ||
| t.test_files = FileList['test/**/*_test.rb'] | ||
| end | ||
|
|
||
| task :default => :test | ||
|
|
||
| namespace :release do | ||
| desc 'Check, bump, commit, and tag a release, e.g. rake release:prepare[1.2.3]' | ||
| task :prepare, [:version] do |_, args| | ||
| version = args[:version].to_s | ||
| abort 'error: version must be x.y.z' unless version.match?(/\A\d+\.\d+\.\d+\z/) | ||
| abort 'error: working tree not clean' unless `git status --porcelain`.empty? | ||
| abort 'error: release from master' unless `git branch --show-current`.strip == 'master' | ||
|
|
||
| sh 'git fetch -q --tags origin master' | ||
| unless `git rev-parse HEAD` == `git rev-parse origin/master` | ||
| abort 'error: master is not in sync with origin' | ||
| end | ||
|
|
||
| current = Bundler::GemHelper.instance.gemspec.version | ||
| unless Gem::Version.new(version) > current | ||
| abort "error: version must be greater than #{current}" | ||
| end | ||
| abort "error: tag #{version} already exists" unless `git tag -l #{version}`.empty? | ||
|
|
||
| Rake::Task[:test].invoke | ||
| sh 'bundle exec rubocop' | ||
|
|
||
| path = 'lib/emailable/version.rb' | ||
| File.write(path, File.read(path).sub(/VERSION = '.*'/, "VERSION = '#{version}'")) | ||
| sh "git commit -q -am 'Release #{version}'" | ||
| sh "git tag -a #{version} -m #{version}" | ||
| puts "Tagged #{version}. Push the commit and tag to release: git push --follow-tags" | ||
| end | ||
| end | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.