Skip to content

Commit 5c7a97e

Browse files
committed
ci(release): handle Bundler prerelease normalization (0.0.2-rc1 -> 0.0.2.pre.rc1) when selecting gem file
1 parent dd0e1a8 commit 5c7a97e

File tree

2 files changed

+97
-6
lines changed

2 files changed

+97
-6
lines changed

.github/workflows/release.yml

Lines changed: 95 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,76 @@ permissions:
1919
contents: read
2020

2121
jobs:
22+
wait_ci:
23+
name: Wait for CI success on tag
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
31+
- name: Determine tag and SHA
32+
id: ref
33+
shell: bash
34+
run: |
35+
TAG="${{ github.ref_type == 'tag' && github.ref_name || github.event.release.tag_name }}"
36+
if [[ -z "$TAG" ]]; then
37+
echo "No tag from event; using placeholder for dry-run if applicable" >&2
38+
TAG="v0.0.0-dryrun"
39+
fi
40+
if [[ "${{ github.ref_type }}" == "tag" ]]; then
41+
SHA="${{ github.sha }}"
42+
else
43+
SHA=$(git rev-list -n1 "$TAG" || true)
44+
fi
45+
echo "tag=$TAG" >> $GITHUB_OUTPUT
46+
echo "sha=$SHA" >> $GITHUB_OUTPUT
47+
48+
- name: Install jq
49+
run: sudo apt-get update && sudo apt-get install -y jq
50+
51+
- name: Wait for CI workflow
52+
env:
53+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
shell: bash
55+
run: |
56+
# Skip wait for manual dry-run
57+
if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ github.event.inputs.dry_run }}" == "true" ]]; then
58+
echo "Dry-run dispatch: skipping CI wait."
59+
exit 0
60+
fi
61+
SHA="${{ steps.ref.outputs.sha }}"
62+
if [[ -z "$SHA" ]]; then
63+
echo "No SHA resolved; skipping CI wait."
64+
exit 0
65+
fi
66+
echo "Waiting for CI to succeed for $SHA ..."
67+
ATTEMPTS=120
68+
SLEEP=10
69+
for i in $(seq 1 $ATTEMPTS); do
70+
RESP=$(curl -s -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \
71+
"https://api.github.com/repos/${{ github.repository }}/actions/runs?per_page=50&head_sha=$SHA")
72+
STATUS=$(echo "$RESP" | jq -r '.workflow_runs[] | select(.name=="CI") | .status' | head -n1)
73+
CONCLUSION=$(echo "$RESP" | jq -r '.workflow_runs[] | select(.name=="CI") | .conclusion' | head -n1)
74+
if [[ "$STATUS" == "completed" ]]; then
75+
if [[ "$CONCLUSION" == "success" ]]; then
76+
echo "CI succeeded."
77+
exit 0
78+
else
79+
echo "CI completed with conclusion: $CONCLUSION"
80+
exit 1
81+
fi
82+
fi
83+
echo "CI status: ${STATUS:-not found}; waiting... ($i/$ATTEMPTS)"
84+
sleep $SLEEP
85+
done
86+
echo "Timed out waiting for CI to complete."
87+
exit 1
88+
2289
sync:
2390
name: Release gem and sync provider
91+
needs: wait_ci
2492
runs-on: ubuntu-latest
2593
env:
2694
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'true' && 'true' || 'false' }}
@@ -100,18 +168,39 @@ jobs:
100168
---
101169
:rubygems_api_key: $RUBYGEMS_API_KEY
102170
EOF
103-
GEM_FILE="logstruct-${{ steps.ver.outputs.version_tag }}.gem"
104-
if [[ ! -f "$GEM_FILE" ]]; then
105-
echo "::error::Expected gem file $GEM_FILE not found."
106-
ls -la *.gem || true
107-
exit 1
171+
VERSION="${{ steps.ver.outputs.version_tag }}"
172+
GEM_FILE="logstruct-${VERSION}.gem"
173+
ALT_VERSION="${VERSION/-/.pre.}"
174+
ALT_GEM_FILE="logstruct-${ALT_VERSION}.gem"
175+
if [[ -f "$GEM_FILE" ]]; then
176+
echo "Using gem file: $GEM_FILE"
177+
elif [[ -f "$ALT_GEM_FILE" ]]; then
178+
echo "Using gem file: $ALT_GEM_FILE (Bundler prerelease normalization)"
179+
GEM_FILE="$ALT_GEM_FILE"
180+
else
181+
# Fallback: pick the most recent built gem that matches the version prefix
182+
CANDIDATE=$(ls -1t logstruct-*.gem 2>/dev/null | head -n1 || true)
183+
if [[ -n "$CANDIDATE" ]]; then
184+
echo "Falling back to: $CANDIDATE"
185+
GEM_FILE="$CANDIDATE"
186+
else
187+
echo "::error::Expected gem file for version $VERSION not found."
188+
ls -la *.gem || true
189+
exit 1
190+
fi
108191
fi
109192
gem push "$GEM_FILE"
110193
111194
- name: Gem publish (dry-run)
112195
if: env.DRY_RUN == 'true'
113196
run: |
114-
echo "[DRY-RUN] Would push gem logstruct-${{ steps.ver.outputs.version_tag }}.gem to RubyGems"
197+
VERSION="${{ steps.ver.outputs.version_tag }}"
198+
ALT_VERSION="${VERSION/-/.pre.}"
199+
CANDIDATE="logstruct-${VERSION}.gem"
200+
if [[ ! -f "$CANDIDATE" && -f "logstruct-${ALT_VERSION}.gem" ]]; then
201+
CANDIDATE="logstruct-${ALT_VERSION}.gem"
202+
fi
203+
echo "[DRY-RUN] Would push gem $CANDIDATE to RubyGems"
115204
116205
- name: Clone terraform-provider-logstruct repository
117206
env:

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: CI
33
on:
44
push:
55
branches: [main]
6+
tags:
7+
- 'v*'
68
pull_request:
79
branches: [main]
810
workflow_dispatch:

0 commit comments

Comments
 (0)