Skip to content

Initial Postio Ruby SDK (v0.1.0) #1

Initial Postio Ruby SDK (v0.1.0)

Initial Postio Ruby SDK (v0.1.0) #1

Workflow file for this run

name: Release
on:
push:
tags: ["v*"]
workflow_dispatch:
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
already-published: ${{ steps.check.outputs.already-published }}
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler-cache: true
- name: Read version
id: version
run: |
VERSION=$(ruby -r ./lib/postio/version -e "puts Postio::VERSION")
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Check tag matches version
if: startsWith(github.ref, 'refs/tags/v')
run: |
TAG="${GITHUB_REF#refs/tags/v}"
VERSION="${{ steps.version.outputs.version }}"
if [ "$TAG" != "$VERSION" ]; then
echo "::error::Tag v$TAG does not match gem version $VERSION"
exit 1
fi
- name: Check if already on RubyGems (idempotent)
id: check
run: |
VERSION="${{ steps.version.outputs.version }}"
STATUS=$(curl -s -o /dev/null -w "%{http_code}" "https://rubygems.org/api/v1/versions/postio.json")
if [ "$STATUS" = "200" ] && curl -s "https://rubygems.org/api/v1/versions/postio.json" | grep -q "\"number\":\"$VERSION\""; then
echo "postio==$VERSION already on RubyGems — skipping publish"
echo "already-published=true" >> "$GITHUB_OUTPUT"
else
echo "already-published=false" >> "$GITHUB_OUTPUT"
fi
- name: RSpec (offline)
if: steps.check.outputs.already-published == 'false'
run: bundle exec rspec
- name: Build gem
if: steps.check.outputs.already-published == 'false'
run: gem build postio.gemspec
- name: Upload gem artifact
if: steps.check.outputs.already-published == 'false'
uses: actions/upload-artifact@v4
with:
name: gem
path: "*.gem"
publish:
needs: build
if: needs.build.outputs.already-published == 'false'
runs-on: ubuntu-latest
environment:
name: rubygems
url: https://rubygems.org/gems/postio
permissions:
id-token: write # RubyGems Trusted Publishers (OIDC)
steps:
- uses: actions/download-artifact@v4
with:
name: gem
path: .
- name: Configure Trusted Publishing
uses: rubygems/release-gem@v1
with:
await-release: true