Skip to content

Commit c16620e

Browse files
committed
Add completion marker to prevent duplicate discussion posts
- Add mark-release-complete job to release.yml that creates and uploads release-complete.json marker to GitHub Release after all release jobs finish - Add check-release-complete job to release-post-comment.yml that downloads and verifies the completion marker before posting to discussions - Update post-discussion job to depend on check-release-complete instead of check-release-exists to ensure only the 4th run (after full completion) posts This fixes the issue where all 4 workflow_run instances created duplicate discussion posts because timestamp-based checks were insufficient. The completion marker ensures only the final run (after release artifacts are complete) posts to discussions.
1 parent 39e59e6 commit c16620e

File tree

2 files changed

+122
-3
lines changed

2 files changed

+122
-3
lines changed

.github/workflows/release-post-comment.yml

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,76 @@ jobs:
139139
140140
echo '─────────────────────────────────────────────────'
141141
142+
check-release-complete:
143+
name: Check if release is complete (Early Exit Pattern)
144+
needs: [identifiers, check-release-exists]
145+
# Only check completion for nightly and stable releases
146+
if: |
147+
needs.check-release-exists.outputs.should_process == 'true' &&
148+
(needs.identifiers.outputs.release_type == 'nightly' || needs.identifiers.outputs.release_type == 'stable')
149+
runs-on: ubuntu-latest
150+
outputs:
151+
should_process: ${{ steps.check.outputs.should_process }}
152+
is_complete: ${{ steps.check.outputs.is_complete }}
153+
154+
steps:
155+
- name: Check for completion marker in GitHub Release
156+
id: check
157+
env:
158+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
159+
run: |
160+
echo '─────────────────────────────────────────────────'
161+
echo '🔍 Checking if release is complete (Early Exit Pattern)'
162+
echo '─────────────────────────────────────────────────'
163+
164+
RELEASE_NAME="${{ needs.check-release-exists.outputs.release_name }}"
165+
RELEASE_TYPE="${{ needs.identifiers.outputs.release_type }}"
166+
167+
echo "Release name: $RELEASE_NAME"
168+
echo "Release type: $RELEASE_TYPE"
169+
echo ""
170+
171+
# Try to download the completion marker from the GitHub Release
172+
echo "Attempting to download release-complete.json marker..."
173+
174+
if gh release download "$RELEASE_NAME" \
175+
--repo "$GITHUB_REPOSITORY" \
176+
--pattern "release-complete.json" \
177+
--dir . 2>/dev/null; then
178+
179+
echo "✅ Completion marker found!"
180+
echo ""
181+
echo "Completion marker contents:"
182+
cat release-complete.json
183+
echo ""
184+
185+
# Verify the marker is for the correct release
186+
MARKER_RELEASE=$(jq -r '.release_name' release-complete.json)
187+
if [ "$MARKER_RELEASE" = "$RELEASE_NAME" ]; then
188+
echo "✅ Completion marker matches release name - proceeding"
189+
{
190+
echo "should_process=true"
191+
echo "is_complete=true"
192+
} >> $GITHUB_OUTPUT
193+
else
194+
echo "⚠️ Completion marker mismatch (marker: $MARKER_RELEASE, expected: $RELEASE_NAME)"
195+
{
196+
echo "should_process=false"
197+
echo "is_complete=false"
198+
} >> $GITHUB_OUTPUT
199+
fi
200+
else
201+
echo "⏳ Completion marker not found yet"
202+
echo " This is normal! Will post once release.yml completes the release."
203+
echo " (This is an early exit - release.yml is still building artifacts)"
204+
{
205+
echo "should_process=false"
206+
echo "is_complete=false"
207+
} >> $GITHUB_OUTPUT
208+
fi
209+
210+
echo '─────────────────────────────────────────────────'
211+
142212
# Development release: Post PR summary comment for development builds
143213
post-pr-comment:
144214
name: Post PR Comment (Development Builds)
@@ -278,13 +348,13 @@ jobs:
278348
# Nightly and Stable releases: Post to GitHub Discussions
279349
post-discussion:
280350
name: Post to GitHub Discussions (Nightly & Stable)
281-
needs: [identifiers, check-release-exists]
351+
needs: [identifiers, check-release-exists, check-release-complete]
282352
runs-on: ubuntu-latest
283353

284354
# Only run for nightly or stable builds (explicit positive list)
285-
# With timestamp verification in check-release-exists, only the 4th run should proceed
355+
# With completion marker verification in check-release-complete, only the 4th run should proceed
286356
if: |
287-
needs.check-release-exists.outputs.should_process == 'true' &&
357+
needs.check-release-complete.outputs.should_process == 'true' &&
288358
(needs.identifiers.outputs.release_type == 'nightly' || needs.identifiers.outputs.release_type == 'stable')
289359
290360
env:

.github/workflows/release.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,52 @@ jobs:
381381
else
382382
echo "⚠️ RTD_TOKEN not configured, skipping RTD build trigger"
383383
fi
384+
385+
# Mark release as complete (for release-post-comment to detect)
386+
mark-release-complete:
387+
name: Mark Release Complete
388+
needs: [identifiers, release-nightly, release-stable]
389+
if: always() && needs.identifiers.result == 'success' && (needs.release-nightly.result == 'success' || needs.release-stable.result == 'success')
390+
runs-on: ubuntu-latest
391+
392+
env:
393+
RELEASE_TYPE: ${{ needs.identifiers.outputs.release_type }}
394+
RELEASE_NAME: ${{ needs.identifiers.outputs.release_name }}
395+
396+
steps:
397+
- name: Create completion marker
398+
run: |
399+
echo "==> Creating release completion marker..."
400+
echo "Release: $RELEASE_NAME"
401+
echo "Type: $RELEASE_TYPE"
402+
403+
# Create completion marker JSON with metadata
404+
cat > release-complete.json <<EOF
405+
{
406+
"release_name": "$RELEASE_NAME",
407+
"release_type": "$RELEASE_TYPE",
408+
"completed_at": "$(date -u +'%Y-%m-%dT%H:%M:%SZ')",
409+
"workflow_run_id": "${{ github.run_id }}",
410+
"commit_sha": "${{ needs.identifiers.outputs.head_sha }}",
411+
"nightly_status": "${{ needs.release-nightly.result }}",
412+
"stable_status": "${{ needs.release-stable.result }}"
413+
}
414+
EOF
415+
416+
echo ""
417+
echo "Completion marker contents:"
418+
cat release-complete.json
419+
420+
- name: Upload completion marker to GitHub Release
421+
env:
422+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
423+
run: |
424+
echo "==> Uploading completion marker to release $RELEASE_NAME..."
425+
426+
# Upload the completion marker as a release asset
427+
gh release upload "$RELEASE_NAME" \
428+
release-complete.json \
429+
--repo "$GITHUB_REPOSITORY" \
430+
--clobber
431+
432+
echo "✅ Completion marker uploaded successfully"

0 commit comments

Comments
 (0)