Skip to content

Commit 87fc076

Browse files
committed
Migrate from Travis CI to GitHub Actions for tests and releases
1 parent 328bb09 commit 87fc076

File tree

4 files changed

+161
-7
lines changed

4 files changed

+161
-7
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Build and release gem to RubyGems
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
with:
14+
fetch-depth: 0 # Fetch current tag as annotated. See https://github.com/actions/checkout/issues/290
15+
- uses: ruby/setup-ruby@v1
16+
with:
17+
ruby-version: 2.7
18+
- name: "Extract data from tag: version, message, body"
19+
id: tag
20+
run: |
21+
git fetch --tags --force # Really fetch annotated tag. See https://github.com/actions/checkout/issues/290#issuecomment-680260080
22+
echo ::set-output name=version::${GITHUB_REF#refs/tags/v}
23+
echo ::set-output name=subject::$(git for-each-ref $GITHUB_REF --format='%(contents:subject)')
24+
BODY="$(git for-each-ref $GITHUB_REF --format='%(contents:body)')"
25+
# Extract changelog entries between this and previous version headers
26+
escaped_version=$(echo ${GITHUB_REF#refs/tags/v} | sed -e 's/[]\/$*.^[]/\\&/g')
27+
changelog=$(awk "BEGIN{inrelease=0} /## ${escaped_version}/{inrelease=1;next} /## [0-9]+\.[0-9]+\.[0-9]+/{inrelease=0;exit} {if (inrelease) print}" CHANGELOG.md)
28+
# Multiline body for release. See https://github.community/t/set-output-truncates-multiline-strings/16852/5
29+
BODY="${BODY}"$'\n'"${changelog}"
30+
BODY="${BODY//'%'/'%25'}"
31+
BODY="${BODY//$'\n'/'%0A'}"
32+
BODY="${BODY//$'\r'/'%0D'}"
33+
echo "::set-output name=body::$BODY"
34+
# Add pre-release option if tag name has any suffix after vMAJOR.MINOR.PATCH
35+
if [[ ${GITHUB_REF#refs/tags/} =~ ^v[0-9]+\.[0-9]+\.[0-9]+.+ ]]; then
36+
echo ::set-output name=prerelease::true
37+
fi
38+
- name: Build gem
39+
run: gem build
40+
- name: Calculate checksums
41+
run: sha256sum yabeda-sidekiq-${{ steps.tag.outputs.version }}.gem > SHA256SUM
42+
- name: Check version
43+
run: ls -l yabeda-sidekiq-${{ steps.tag.outputs.version }}.gem
44+
- name: Create Release
45+
id: create_release
46+
uses: actions/create-release@v1
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
with:
50+
tag_name: ${{ github.ref }}
51+
release_name: ${{ steps.tag.outputs.subject }}
52+
body: ${{ steps.tag.outputs.body }}
53+
draft: false
54+
prerelease: ${{ steps.tag.outputs.prerelease }}
55+
- name: Upload built gem as release asset
56+
uses: actions/upload-release-asset@v1
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
with:
60+
upload_url: ${{ steps.create_release.outputs.upload_url }}
61+
asset_path: yabeda-sidekiq-${{ steps.tag.outputs.version }}.gem
62+
asset_name: yabeda-sidekiq-${{ steps.tag.outputs.version }}.gem
63+
asset_content_type: application/x-tar
64+
- name: Upload checksums as release asset
65+
uses: actions/upload-release-asset@v1
66+
env:
67+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
with:
69+
upload_url: ${{ steps.create_release.outputs.upload_url }}
70+
asset_path: SHA256SUM
71+
asset_name: SHA256SUM
72+
asset_content_type: text/plain
73+
- name: Publish to GitHub packages
74+
env:
75+
GEM_HOST_API_KEY: Bearer ${{ secrets.GITHUB_TOKEN }}
76+
run: |
77+
gem push yabeda-sidekiq-${{ steps.tag.outputs.version }}.gem --host https://rubygems.pkg.github.com/${{ github.repository_owner }}
78+
- name: Publish to RubyGems
79+
env:
80+
GEM_HOST_API_KEY: "${{ secrets.RUBYGEMS_API_KEY }}"
81+
run: |
82+
gem push yabeda-sidekiq-${{ steps.tag.outputs.version }}.gem

.github/workflows/test.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Run tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- '**'
8+
tags-ignore:
9+
- 'v*'
10+
11+
jobs:
12+
test:
13+
name: "Run tests"
14+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
15+
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
include:
20+
- ruby: 3.0
21+
- ruby: 2.7
22+
- ruby: 2.6
23+
- ruby: 2.5
24+
container:
25+
image: ruby:${{ matrix.ruby }}
26+
env:
27+
CI: true
28+
steps:
29+
- uses: actions/checkout@v2
30+
- uses: actions/cache@v2
31+
with:
32+
path: vendor/bundle
33+
key: bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }}
34+
restore-keys: |
35+
bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }}
36+
bundle-${{ matrix.ruby }}-
37+
- name: Upgrade Bundler to 2.0 (for older Rubies)
38+
run: gem install bundler -v '~> 2.0'
39+
- name: Bundle install
40+
run: |
41+
bundle config path vendor/bundle
42+
bundle install
43+
bundle update
44+
- name: Run Rubocop
45+
run: bundle exec rubocop
46+
- name: Run RSpec
47+
run: bundle exec rspec

.travis.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,38 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
9191
9292
Bug reports and pull requests are welcome on GitHub at https://github.com/yabeda-rb/yabeda-sidekiq.
9393
94+
### Releasing
95+
96+
1. Bump version number in `lib/yabeda/sidekiq/version.rb`
97+
98+
In case of pre-releases keep in mind [rubygems/rubygems#3086](https://github.com/rubygems/rubygems/issues/3086) and check version with command like `Gem::Version.new(Yabeda::Sidekiq::VERSION).to_s`
99+
100+
2. Fill `CHANGELOG.md` with missing changes, add header with version and date.
101+
102+
3. Make a commit:
103+
104+
```sh
105+
git add lib/yabeda/sidekiq/version.rb CHANGELOG.md
106+
version=$(ruby -r ./lib/yabeda/sidekiq/version.rb -e "puts Gem::Version.new(Yabeda::Sidekiq::VERSION)")
107+
git commit --message="${version}: " --edit
108+
```
109+
110+
4. Create annotated tag:
111+
112+
```sh
113+
git tag v${version} --annotate --message="${version}: " --edit --sign
114+
```
115+
116+
5. Fill version name into subject line and (optionally) some description (list of changes will be taken from changelog and appended automatically)
117+
118+
6. Push it:
119+
120+
```sh
121+
git push --follow-tags
122+
```
123+
124+
7. GitHub Actions will create a new release, build and push gem into RubyGems! You're done!
125+
94126
## License
95127

96128
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

0 commit comments

Comments
 (0)