Skip to content

gh release create: Add flag to prevent a release if tag does not exist #6566

Description

@victorlin

Originally from #5855 (comment).

Describe the feature or problem you’d like to solve

I want to create a release only if the tag exists (do not want auto tag creation with gh release create <tag>).

The docs currently say:

If a matching git tag does not yet exist, one will automatically get created from the latest state of the default branch. Use --target to override this.

However, using --target is not a solution because I simply don't want to create a release in this case, not release from another commit ID.

Proposed solution

Add a flag such as --no-auto-tag/--fail-on-missing-tag which overrides the default behavior of creating the tag if it doesn't exist.

Activity

  1. mislav commented on Nov 5, 2022

    @mislav
    Contributor

    Thanks for the suggestion. I'm not sure if this should be a separate issue, though. If we allow tag names for --target per #5855, then you should be able to achieve what you want with:

    gh release create v1.2.3 --target=v1.2.3
    

    Or did you have another idea for this feature in mind?

    The workaround for you right now is to use the API to check if the tag already exists:

    gh api --silent "repos/:owner/:repo/git/refs/tags/v1.2.3" && gh release create v1.2.3 --notes ""
  2. added
    more-info-neededMore info needed from user/contributor
    and removed on Nov 7, 2022
  3. victorlin commented on Nov 10, 2022

    @victorlin
    Author

    @mislav this feature request is slightly different. Instead of creating a release from an existing tag name using --target, don't use that flag and only create a release if the required parameter [<tag>] represents an existing tag. That ability shouldn't be blocked by platform limitations.

  4. mislav commented on Nov 14, 2022

    @mislav
    Contributor

    Instead of creating a release from an existing tag name using --target, don't use that flag and only create a release if the required parameter [<tag>] represents an existing tag.

    Well, if --target (a platform feature) was allowed to point to a tag, then you could achieve what you want with:

    gh release create v1.2.3 --target=v1.2.3
    #=> (errors out if "v1.2.3" tag does not exist)

    I've proposed this approach because it should solve both this use-case and the use-case proposed in the thread you've linked (explicitly referencing tag names using --target).

    That ability shouldn't be blocked by platform limitations.

    You're right that the CLI should be able to implement what you're asking without relying on new platform features being shipped. We could check for the existence of remote tags by querying the GitHub API for git tags.

  5. added
    discussFeature changes that require discussion primarily among the GitHub CLI team
    and removed
    more-info-neededMore info needed from user/contributor
    on Nov 14, 2022
  6. mislav commented on Nov 14, 2022

    @mislav
    Contributor

    We discussed this and agreed that a flag such as gh release create <tag> --verify-tag would be something we could implement in the gh client. We chose that name because --fail-on-missing-tag is a bit long, even if it's more accurate.

    The implementation would then be: if the flag is set, query <tag> among repository tags via the GitHub API before creating the release, and abort the command if the tag was not found.

    @victorlin Does that sound good?

  7. added and removed
    discussFeature changes that require discussion primarily among the GitHub CLI team
    on Nov 14, 2022
  8. victorlin commented on Nov 14, 2022

    @victorlin
    Author

    @mislav that sounds great, thanks for the attention on this!

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions