Skip to content

Commit

Permalink
Use RubyGems trusted publisher protocol when publishing (#28)
Browse files Browse the repository at this point in the history
* use rubygems trusted publisher protocol when publishing

* move permissions down to the job level
  • Loading branch information
DustinFisher authored Sep 12, 2024
1 parent 727dab8 commit 31e66a4
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions .github/workflows/publish_gem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,49 @@ name: Publish Gem
on:
workflow_dispatch:

permissions:
contents: write

jobs:
build_and_publish:
name: Build, tag & publish
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write

steps:
- uses: actions/checkout@v3
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2.1
bundler-cache: true

- name: Get version
id: version
run: |
VERSION=$(ruby -e "require './lib/tip_tap/version'; puts TipTap::VERSION")
echo "::set-output name=version::$VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Create and push tag
- name: Create tag
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git tag v${{ steps.version.outputs.version }}
git push origin v${{ steps.version.outputs.version }}
- name: Push tag
run: git push origin v${{ steps.version.outputs.version }}

- name: Install dependencies
run: bundle install

- name: Run tests
run: |
bundle install
bundle exec rspec
run: bundle exec rspec

- name: Build and publish to RubyGems
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
gem build *.gemspec
gem push *.gem
env:
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_API_KEY}}"
- name: Publish to RubyGems
uses: rubygems/release-gem@v1

- name: Create GitHub Release
uses: actions/create-release@v1
Expand Down

0 comments on commit 31e66a4

Please sign in to comment.