Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[gh release create/upload] Expand glob patterns for all platforms - #10413

#10413
Merged
jtmcg merged 10 commits into
cli:trunkcli/cli:trunkfrom
iamazeem:5099-gh-release-create-upload-expand-glob-patterns-on-windowsiamazeem/cli:5099-gh-release-create-upload-expand-glob-patterns-on-windowsCopy head branch name to clipboard
Mar 12, 2025
Merged

[gh release create/upload] Expand glob patterns for all platforms#10413
jtmcg merged 10 commits into
cli:trunkcli/cli:trunkfrom
iamazeem:5099-gh-release-create-upload-expand-glob-patterns-on-windowsiamazeem/cli:5099-gh-release-create-upload-expand-glob-patterns-on-windowsCopy head branch name to clipboard

Conversation

@iamazeem

@iamazeem iamazeem commented Feb 9, 2025

Copy link
Copy Markdown
Contributor

Fixes #5099.

Verified that this issue is only applicable to Windows Command Prompt and Powershell.
See this relevant SO thread for more details.

GitBash behaves same as a Linux shell.

This issue affects gh release create and gh release upload commands.
In this PR, the glob patterns are expanded internally for Windows.

Tests (same for Windows Command Prompt and Powershell)

# Create test files e.g. test.{1,2,3} and log.{1,2,3}
> echo "test.1" > test.1
> echo "test.2" > test.2
> echo "test.3" > test.3
> echo "log.1" > log.1
> echo "log.2" > log.2
> echo "log.3" > log.3

# Create release with test.{1,2,3} files with glob pattern test.*
> .\gh.exe release create --repo iamazeem/test --draft --notes "Test" v1.2.3 test.*
https://github.com/iamazeem/test/releases/tag/untagged-d72acf4185040741cacb

# Verify release
> .\gh.exe release view --repo iamazeem/test v1.2.3
v1.2.3
Draft • iamazeem created this less than a minute ago

  Test


Assets
test.1  18 B
test.2  18 B
test.3  18 B

View on GitHub: https://github.com/iamazeem/test/releases/tag/untagged-d72acf4185040741cacb


# Upload log.{1,2,3} files to release with glob pattern log.*
> .\gh.exe release upload --repo iamazeem/test v1.2.3 log.*
Successfully uploaded 3 assets to v1.2.3

# Verify release again
> .\gh.exe release view --repo iamazeem/test v1.2.3
v1.2.3
Draft • iamazeem created this about 2 minutes ago

  Test


Assets
log.1   16 B
log.2   16 B
log.3   16 B
test.1  18 B
test.2  18 B
test.3  18 B

View on GitHub: https://github.com/iamazeem/test/releases/tag/untagged-d72acf4185040741cacb

Invalid patterns

# Create release with a glob pattern which doesn't expand e.g. test123.*
> .\gh.exe release create --repo iamazeem/test --draft --notes "Test" v1.2.3 test123.*
CreateFile test123.*: The filename, directory name, or volume label syntax is incorrect.

Notes

  • In Powershell, quoting (single or double) glob patterns work the same and the quotes are not passed to gh.
  • In Command Prompt, double quotes work same as Powershell but single quotes become part of the pattern itself.
    • For example, 'test.*' is passed as-is and cannot be expanded.

Error on Command Prompt

> .\gh.exe release create --repo iamazeem/test --draft --notes "Test" v1.2.3 'test.*'
CreateFile 'test.*': The filename, directory name, or volume label syntax is incorrect.

UPDATE

After discussions, the support for glob patterns has been added for all the platforms.

@iamazeem
iamazeem requested a review from a team as a code owner February 9, 2025 17:55
@iamazeem
iamazeem requested a review from andyfeller February 9, 2025 17:55
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Feb 9, 2025

@jtmcg jtmcg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Coming in with another blast from the past! We appreciate all the work you're putting in, @iamazeem 🙌

I reviewed the old issue and I think there was just a bit more to do from there than is delivered in this PR. I've added Acceptance Criteria to it so we can more easily track what needs doing. Let me know if you have any questions.

