Skip to content

Conversation

@ksylvan
Copy link
Collaborator

@ksylvan ksylvan commented Jun 28, 2025

Fix GitHub Release Creation Error Handling in CI/CD Pipeline

Summary

This PR improves the error handling in the GitHub Actions release workflow by properly checking if a release already exists before attempting to create it. The previous implementation could fail when the release view command returned a non-zero exit code.

This ensures that during the GitHub release before matrix builds start, we get only one build trying to create a release.

Related Issues

Closes #1554

Files Changed

  • .github/workflows/release.yml: Modified the release creation logic to properly handle the case where a release tag already exists.

Code Changes

.github/workflows/release.yml

The release creation step has been refactored from a single line command to a proper conditional check:

Before:

gh release view ${{ env.latest_tag }} || gh release create ${{ env.latest_tag }} --title "Release ${{ env.latest_tag }}" --notes "Automated release for ${{ env.latest_tag }}"

After:

if ! gh release view ${{ env.latest_tag }} >/dev/null 2>&1; then
  gh release create ${{ env.latest_tag }} --title "Release ${{ env.latest_tag }}" --notes "Automated release for ${{ env.latest_tag }}"
else
  echo "Release ${{ env.latest_tag }} already exists."
fi

Reason for Changes

The previous implementation using the || operator could cause issues in the CI/CD pipeline when gh release view returned an error. This could happen when:

  • The release doesn't exist (expected behavior)
  • Network issues occur
  • API rate limits are hit

By explicitly checking the exit code and redirecting output to /dev/null, we ensure that:

  1. The workflow doesn't fail on expected "release not found" errors
  2. We get clearer feedback when a release already exists
  3. The pipeline is more robust against transient failures

Impact of Changes

  • Improved Reliability: The release workflow will be more stable and less prone to failures due to race conditions or timing issues
  • Better Logging: Clear feedback when a release already exists helps with debugging CI/CD issues
  • No Functional Changes: The end result remains the sam. Releases are created only when they don't exist

Test Plan

This change can be tested by:

  1. Running the workflow on a tag that doesn't have a release (should create a new release)
  2. Re-running the workflow on the same tag (should skip creation and log that the release exists)
  3. Verifying that the workflow completes successfully in both cases

Additional Notes

This is a defensive programming improvement that makes the CI/CD pipeline more resilient. The change follows shell scripting best practices by:

  • Properly handling command exit codes
  • Redirecting both stdout and stderr when we only care about the exit status
  • Providing informative feedback for different scenarios

### CHANGES

*   Check if a release exists before attempting creation.
*   Suppress error output from `gh release view` command.
*   Add an informative log when release already exists.
@ksylvan ksylvan requested a review from Copilot June 28, 2025 04:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the GitHub Actions release workflow to improve error handling by explicitly checking if a release exists before attempting to create it, thereby preventing race conditions in the CI/CD pipeline.

  • Refactors the release creation command to a conditional check.
  • Redirects output to suppress expected errors when a release isn’t found.
  • Logs a clear message when a release already exists.
Comments suppressed due to low confidence (1)

.github/workflows/release.yml:114

  • Consider adding a comment above this conditional to explain the use of '/dev/null' redirection, clarifying that it's intended to suppress expected 'release not found' errors and handle transient failures gracefully.
          if ! gh release view ${{ env.latest_tag }} >/dev/null 2>&1; then

@ksylvan ksylvan merged commit d8d1574 into danielmiessler:main Jun 28, 2025
1 check passed
@ksylvan ksylvan deleted the 0627-github-actions-release-fix branch June 28, 2025 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Build process race condition creates incomplete release

1 participant