Skip to content

gh release create successfully returns before release is available to subsequent calls #6599

Description

@jo-tools

Describe the bug

The command to create a release returns too early - before the release is available to subsequent calls.
This possibly leads to errors when trying to upload files right after creating a release.

Steps to reproduce the behavior

When trying to do the following in a Shell Script or in a GitHub Workflow:

gh release create <tag> --generate-notes --draft
gh release upload <tag> file1
gh release upload <tag> file2
gh release edit <tag> --draft=false

Then the second line gh release upload ... (often - not always) fails with the error: release not found

Expected vs actual behavior

gh release upload ... should wait until the release is available to other calls.
If this command returns OK, then it's expected that the release exists for the next call.

Workaround

gh release create <tag> --generate-notes --draft

echo "It might take a while to be available, so let's try to view it before uploading assets'"

RELEASE_READY=0
for i in {1..10}
do
	echo "View Release - attempt $i"
	gh release view <tag>
	if [ $? -eq 0 ]; then
		RELEASE_READY=1
		break
	fi
	sleep 1
done
if [ $RELEASE_READY -ne 1 ]; then
  exit 1
fi

gh release upload <tag> file1
gh release upload <tag> file2
gh release edit <tag> --draft=false

Activity

  1. mislav commented on Nov 14, 2022

    @mislav
    Contributor

    Hi, thank you for reporting. We talked about this previously here: duplicate of #6198 (comment)

    Summary:

    1. Draft releases referenced by tag name are looked up by listing releases from API;
    2. API list of releases suffers replication lag;
    3. As a result, trying to reference a draft release immediately after its creation might be too soon.

    Workaround: just upload assets to a new non-draft release and allow it to be published. Internally, GitHub CLI will create a draft release first, upload assets to it, and publish it after all the assets are fully uploaded and available.

    gh release create <tag> --generate-notes <file1> <file2>
    
  2. added
    more-info-neededMore info needed from user/contributor
    and removed on Nov 14, 2022
  3. jo-tools commented on Nov 14, 2022

    @jo-tools
    Author

    Workaround: just upload assets to a new non-draft release and allow it to be published.

    That doesn't work in a workflow of mines. There are a bunch of uploads, which are included if necessary and required:

          - name: Upload Asset XYZ
            if: ${{ needs.some.condition }}
            working-directory: ${{ env.ASSETS_FOLDER }}
            run: |
              gh release upload <tag> <Asset_XYZ>
    

    So I prefer and want a Draft Release that is only being published once all conditional Assets are uploaded.

    We talked about this previously here: duplicate of #6198 (comment)

    Ah - I haven't found that. Sorry about the duplicate.

    I still consider the current behavior a bug, or at least an unexpected behavior of the system.
    One would assume that creating a (draft) release returning a success, that that draft release is immediately available.

    Sure, one can workaround with either sleep x, or such as mentioned above do some polling until the just-created (draft) release available for further processing. But honestly I'd prefer gh release create to do that internally.

    A shell script, an action or a workflow should not be aware of GitHub internals (such as what you have mentioned: " I suspect some kind of database or ElasticSearch replication lag."). If that's know to GitHub, it should handle that accordingly on their end.

    I am obviously not the first one running into this. And I won't be the last one. Which basically means that you're going to get issues about this again and again.

    At the very least... it would have helped to find this "potential/known issue" in the documentation. If GitHub really wants to have this current behavior "by design", then the documentation should mention this in the docs for gh release create (along with suggestions how to deal with it).

  4. josefaidt commented on Nov 14, 2022

    @josefaidt

    This may be the wrong place to jump in but I'm experiencing similar issues with gh release create ... --draft and subsequently attempting to access the release with gh release view ... where I'm receiving release not found. I have no troubles running the same release view command locally, and this appears to only occur in GitHub Actions. BUT what's interesting is that this was working fine and as I've continued working on the action it suddenly stopped working.

    I noticed a similar issue (#3037) which talks about a similar behavior, and I did notice GitHub actions is able to list the draft releases on subsequent runs

    I was able to add sleep 5 between create and view to workaround this issue in the meantime

  5. mislav commented on Nov 16, 2022

    @mislav
    Contributor

    Sure, one can workaround with either sleep x, or such as mentioned above do some polling until the just-created (draft) release available for further processing. But honestly I'd prefer gh release create to do that internally.

    Good point. We can consider blocking gh release create operation until the newly created draft release is "visible".

    So I prefer and want a Draft Release that is only being published once all conditional Assets are uploaded.

    Your conditional logic could put all the assets to upload in a single directory. Then, when all that is processed and done, a single gh release create <tag> dist/* operation could upload all the files at once. I believe that a release automation approach that relies on fewer total gh commands will be simpler and more resilient to maintain.

    But that's beside the point. Of course that the main problem still remains, and that is that draft releases are not immediately visible by CLI upon creation.

  6. added
    priority-3Affects a small number of users or is largely cosmetic
    and removed
    more-info-neededMore info needed from user/contributor
    on Nov 16, 2022
  7. mislav commented on Nov 16, 2022

    @mislav
    Contributor

    I just experimented with the API and found out that the GraphQL Repository.release connection allows us to directly fetch a draft release by its pending tag name (unlike the REST API where this is not allowed). By switching to GraphQL for this, we could avoid having to rely on release listing that has replication lag and gain the ability to immediately reference the new draft release in a subsequent CLI operation.

    {
      repository(owner: "cli", name: "cli") {
        release(tagName: "v2.20.2") {
          name
          databaseId
          isDraft
        }
      }
    }

    We might have to completely reimplement FetchRelease and FetchLatestRelease for this, but I think it could be worth it

    func FetchRelease(httpClient *http.Client, baseRepo ghrepo.Interface, tagName string) (*Release, error) {

  8. jo-tools commented on Nov 16, 2022

    @jo-tools
    Author

    Your conditional logic could put all the assets to upload in a single directory. Then, when all that is processed and done, a single gh release create <tag> dist/* operation could upload all the files at once.

    Good hint - thanks. But that's not the point of this issue.

    We can consider blocking gh release create operation until the newly created draft release is "visible".

    Or document that it is designed to behave "async". And similar to Apple's notarytool add a parameter --wait, which would block and only return once available for all subsequent calls.

  9. mislav commented on Dec 19, 2022

    @mislav
    Contributor

    Fixed in 7caf7da

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority-3Affects a small number of users or is largely cosmetic

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions