Visitar URL original
fix: support Windows-style file globs by chenrui333 · Pull Request #754 · softprops/action-gh-release · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ jobs:

> **⚠️ Note:** Notice the `|` in the yaml syntax above ☝️. That lets you effectively declare a multi-line yaml string. You can learn more about multi-line yaml syntax [here](https://yaml-multiline.info)

> **⚠️ Note for Windows:** Paths must use `/` as a separator, not `\`, as `\` is used to escape characters with special meaning in the pattern; for example, instead of specifying `D:\Foo.txt`, you must specify `D:/Foo.txt`. If you're using PowerShell, you can do this with `$Path = $Path -replace '\\','/'`
> **⚠️ Note for Windows:** Both `\` and `/` path separators are accepted in `files` globs. If you need to match a literal glob metacharacter such as `[` or `]`, keep escaping the metacharacter itself in the pattern.

### 📝 External release notes

Expand Down Expand Up @@ -186,7 +186,7 @@ The following are optional as `step.with` keys
| `draft` | Boolean | Indicator of whether or not this release is a draft |
| `prerelease` | Boolean | Indicator of whether or not is a prerelease |
| `preserve_order` | Boolean | Upload assets sequentially in the provided order. This controls the action's upload behavior, but it does not control the final asset ordering that GitHub may display on the release page or return from the Releases API. |
| `files` | String | Newline-delimited globs of paths to assets to upload for release. Escape glob metacharacters when you need to match a literal filename that contains them, such as `[` or `]`. |
| `files` | String | Newline-delimited globs of paths to assets to upload for release. Escape glob metacharacters when you need to match a literal filename that contains them, such as `[` or `]`. On Windows, both `\` and `/` separators are accepted. |
| `overwrite_files` | Boolean | Indicator of whether files should be overwritten when they already exist. Defaults to true |
| `name` | String | Name of the release. defaults to tag name |
| `tag_name` | String | Name of a tag. defaults to `github.ref_name` |
Expand Down
21 changes: 21 additions & 0 deletions __tests__/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
alignAssetName,
isTag,
normalizeGlobPattern,
parseConfig,
parseInputFiles,
paths,
Expand Down Expand Up @@ -505,6 +506,26 @@ describe('util', () => {
});
});

describe('normalizeGlobPattern', () => {
it('preserves posix-style patterns on non-windows platforms', () => {
assert.equal(normalizeGlobPattern('./dist/**/*.tgz', 'linux'), './dist/**/*.tgz');
});

it('normalizes relative windows-style glob patterns', () => {
assert.equal(
normalizeGlobPattern('.\\release-assets\\rssguard-*win7.exe', 'win32'),
'./release-assets/rssguard-*win7.exe',
);
});

it('normalizes absolute windows-style glob patterns', () => {
assert.equal(
normalizeGlobPattern('D:\\a\\repo\\build\\packages\\*', 'win32'),
'D:/a/repo/build/packages/*',
);
});
});

describe('replaceSpacesWithDots', () => {
it('replaces all spaces with dots', () => {
expect(alignAssetName('John Doe.bla')).toBe('John.Doe.bla');
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ inputs:
description: "Upload artifacts sequentially in the provided order. This does not control the final display order GitHub uses for release assets."
required: false
files:
description: "Newline-delimited list of path globs for asset files to upload. Escape glob metacharacters when matching literal filenames that contain them."
description: "Newline-delimited list of path globs for asset files to upload. Escape glob metacharacters when matching literal filenames that contain them. On Windows, both \\ and / path separators are accepted."
required: false
working_directory:
description: "Base directory to resolve 'files' globs against (defaults to job working-directory)"
Expand Down
36 changes: 18 additions & 18 deletions dist/index.js

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,19 @@ const parseMakeLatest = (value: string | undefined): 'true' | 'false' | 'legacy'
return undefined;
};

export const normalizeGlobPattern = (
pattern: string,
platform: NodeJS.Platform = process.platform,
): string => {
if (platform === 'win32') {
return pattern.replace(/\\/g, '/');
}
return pattern;
};

export const paths = (patterns: string[], cwd?: string): string[] => {
return patterns.reduce((acc: string[], pattern: string): string[] => {
const matches = glob.sync(pattern, { cwd, dot: true, absolute: false });
const matches = glob.sync(normalizeGlobPattern(pattern), { cwd, dot: true, absolute: false });
const resolved = matches
.map((p) => (cwd ? pathLib.join(cwd, p) : p))
.filter((p) => {
Expand All @@ -143,7 +153,7 @@ export const paths = (patterns: string[], cwd?: string): string[] => {

export const unmatchedPatterns = (patterns: string[], cwd?: string): string[] => {
return patterns.reduce((acc: string[], pattern: string): string[] => {
const matches = glob.sync(pattern, { cwd, dot: true, absolute: false });
const matches = glob.sync(normalizeGlobPattern(pattern), { cwd, dot: true, absolute: false });
const files = matches.filter((p) => {
try {
const full = cwd ? pathLib.join(cwd, p) : p;
Expand Down