Sha256: 0e39cd4ddd5c2432daae909231edcdf1254d18a0cb15fd9b7cdc9bbdef231399

Contents?: true

Size: 1.97 KB

Versions: 3

Compression:

Stored size: 1.97 KB

Contents

name: Publish

on:
  push:
    branches:
      - main
  workflow_dispatch:

concurrency: rubygems

jobs:
  pre:
    name: Pre-flight checks
    runs-on: ubuntu-latest
    outputs:
      go: ${{ steps.gem_version.outputs.new_version }}

    steps:
      - uses: actions/checkout@v3

      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: '3'

      - name: Check if new version to release
        id: gem_version
        run: |
          gem_version=$(ruby -r rubygems -e "puts Gem::Specification::load('govuk_tech_docs.gemspec').version")
          echo "gem_version=$gem_version" >> "$GITHUB_OUTPUT"

          if git fetch origin "refs/tags/v$gem_version" >/dev/null 2>&1
          then
            echo "Tag 'v$gem_version' already exists"
            echo "new_version=false" >> "$GITHUB_OUTPUT"
          else
            echo "new_version=true" >> "$GITHUB_OUTPUT"
          fi

  deploy:
    name: Publish Ruby Gem
    environment: rubygems
    permissions:
      contents: write  # needed to be able to tag the release
    runs-on: ubuntu-latest
    needs: pre
    if: ${{ needs.pre.outputs.go == 'true' }}

    steps:
      - uses: actions/checkout@v3

      - uses: actions/setup-node@v3
        with:
          node-version-file: '.nvmrc'
          cache: 'npm'

      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: '3'
          bundler-cache: true

      - name: Publish
        env:
          RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
        run: |
          mkdir -p ~/.gem

          cat << EOF > ~/.gem/credentials
          ---
          :rubygems_api_key: ${RUBYGEMS_API_KEY}
          EOF

          chmod 0600 ~/.gem/credentials

          # tag will be associated with github-actions bot user, see
          # https://github.community/t/github-actions-bot-email-address/17204
          git config user.name "github-actions[bot]"
          git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

          bundle exec rake release

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
govuk_tech_docs-3.5.0 .github/workflows/publish.yaml
govuk_tech_docs-3.4.5 .github/workflows/publish.yaml
govuk_tech_docs-3.4.0 .github/workflows/publish.yaml