Skip to content

Auto-trigger CD when CI passes and the gem version is bumped #637

Auto-trigger CD when CI passes and the gem version is bumped

Auto-trigger CD when CI passes and the gem version is bumped #637

Workflow file for this run

name: CI
on:
push:
branches:
- main
pull_request:
permissions:
contents: write
jobs:
ci-data:
runs-on: ubuntu-latest
outputs:
result: ${{ steps.fetch.outputs.result }}
steps:
- id: fetch
uses: oxidize-rb/actions/fetch-ci-data@v1
with:
stable-ruby-versions: |
# Explicitly include all Ruby versions we want to support
# to ensure binaries are built for each version
only: ['3.2', '3.3', '3.4', '4.0']
rspec:
runs-on: ${{ matrix.os }}
needs: ci-data
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-latest"]
ruby: ${{ fromJSON(needs.ci-data.outputs.result).stable-ruby-versions }}
rust: ["stable"]
steps:
- uses: actions/checkout@v6
- uses: oxidize-rb/actions/setup-ruby-and-rust@v1
with:
ruby-version: ${{ matrix.ruby }}
rustup-toolchain: ${{ matrix.rust }}
bundler-cache: true
cargo-cache: false
- name: Run ruby tests
run: bundle exec rake
- name: Compile rust ext
run: bundle exec rake compile:release
rspec_ruby_version_file:
name: "RSpec (ruby-version-file)"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: oxidize-rb/actions/setup-ruby-and-rust@v1
with:
rustup-toolchain: stable
bundler-cache: true
cargo-cache: false
- name: Run ruby tests
run: bundle exec rake
- name: Compile rust ext
run: bundle exec rake compile:release
static_type_check:
name: "Type Check"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Run static type checks
run: bundle exec srb tc
notify_on_failure:
runs-on: ubuntu-latest
needs: [rspec, static_type_check]
if: ${{ failure() && github.ref == 'refs/heads/main' }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
steps:
- uses: slackapi/slack-github-action@v1.25.0
with:
payload: |
{
"text": "${{ github.repository }}/${{ github.ref }}: FAILED\n${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
check-release:
name: Check if release needed
runs-on: ubuntu-latest
needs: [rspec, rspec_ruby_version_file, static_type_check]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
outputs:
should_release: ${{ steps.check.outputs.should_release }}
version: ${{ steps.check.outputs.version }}
steps:
- uses: actions/checkout@v6
- id: check
run: |
VERSION=$(ruby -r ./lib/code_ownership/version.rb -e "puts CodeOwnership::VERSION")
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
"https://rubygems.org/api/v2/rubygems/code_ownership/versions/${VERSION}.json")
if [ "$STATUS" = "200" ]; then
echo "should_release=false" >> "$GITHUB_OUTPUT"
echo "::notice::code_ownership ${VERSION} already on RubyGems — skipping release."
else
echo "should_release=true" >> "$GITHUB_OUTPUT"
echo "::notice::code_ownership ${VERSION} not published — will release."
fi
release:
name: Release
needs: check-release
if: needs.check-release.outputs.should_release == 'true'
permissions:
contents: write
uses: ./.github/workflows/cd.yml
secrets: inherit
notify_on_release:
runs-on: ubuntu-latest
needs: [check-release, release]
if: ${{ github.ref == 'refs/heads/main' && needs.release.result == 'success' }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
steps:
- uses: slackapi/slack-github-action@v1.25.0
with:
payload: |
{
"text": "🎉 Released ${{ github.repository }} v${{ needs.check-release.outputs.version }}"
}