Skip to content

Check if release exists before creating a new one#49

Merged
RaoulSchaffranek merged 3 commits intomasterfrom
raoul/check-release-exists
Jul 16, 2025
Merged

Check if release exists before creating a new one#49
RaoulSchaffranek merged 3 commits intomasterfrom
raoul/check-release-exists

Conversation

@RaoulSchaffranek
Copy link
Member

@RaoulSchaffranek RaoulSchaffranek commented Jul 8, 2025

This PR checks if a GitHub release already exists before creating a new release.
This is needed to avoid the following deadlock:

  1. We trigger the "release" workflow
  2. The workflow passes the "Create a Release" step
  3. The workflow fails in a later step (e.g., due the flakiness of the VSX registry or the VSCode marketplace)
  4. We rerun the workflow
  5. The workflow now fails in the "Create a Release" because it already exists

This happened just now: https://github.com/runtimeverification/simbolik-vscode/actions/runs/16137751602

Copy link
Member

Choose a reason for hiding this comment

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

If you want to create a release before doing all the other work, I'd suggest you to use draft releases like we do with K.

The structure is as follows:

draft-release:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Create Draft Release
        id: create_release
        uses: softprops/action-gh-release@v1
        with:
          draft: true
          tag_name: v${{ github.run_number }} # Example tag name
          name: Draft Release ${{ github.run_number }}
          body: |
            This is a draft release.
            Details will be added once testing is complete.
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  build-and-test:
    needs: draft-release  # Ensure this job runs after the draft release is created
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      # Add your build and test steps here

      - name: Upload assets to draft release
        uses: actions/upload-release-asset@v1
        with:
          upload_url: ${{ needs.draft-release.outputs.upload_url }}
          asset_path: ./path/to/your/asset.zip
          asset_name: asset.zip
          asset_content_type: application/zip

  publish-or-delete-release:
    needs: build-and-test
    if: success() # Run only if the 'build-and-test' job was successful
    runs-on: ubuntu-latest
    steps:
      - name: Publish Release
        id: publish_release
        uses: ncipollo/release-action@v1
        with:
          # Use the tag from the draft release step
          tag: v${{ github.run_number }}
          # The release is already created, so we just need to update it
          token: ${{ secrets.GITHUB_TOKEN }}

  delete-draft-on-failure:
    needs: build-and-test
    if: failure() # Run only if the 'build-and-test' job failed
    runs-on: ubuntu-latest
    steps:
      - name: Delete Draft Release
        uses: author/action-rollback@v1 # Example action to delete release
        with:
          tag: v${{ github.run_number }} # Specify the tag of the draft release to delete
          token: ${{ secrets.GITHUB_TOKEN }}

Copy link
Member

Choose a reason for hiding this comment

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

The primary difference I see is this cleans up the draft release on failure, and if a new release occurs before yours is manually fixed the release becomes unrelated to actual release artifacts. If the draft is not cleaned it's also not official in the GH pipeline and isn't tagged.

The bare minimum I'd suggest to delete the release on failure.

Copy link
Member Author

Choose a reason for hiding this comment

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

In the case of simbolik-vscode we run the build step before the release step. If the build step fails, no release is uploaded; hence, cleaning up is unnecessary. Or am I missing something?

@F-WRunTime F-WRunTime self-requested a review July 8, 2025 14:56
@RaoulSchaffranek RaoulSchaffranek merged commit d7fe10a into master Jul 16, 2025
1 check passed
@RaoulSchaffranek RaoulSchaffranek deleted the raoul/check-release-exists branch July 16, 2025 08:23
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.

2 participants