mirror of
https://github.com/softprops/action-gh-release.git
synced 2026-03-15 09:20:54 -04:00
fix: support Windows-style file globs (#754)
Signed-off-by: Rui Chen <rui@chenrui.dev>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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` |
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
alignAssetName,
|
||||
isTag,
|
||||
normalizeGlobPattern,
|
||||
parseConfig,
|
||||
parseInputFiles,
|
||||
paths,
|
||||
@@ -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');
|
||||
|
||||
@@ -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)"
|
||||
|
||||
36
dist/index.js
vendored
36
dist/index.js
vendored
File diff suppressed because one or more lines are too long
14
src/util.ts
14
src/util.ts
@@ -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) => {
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user