tl;dr: We want to expand wildcards for ALL platforms using gh and we want this to happen in gist create and release create in addition to what you've done here for release upload. I suspect its not too much more effort for those, given the solution you've outlined here 🙂

Also, if you haven't already come to expect it from me by now, I'm going to ask for some tests 😅

Comment thread pkg/cmd/release/shared/upload.go Outdated
@jtmcg
jtmcg requested review from jtmcg and removed request for andyfeller February 10, 2025 16:48
@iamazeem

Copy link
Copy Markdown
Contributor Author

@jtmcg:

We want to expand wildcards for ALL platforms using gh

As mentioned in the PR description, it's only needed for Windows.
The shells on Linux and Mac perform their own expansion.
That's why I targeted only Windows after verification.

we want this to happen in gist create

Sure, I'll add its support for gist create.

Also, if you haven't already come to expect it from me by now, I'm going to ask for some tests 😅

Actually, I thought about how to approach these tests and then decided not to.
Apparently, it's a shell-specific thing and didn't feel like that it should be covered.
If you could share some examples that'd be very helpful. Thanks!

@iamazeem

Copy link
Copy Markdown
Contributor Author

gh gist create

Working fine both on Linux and Windows.

Tests (Windows)

> .\gh.exe gist create -d "test" test.*
- Creating gist with multiple files
✓ Created secret gist test.1
https://gist.github.com/iamazeem/4d5a636d1c66f58be21440efd37247f0

>.\gh.exe gist list -L1
ID                                DESCRIPTION  FILES    VISIBILITY  UPDATED
4d5a636d1c66f58be21440efd37247f0  test         3 files  secret      less than a minute ago

> .\gh.exe gist view 4d5a636d1c66f58be21440efd37247f0
test

test.1

test.1

test.2

test.1

test.3

test.1

> .\gh.exe gist delete --yes 4d5a636d1c66f58be21440efd37247f0
✓ Gist "test.1" deleted

@iamazeem

iamazeem commented Feb 11, 2025

Copy link
Copy Markdown
Contributor Author

@jtmcg: Please review. Thanks!

Comment thread pkg/cmdutil/args.go Outdated
Comment thread pkg/cmdutil/args.go Outdated
@jtmcg

jtmcg commented Feb 13, 2025

Copy link
Copy Markdown
Contributor

As mentioned in the PR description, it's only needed for Windows.
The shells on Linux and Mac perform their own expansion.
That's why I targeted only Windows after verification.

Totally. There may be a good reason to also handle other os's explicitly in the CLI, though... Not sure what they are at the moment, but I'll think on this and get back to you on it 👍 If you can think of any reasons for or against it, I'm all ears, too

Actually, I thought about how to approach these tests and then decided not to.
Apparently, it's a shell-specific thing and didn't feel like that it should be covered.
If you could share some examples that'd be very helpful. Thanks!

Sure thing! I'll take a look and add a PR into your feature branch for it if I can find a solution

@jtmcg

jtmcg commented Feb 13, 2025

Copy link
Copy Markdown
Contributor

@iamazeem, here's the PR with the testing example. Note, I moved the os check out of the helper function and into the commands. I'm not sure if that's exactly right, but it seemed weird to have a function named GlobWindowsPaths that was also making decisions about mac and ubuntu 🤷

@iamazeem

Copy link
Copy Markdown
Contributor Author

@jtmcg

There may be a good reason to also handle other os's explicitly in the CLI, though... Not sure what they are at the moment, but I'll think on this and get back to you on it 👍 If you can think of any reasons for or against it, I'm all ears, too

On nix shells, the expansions happen when args are in double quotes e.g. "test.*".
In single quotes, the glob patterns are not expanded e.g. 'test.*'.
If gh were to start expanding everything internally then the behavior of single quotes would be altered.
That was my only concern while implementing this i.e. not to break the default behavior of nix shell expansions and the UX should remain consistent on all platforms where gh works.

