Skip to content

Commit f859019

Browse files
committed
update release workflow
1 parent dc5910c commit f859019

File tree

1 file changed

+45
-13
lines changed

1 file changed

+45
-13
lines changed

.github/workflows/gem.yml

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,61 @@
1-
name: Publish and Release Gem
1+
name: release
2+
23
on:
3-
push:
4-
branches: [ $default-branch ]
5-
paths: [ "VERSION" ]
64
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
paths:
9+
- lib/version.rb
10+
11+
permissions:
12+
contents: write
13+
packages: write
714

815
jobs:
916
release:
1017
runs-on: ubuntu-latest
1118

1219
steps:
13-
- name: Checkout
14-
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab
20+
- name: checkout
21+
uses: actions/checkout@v3
1522

16-
- name: Setup Ruby
17-
uses: ruby/setup-ruby@8a45918450651f5e4784b6031db26f4b9f76b251
23+
- uses: ruby/setup-ruby@250fcd6a742febb1123a77a841497ccaa8b9e939 # [email protected]
1824
with:
1925
bundler-cache: true
2026

21-
- name: Run Tests
27+
- name: bootstrap
28+
run: script/bootstrap
29+
30+
- name: lint
31+
run: bundle exec rubocop -c .rubocop.yml lib/ spec/
32+
33+
- name: test
2234
run: script/test
2335

24-
- name: Build Gem
36+
- name: set GEM_NAME from gemspec
37+
run: echo "GEM_NAME=$(ls | grep gemspec | cut -d. -f1)" >> $GITHUB_ENV
38+
39+
# builds the gem and saves the version to GITHUB_ENV
40+
- name: build
41+
run: echo "GEM_VERSION=$(gem build ${{ env.GEM_NAME }}.gemspec 2>&1 | grep Version | cut -d':' -f 2 | tr -d " \t\n\r")" >> $GITHUB_ENV
42+
43+
- name: publish to GitHub packages
2544
run: |
26-
echo "GEM_VERSION=$(gem build entitlements-gitrepo-auditor-plugin.gemspec 2>&1 | grep Version | cut -d':' -f 2 | tr -d " \t\n\r")" >> $GITHUB_ENV
27-
- name: Publish to GitHub Packages
45+
export OWNER=$( echo ${{ github.repository }} | cut -d "/" -f 1 )
46+
GEM_HOST_API_KEY=${{ secrets.GITHUB_TOKEN }} gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} ${{ env.GEM_NAME }}-${{ env.GEM_VERSION }}.gem
47+
48+
- name: release
49+
uses: ncipollo/release-action@a2e71bdd4e7dab70ca26a852f29600c98b33153e # [email protected]
50+
with:
51+
artifacts: "${{ env.GEM_NAME }}-${{ env.GEM_VERSION }}.gem"
52+
tag: "v${{ env.GEM_VERSION }}"
53+
generateReleaseNotes: true
54+
55+
- name: Publish to RubyGems
2856
run: |
29-
GEM_HOST_API_KEY=${{ secrets.GITHUB_TOKEN }} gem push --KEY github --host https://rubygems.pkg.github.com/github entitlements-gitrepo-auditor-plugin-${{ env.GEM_VERSION }}.gem
57+
mkdir -p ~/.gem
58+
echo -e "---\n:rubygems_api_key: ${{ secrets.RUBYGEMS_API_KEY }}" > ~/.gem/credentials
59+
chmod 0600 ~/.gem/credentials
60+
gem push ${{ env.GEM_NAME }}-${{ env.GEM_VERSION }}.gem
61+
rm ~/.gem/credentials

0 commit comments

Comments
 (0)