Skip to content

Commit 4a7d6f8

Browse files
perryqhclaude
andcommitted
Auto-trigger CD when CI passes and the gem version is bumped
Previously the CD workflow only ran via workflow_dispatch. Wire it to fire automatically after CI succeeds on main, but only when the version in lib/code_ownership/version.rb isn't already on RubyGems. ci.yml: - Add a check-release gate job that reads CodeOwnership::VERSION and queries the RubyGems API; sets should_release=true only when the version is unpublished. Runs only on push to main. - Add a release job that calls cd.yml as a reusable workflow (secrets: inherit), gated on should_release and on the test jobs passing via needs. - Add a notify_on_release Slack notification on successful release, mirroring the existing notify_on_failure hook. - Add top-level contents: write so the reusable workflow's token can create the GitHub Release. cd.yml: - Add a dry_run input to workflow_call/workflow_dispatch that skips the irreversible gem push (logs "would push" instead), so the full build + job graph can be exercised on a branch without publishing. The GitHub Release step is already gated on new_version, so it skips automatically in dry-run. workflow_dispatch remains as a manual fallback. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent d861735 commit 4a7d6f8

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

.github/workflows/cd.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33

44
on:
55
workflow_call:
6+
inputs:
7+
dry_run:
8+
type: boolean
9+
default: false
610
workflow_dispatch:
11+
inputs:
12+
dry_run:
13+
type: boolean
14+
default: false
15+
description: "Build gems but don't publish or release"
716

817
concurrency:
918
group: ${{ github.workflow }}-${{ github.ref }}
@@ -129,6 +138,11 @@
129138
for i in *.gem; do
130139
if [ -f "$i" ]; then
131140
echo "⏳ Attempting to push $i..."
141+
if [ "${{ inputs.dry_run }}" = "true" ]; then
142+
echo "🧪 dry-run: would push $i (skipping)"
143+
SKIPPED_GEMS+=("$i")
144+
continue
145+
fi
132146
if ! gem push "$i" >push.out 2>&1; then
133147
gemerr=$?
134148
if grep -q "Repushing of gem" push.out; then

.github/workflows/ci.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
- main
77
pull_request:
88

9+
permissions:
10+
contents: write
11+
912
jobs:
1013
ci-data:
1114
runs-on: ubuntu-latest
@@ -80,3 +83,51 @@ jobs:
8083
{
8184
"text": "${{ github.repository }}/${{ github.ref }}: FAILED\n${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
8285
}
86+
87+
check-release:
88+
name: Check if release needed
89+
runs-on: ubuntu-latest
90+
needs: [rspec, rspec_ruby_version_file, static_type_check]
91+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
92+
outputs:
93+
should_release: ${{ steps.check.outputs.should_release }}
94+
version: ${{ steps.check.outputs.version }}
95+
steps:
96+
- uses: actions/checkout@v6
97+
- id: check
98+
run: |
99+
VERSION=$(ruby -r ./lib/code_ownership/version.rb -e "puts CodeOwnership::VERSION")
100+
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
101+
STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
102+
"https://rubygems.org/api/v2/rubygems/code_ownership/versions/${VERSION}.json")
103+
if [ "$STATUS" = "200" ]; then
104+
echo "should_release=false" >> "$GITHUB_OUTPUT"
105+
echo "::notice::code_ownership ${VERSION} already on RubyGems — skipping release."
106+
else
107+
echo "should_release=true" >> "$GITHUB_OUTPUT"
108+
echo "::notice::code_ownership ${VERSION} not published — will release."
109+
fi
110+
111+
release:
112+
name: Release
113+
needs: check-release
114+
if: needs.check-release.outputs.should_release == 'true'
115+
permissions:
116+
contents: write
117+
uses: ./.github/workflows/cd.yml
118+
secrets: inherit
119+
120+
notify_on_release:
121+
runs-on: ubuntu-latest
122+
needs: [check-release, release]
123+
if: ${{ github.ref == 'refs/heads/main' && needs.release.result == 'success' }}
124+
env:
125+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
126+
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
127+
steps:
128+
- uses: slackapi/slack-github-action@v1.25.0
129+
with:
130+
payload: |
131+
{
132+
"text": "🎉 Released ${{ github.repository }} v${{ needs.check-release.outputs.version }}"
133+
}

0 commit comments

Comments
 (0)