@jtmcg jtmcg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great, so here's where we're at:

  1. We want to handle all globbing ourselves, regardless of shell
  2. We want to error if a glob pattern doesn't find any matches. This error should contain ALL patterns that don't have matches and not just the first that didn't match. Perhaps this suggests a new bespoke error type?

Does this make sense?

Comment thread pkg/cmdutil/args.go Outdated
@iamazeem iamazeem changed the title [gh release create/upload] Expand glob patterns on Windows (Command Prompt and Powershell) [gh release create/upload] Expand glob patterns for all platforms Feb 22, 2025
@iamazeem
iamazeem requested a review from jtmcg February 22, 2025 07:28

@jtmcg jtmcg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking good. I like how clean this reads, now! Have a couple of questions, though

Comment thread pkg/cmd/gist/create/create.go Outdated
Comment thread pkg/cmdutil/args.go Outdated
@iamazeem
iamazeem requested a review from jtmcg February 25, 2025 13:00

@jtmcg jtmcg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The requested changes are described in this comment

@iamazeem
iamazeem requested a review from jtmcg February 26, 2025 07:50
iamazeem and others added 2 commits February 27, 2025 19:20
…mers (#3)

* Separate partitioning from globbing in cmdutil/args package and consumers

In the previous commit, GlobPaths was overloaded, containing logic
specific to command use-cases. This commit removes that functionality from
GlobPaths and back into the commands that have the special use-cases.

To do this, I've introduced a new Partition util in cmdutil/args.go that
will separate a slice into two slices given a predicate. This functionality
is leveraged by both the special use-cases described above to separate the
command-specific syntax from the globable filepaths.

* Add test to validate that the order of '-' in gh gist create args doesn't matter
@jtmcg
jtmcg merged commit 4a8ecee into cli:trunk Mar 12, 2025
@iamazeem
iamazeem deleted the 5099-gh-release-create-upload-expand-glob-patterns-on-windows branch March 12, 2025 16:23
@darylgwpo

This comment was marked as spam.

tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Mar 26, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [cli/cli](https://github.com/cli/cli) | minor | `v2.68.1` -> `v2.69.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>cli/cli (cli/cli)</summary>

### [`v2.69.0`](https://github.com/cli/cli/releases/tag/v2.69.0): GitHub CLI 2.69.0

[Compare Source](cli/cli@v2.68.1...v2.69.0)

#### What's Changed

##### Features

-   Commands that accept filepath arguments will do glob expansion for `*` characters, by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10413

##### Bug Fixes

-   `gh issue/pr comment --edit-last` no longer creates a comment in non-interactive mode if there weren't one. A new flag `--create-if-none` provides this behaviour, by [@&#8203;andyfeller](https://github.com/andyfeller) in cli/cli#10625
-   `gh repo sync` provides a more informative error for missing workflow permissions when the token is provided by a GitHub app, by [@&#8203;wata727](https://github.com/wata727) in cli/cli#10574
-   `gh api` no longer tries to encode URLs incorrectly, by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10630

##### Other

-   Add cli-discuss-automation environment to triage.md by [@&#8203;jtmcg](https://github.com/jtmcg) in cli/cli#10552
-   chore: remove redundant word in comment by [@&#8203;kevincatty](https://github.com/kevincatty) in cli/cli#10586
-   Bump golang.org/x/net from 0.34.0 to 0.36.0 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#10593

#### New Contributors

-   [@&#8203;kevincatty](https://github.com/kevincatty) made their first contribution in cli/cli#10586
-   [@&#8203;wata727](https://github.com/wata727) made their first contribution in cli/cli#10574

**Full Changelog**: cli/cli@v2.68.1...v2.69.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4yMTMuNSIsInVwZGF0ZWRJblZlciI6IjM5LjIxMy41IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
@qoqnoos1

This comment was marked as spam.

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

Labels

external pull request originating outside of the CLI core team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh release create wildcard '*' not working on windows

9 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.