|
1 | | -name: Publish and Release Gem |
| 1 | +name: release |
| 2 | + |
2 | 3 | on: |
3 | | - push: |
4 | | - branches: [ $default-branch ] |
5 | | - paths: [ "VERSION" ] |
6 | 4 | workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + paths: |
| 9 | + - lib/version.rb |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + packages: write |
7 | 14 |
|
8 | 15 | jobs: |
9 | 16 | release: |
10 | 17 | runs-on: ubuntu-latest |
11 | 18 |
|
12 | 19 | steps: |
13 | | - - name: Checkout |
14 | | - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab |
| 20 | + - name: checkout |
| 21 | + uses: actions/checkout@v3 |
15 | 22 |
|
16 | | - - name: Setup Ruby |
17 | | - uses: ruby/setup-ruby@8a45918450651f5e4784b6031db26f4b9f76b251 |
| 23 | + - uses: ruby/setup-ruby@250fcd6a742febb1123a77a841497ccaa8b9e939 # [email protected] |
18 | 24 | with: |
19 | 25 | bundler-cache: true |
20 | 26 |
|
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 |
22 | 34 | run: script/test |
23 | 35 |
|
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 |
25 | 44 | 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 |
28 | 56 | 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