From 457c8355cae8141023ac776d5f2fdb7ddd0d40c6 Mon Sep 17 00:00:00 2001 From: Vincent Pochet Date: Thu, 26 Sep 2024 16:48:09 +0200 Subject: [PATCH] Add a github action to publish gem to Rubygem --- .github/workflows/gem-push.yml | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/gem-push.yml diff --git a/.github/workflows/gem-push.yml b/.github/workflows/gem-push.yml new file mode 100644 index 0000000..87f832c --- /dev/null +++ b/.github/workflows/gem-push.yml @@ -0,0 +1,46 @@ +name: Push to RubyGems + +on: workflow_dispatch + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + ruby-version: ["3.3", "3.2", "3.1", "3.0"] + + steps: + - uses: actions/checkout@v3 + - name: Set up Ruby ${{ matrix.ruby-version }} + uses: ruby/setup-ruby@359bebbc29cbe6c87da6bc9ea3bc930432750108 + with: + ruby-version: ${{ matrix.ruby-version }} + - name: Install dependencies + run: bundle install + - name: Run tests + run: bundle exec rspec + + publish: + needs: build + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v3 + - name: Set up Ruby + uses: ruby/setup-ruby@359bebbc29cbe6c87da6bc9ea3bc930432750108 + with: + ruby-version: "3.1" + + - name: 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}}"