Skip to content

gh release create wildcard '*' not working on windows #5099

Description

@jamesjohnmcguire

Describe the bug

gh --version
gh version 2.4.0 (2021-12-21)

As the title states, I can't seem to find a way to submit multiple files with a wildcard. Straight from the docs, this sample command fails:
gh release create v1.2.3 ./dist/*.tgz

with the following message:
CreateFile ./dist/*.tgz: The filename, directory name, or volume label syntax is incorrect.

If I run the command, with an individual file, it works such as:
gh release create v1.2.3 dist\Tool-Linux.tgz

It works.

If I open up a Linux terminal, such as git bash, and try the command in there, it works.

Steps to reproduce the behavior

  1. Type this
    dir /b dist

  2. View the output
    Tool-Linux.tgz
    Tool-MacOS.tgz
    Tool-Windows.tgz

  3. Type this
    gh release create v1.2.3 ./dist/*.tgz

  4. View the output

  5. See error
    CreateFile ./dist/*.tgz: The filename, directory name, or volume label syntax is incorrect.

I also tried:
gh release create v1.2.3 .\dist*.tgz
gh release create v1.2.3 dist*.tgz

cd dist
gh release create v1.2.3 *.tgz

with no succcess

Expected vs actual behavior

A successfully submited release tag

Activity

  1. added
    priority-3Affects a small number of users or is largely cosmetic
    and removed on Jan 25, 2022
  2. mislav commented on Jan 25, 2022

    @mislav
    Contributor

    Thank you for reporting!

    Unlike other platforms, Windows does not auto-expand wildcards in its shells when passing arguments to commands. For example, even though PowerShell has support for wildcard expansion like ls ./dist/*.tgz, it does not automatically perform such expansion. You can work around it by using the following expression in powershell:

    > gh release create v1.2.3 (get-item .\dist\*.tgz)

    To make it easier for gh users (and to make the example code that you pointed out work on Windows), I propose that we additionally expand glob expressions in arguments to commands such as gist create, release create, and release upload. This should perhaps only be done on Windows, since users on other platforms might be surprised that globs are additionally expanded by the gh process in addition to their shell.

  3. added
    priority-2Affects more than a few users but doesn't prevent core functions
    and removed
    priority-3Affects a small number of users or is largely cosmetic
    on Jan 25, 2022
  4. jessehouwing commented on Feb 7, 2022

    @jessehouwing
    Contributor

    The problem with parsing (dir *.*) is that it only works in PowerShell and that the expanded command becomes too long, causing execution to fail.

    ResourceUnavailable: D:\a\azure-pipelines-tasks-zips\azure-pipelines-tasks-zips\build.ps1:27
    Line |
      27 |      & gh release create $tag -t "$tag" --target main -n """" ((dir _d …
         |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | Program 'gh.exe' failed to run: An error occurred trying to start process 'C:\Program Files
         | (x86)\GitHub CLI\gh.exe' with working directory
         | 'D:\a\azure-pipelines-tasks-zips\azure-pipelines-tasks-zips'. The filename or extension is too long.At
         | D:\a\azure-pipelines-tasks-zips\azure-pipelines-tasks-zips\build.ps1:27 char:5 +     & gh release
         | create $tag -t "$tag" --target main -n """" ((dir _d … +    
         | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
    

    Commands like git add *.zip work fine, because the tool expands the wildcard internally.

  5. mislav commented on Mar 18, 2022

    @mislav
    Contributor

    Let's just follow git's lead and expand wildcards on all platforms then, not just Windows. PRs welcome!

  6. thp-stopsmops commented on Feb 15, 2023

    @thp-stopsmops

    Another workaround to use when using cmd and not PowerShell is described here (found via this superuser answer) and could be used like this (note that this will invoke the tool once for each filename, so it's strictly speaking not equivalent to gh release create v1.2.3 dist/*.tgz on *NIX shells if there are multiple matching files):

    for /R %i in (dist\*.tgz) DO gh release create v1.2.3 %i
    

    Of course, eventually replacing this with wildcard/glob expansion in gh would clean things up a lot.

    A quick search reveals AssetsFromArgs might be the place where this can be added (at least for upload and create), but my golang skills are insufficient (read: non-existent) to actually go (ha!) and implement this:

    func AssetsFromArgs(args []string) (assets []*AssetForUpload, err error) {

  7. added a commit that references this issue on Apr 17, 2024
  8. jtmcg commented on Feb 10, 2025

    @jtmcg
    Contributor

    Acceptance Criteria

    Given a call to gist create, release create, or release upload command
    when a wildcard is used in the <files>... field
    then that wildcard is expanded on all platforms by gh

  9. self-assigned this
    on Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggh-releaserelating to the gh release commandhelp wantedContributions welcomepriority-2Affects more than a few users but doesn't prevent core functions

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions