Compare commits

..

No commits in common. "master" and "v2.3.4" have entirely different histories.

8 changed files with 34 additions and 205 deletions

View file

@ -1,11 +1,3 @@
## 2.4.0
## What's Changed
### Exciting New Features 🎉
* feat(action): respect working_directory for files globs by @stephenway in https://github.com/softprops/action-gh-release/pull/667
## 2.3.4
## What's Changed

View file

@ -39,18 +39,6 @@ describe('util', () => {
'loom',
]);
});
it('handles globs with brace groups containing commas', () => {
assert.deepStrictEqual(parseInputFiles('./**/*.{exe,deb,tar.gz}\nfoo,bar'), [
'./**/*.{exe,deb,tar.gz}',
'foo',
'bar',
]);
});
it('handles single-line brace pattern correctly', () => {
assert.deepStrictEqual(parseInputFiles('./**/*.{exe,deb,tar.gz}'), [
'./**/*.{exe,deb,tar.gz}',
]);
});
});
describe('releaseBody', () => {
it('uses input body', () => {
@ -122,52 +110,6 @@ describe('util', () => {
}),
);
});
it('falls back to body when body_path is missing', () => {
assert.equal(
releaseBody({
github_ref: '',
github_repository: '',
github_token: '',
input_body: 'fallback-body',
input_body_path: '__tests__/does-not-exist.txt',
input_draft: false,
input_prerelease: false,
input_files: [],
input_overwrite_files: undefined,
input_preserve_order: undefined,
input_name: undefined,
input_tag_name: undefined,
input_target_commitish: undefined,
input_discussion_category_name: undefined,
input_generate_release_notes: false,
input_make_latest: undefined,
}),
'fallback-body',
);
});
it('returns undefined when body_path is missing and body is not provided', () => {
assert.equal(
releaseBody({
github_ref: '',
github_repository: '',
github_token: '',
input_body: undefined,
input_body_path: '__tests__/does-not-exist.txt',
input_draft: false,
input_prerelease: false,
input_files: [],
input_overwrite_files: undefined,
input_preserve_order: undefined,
input_name: undefined,
input_tag_name: undefined,
input_target_commitish: undefined,
input_discussion_category_name: undefined,
input_generate_release_notes: false,
input_make_latest: undefined,
}),
undefined,
);
});
});
describe('parseConfig', () => {
it('parses basic config', () => {
@ -186,7 +128,6 @@ describe('util', () => {
github_ref: '',
github_repository: '',
github_token: '',
input_working_directory: undefined,
input_append_body: false,
input_body: undefined,
input_body_path: undefined,
@ -215,7 +156,6 @@ describe('util', () => {
github_ref: '',
github_repository: '',
github_token: '',
input_working_directory: undefined,
input_append_body: false,
input_body: undefined,
input_body_path: undefined,
@ -243,7 +183,6 @@ describe('util', () => {
github_ref: '',
github_repository: '',
github_token: '',
input_working_directory: undefined,
input_append_body: false,
input_body: undefined,
input_body_path: undefined,
@ -272,7 +211,6 @@ describe('util', () => {
github_ref: '',
github_repository: '',
github_token: '',
input_working_directory: undefined,
input_append_body: false,
input_body: undefined,
input_body_path: undefined,
@ -305,7 +243,6 @@ describe('util', () => {
github_ref: '',
github_repository: '',
github_token: 'env-token',
input_working_directory: undefined,
input_append_body: false,
input_body: undefined,
input_body_path: undefined,
@ -335,7 +272,6 @@ describe('util', () => {
github_ref: '',
github_repository: '',
github_token: 'input-token',
input_working_directory: undefined,
input_append_body: false,
input_body: undefined,
input_body_path: undefined,
@ -364,7 +300,6 @@ describe('util', () => {
github_ref: '',
github_repository: '',
github_token: '',
input_working_directory: undefined,
input_append_body: false,
input_body: undefined,
input_body_path: undefined,
@ -392,7 +327,6 @@ describe('util', () => {
github_ref: '',
github_repository: '',
github_token: '',
input_working_directory: undefined,
input_append_body: false,
input_body: undefined,
input_body_path: undefined,
@ -420,7 +354,6 @@ describe('util', () => {
github_ref: '',
github_repository: '',
github_token: '',
input_working_directory: undefined,
input_append_body: true,
input_body: undefined,
input_body_path: undefined,
@ -455,10 +388,6 @@ describe('util', () => {
'tests/data/foo/bar.txt',
]);
});
it('resolves files relative to working_directory', async () => {
assert.deepStrictEqual(paths(['data/**/*'], 'tests'), ['tests/data/foo/bar.txt']);
});
});
describe('unmatchedPatterns', () => {
@ -468,12 +397,6 @@ describe('util', () => {
['tests/data/does/not/exist/*'],
);
});
it('resolves unmatched relative to working_directory', async () => {
assert.deepStrictEqual(unmatchedPatterns(['data/does/not/exist/*'], 'tests'), [
'data/does/not/exist/*',
]);
});
});
describe('replaceSpacesWithDots', () => {
@ -490,36 +413,3 @@ describe('util', () => {
});
});
});
describe('parseInputFiles edge cases', () => {
it('handles multiple brace groups on same line', () => {
assert.deepStrictEqual(parseInputFiles('./**/*.{exe,deb},./dist/**/*.{zip,tar.gz}'), [
'./**/*.{exe,deb}',
'./dist/**/*.{zip,tar.gz}',
]);
});
it('handles nested braces', () => {
assert.deepStrictEqual(parseInputFiles('path/{a,{b,c}}/file.txt'), ['path/{a,{b,c}}/file.txt']);
});
it('handles empty comma-separated values', () => {
assert.deepStrictEqual(parseInputFiles('foo,,bar'), ['foo', 'bar']);
});
it('handles commas with spaces around braces', () => {
assert.deepStrictEqual(parseInputFiles(' ./**/*.{exe,deb} , file.txt '), [
'./**/*.{exe,deb}',
'file.txt',
]);
});
it('handles mixed newlines and commas with braces', () => {
assert.deepStrictEqual(parseInputFiles('file1.txt\n./**/*.{exe,deb},file2.txt\nfile3.txt'), [
'file1.txt',
'./**/*.{exe,deb}',
'file2.txt',
'file3.txt',
]);
});
});

View file

@ -27,9 +27,6 @@ inputs:
files:
description: "Newline-delimited list of path globs for asset files to upload"
required: false
working_directory:
description: "Base directory to resolve 'files' globs against (defaults to job working-directory)"
required: false
overwrite_files:
description: "Overwrite existing files with the same name. Defaults to true"
required: false

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

20
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "action-gh-release",
"version": "2.4.0",
"version": "2.3.4",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "action-gh-release",
"version": "2.4.0",
"version": "2.3.4",
"dependencies": {
"@actions/core": "^1.11.1",
"@actions/github": "^6.0.1",
@ -18,12 +18,12 @@
"devDependencies": {
"@types/glob": "^9.0.0",
"@types/mime-types": "^3.0.1",
"@types/node": "^20.19.19",
"@types/node": "^20.19.18",
"@vercel/ncc": "^0.38.4",
"@vitest/coverage-v8": "^3.2.4",
"prettier": "3.6.2",
"ts-node": "^10.9.2",
"typescript": "^5.9.3",
"typescript": "^5.9.2",
"typescript-formatter": "^7.2.2",
"vitest": "^3.1.4"
}
@ -1482,9 +1482,9 @@
"license": "MIT"
},
"node_modules/@types/node": {
"version": "20.19.19",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.19.tgz",
"integrity": "sha512-pb1Uqj5WJP7wrcbLU7Ru4QtA0+3kAXrkutGiD26wUKzSMgNNaPARTUDQmElUXp64kh3cWdou3Q0C7qwwxqSFmg==",
"version": "20.19.18",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.18.tgz",
"integrity": "sha512-KeYVbfnbsBCyKG8e3gmUqAfyZNcoj/qpEbHRkQkfZdKOBrU7QQ+BsTdfqLSWX9/m1ytYreMhpKvp+EZi3UFYAg==",
"dev": true,
"license": "MIT",
"dependencies": {
@ -2817,9 +2817,9 @@
}
},
"node_modules/typescript": {
"version": "5.9.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
"version": "5.9.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.2.tgz",
"integrity": "sha512-CWBzXQrc/qOkhidw1OzBTQuYRbfyxDXJMVJ1XNwUHGROVmuaeiEm3OslpZ1RV96d7SKKjZKrSJu3+t/xlw3R9A==",
"dev": true,
"license": "Apache-2.0",
"bin": {

View file

@ -1,6 +1,6 @@
{
"name": "action-gh-release",
"version": "2.4.0",
"version": "2.3.4",
"private": true,
"description": "GitHub Action for creating GitHub Releases",
"main": "lib/main.js",
@ -32,12 +32,12 @@
"devDependencies": {
"@types/glob": "^9.0.0",
"@types/mime-types": "^3.0.1",
"@types/node": "^20.19.19",
"@types/node": "^20.19.18",
"@vercel/ncc": "^0.38.4",
"@vitest/coverage-v8": "^3.2.4",
"prettier": "3.6.2",
"ts-node": "^10.9.2",
"typescript": "^5.9.3",
"typescript": "^5.9.2",
"typescript-formatter": "^7.2.2",
"vitest": "^3.1.4"
}

View file

@ -12,7 +12,7 @@ async function run() {
throw new Error(`⚠️ GitHub Releases requires a tag`);
}
if (config.input_files) {
const patterns = unmatchedPatterns(config.input_files, config.input_working_directory);
const patterns = unmatchedPatterns(config.input_files);
patterns.forEach((pattern) => {
if (config.input_fail_on_unmatched_files) {
throw new Error(`⚠️ Pattern '${pattern}' does not match any files.`);
@ -50,7 +50,7 @@ async function run() {
//);
const rel = await release(config, new GitHubReleaser(gh));
if (config.input_files && config.input_files.length > 0) {
const files = paths(config.input_files, config.input_working_directory);
const files = paths(config.input_files);
if (files.length == 0) {
if (config.input_fail_on_unmatched_files) {
throw new Error(`⚠️ ${config.input_files} does not include a valid file.`);

View file

@ -1,6 +1,5 @@
import * as glob from 'glob';
import { statSync, readFileSync } from 'fs';
import * as pathLib from 'path';
export interface Config {
github_token: string;
@ -13,7 +12,6 @@ export interface Config {
input_body?: string;
input_body_path?: string;
input_files?: string[];
input_working_directory?: string;
input_overwrite_files?: boolean;
input_draft?: boolean;
input_preserve_order?: boolean;
@ -35,53 +33,23 @@ export const uploadUrl = (url: string): string => {
};
export const releaseBody = (config: Config): string | undefined => {
if (config.input_body_path) {
try {
const contents = readFileSync(config.input_body_path, 'utf8');
return contents;
} catch (err: any) {
console.warn(
`⚠️ Failed to read body_path "${config.input_body_path}" (${err?.code ?? 'ERR'}). Falling back to 'body' input.`,
);
}
}
return config.input_body;
return (
(config.input_body_path && readFileSync(config.input_body_path).toString('utf8')) ||
config.input_body
);
};
type Env = { [key: string]: string | undefined };
const smartSplit = (input: string): string[] => {
const result: string[] = [];
let current = '';
let braceDepth = 0;
for (const ch of input) {
if (ch === '{') {
braceDepth++;
}
if (ch === '}') {
braceDepth--;
}
if (ch === ',' && braceDepth === 0) {
if (current.trim()) {
result.push(current.trim());
}
current = '';
} else {
current += ch;
}
}
if (current.trim()) {
result.push(current.trim());
}
return result;
};
export const parseInputFiles = (files: string): string[] => {
return files
.split(/\r?\n/)
.flatMap((line) => smartSplit(line))
.filter((pat) => pat.trim() !== '');
return files.split(/\r?\n/).reduce<string[]>(
(acc, line) =>
acc
.concat(line.split(','))
.filter((pat) => pat)
.map((pat) => pat.trim()),
[],
);
};
export const parseConfig = (env: Env): Config => {
@ -94,7 +62,6 @@ export const parseConfig = (env: Env): Config => {
input_body: env.INPUT_BODY,
input_body_path: env.INPUT_BODY_PATH,
input_files: parseInputFiles(env.INPUT_FILES || ''),
input_working_directory: env.INPUT_WORKING_DIRECTORY || undefined,
input_overwrite_files: env.INPUT_OVERWRITE_FILES
? env.INPUT_OVERWRITE_FILES == 'true'
: undefined,
@ -117,34 +84,17 @@ const parseMakeLatest = (value: string | undefined): 'true' | 'false' | 'legacy'
return undefined;
};
export const paths = (patterns: string[], cwd?: string): string[] => {
export const paths = (patterns: string[]): string[] => {
return patterns.reduce((acc: string[], pattern: string): string[] => {
const matches = glob.sync(pattern, { cwd, dot: true, absolute: false });
const resolved = matches
.map((p) => (cwd ? pathLib.join(cwd, p) : p))
.filter((p) => {
try {
return statSync(p).isFile();
} catch {
return false;
}
});
return acc.concat(resolved);
return acc.concat(glob.sync(pattern).filter((path) => statSync(path).isFile()));
}, []);
};
export const unmatchedPatterns = (patterns: string[], cwd?: string): string[] => {
export const unmatchedPatterns = (patterns: string[]): string[] => {
return patterns.reduce((acc: string[], pattern: string): string[] => {
const matches = glob.sync(pattern, { cwd, dot: true, absolute: false });
const files = matches.filter((p) => {
try {
const full = cwd ? pathLib.join(cwd, p) : p;
return statSync(full).isFile();
} catch {
return false;
}
});
return acc.concat(files.length == 0 ? [pattern] : []);
return acc.concat(
glob.sync(pattern).filter((path) => statSync(path).isFile()).length == 0 ? [pattern] : [],
);
}, []);
};