Compare commits

...

3 Commits

Author SHA1 Message Date
Rui Chen
aec2ec56f9 release 2.4.0
Signed-off-by: Rui Chen <rui@chenrui.dev>
2025-10-06 22:53:32 -04:00
Stephen Way
4db716b167 feat: respect working_directory for files globs; add input and tests (#667) 2025-10-06 22:51:45 -04:00
dependabot[bot]
14820f2cee chore(deps): bump the npm group with 2 updates (#668)
Bumps the npm group with 2 updates: [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) and [typescript](https://github.com/microsoft/TypeScript).


Updates `@types/node` from 20.19.18 to 20.19.19
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Updates `typescript` from 5.9.2 to 5.9.3
- [Release notes](https://github.com/microsoft/TypeScript/releases)
- [Changelog](https://github.com/microsoft/TypeScript/blob/main/azure-pipelines.release-publish.yml)
- [Commits](https://github.com/microsoft/TypeScript/compare/v5.9.2...v5.9.3)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-version: 20.19.19
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm
- dependency-name: typescript
  dependency-version: 5.9.3
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-10-06 22:48:36 -04:00
8 changed files with 72 additions and 22 deletions

View File

@@ -1,3 +1,11 @@
## 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 ## 2.3.4
## What's Changed ## What's Changed

View File

@@ -128,6 +128,7 @@ describe('util', () => {
github_ref: '', github_ref: '',
github_repository: '', github_repository: '',
github_token: '', github_token: '',
input_working_directory: undefined,
input_append_body: false, input_append_body: false,
input_body: undefined, input_body: undefined,
input_body_path: undefined, input_body_path: undefined,
@@ -156,6 +157,7 @@ describe('util', () => {
github_ref: '', github_ref: '',
github_repository: '', github_repository: '',
github_token: '', github_token: '',
input_working_directory: undefined,
input_append_body: false, input_append_body: false,
input_body: undefined, input_body: undefined,
input_body_path: undefined, input_body_path: undefined,
@@ -183,6 +185,7 @@ describe('util', () => {
github_ref: '', github_ref: '',
github_repository: '', github_repository: '',
github_token: '', github_token: '',
input_working_directory: undefined,
input_append_body: false, input_append_body: false,
input_body: undefined, input_body: undefined,
input_body_path: undefined, input_body_path: undefined,
@@ -211,6 +214,7 @@ describe('util', () => {
github_ref: '', github_ref: '',
github_repository: '', github_repository: '',
github_token: '', github_token: '',
input_working_directory: undefined,
input_append_body: false, input_append_body: false,
input_body: undefined, input_body: undefined,
input_body_path: undefined, input_body_path: undefined,
@@ -243,6 +247,7 @@ describe('util', () => {
github_ref: '', github_ref: '',
github_repository: '', github_repository: '',
github_token: 'env-token', github_token: 'env-token',
input_working_directory: undefined,
input_append_body: false, input_append_body: false,
input_body: undefined, input_body: undefined,
input_body_path: undefined, input_body_path: undefined,
@@ -272,6 +277,7 @@ describe('util', () => {
github_ref: '', github_ref: '',
github_repository: '', github_repository: '',
github_token: 'input-token', github_token: 'input-token',
input_working_directory: undefined,
input_append_body: false, input_append_body: false,
input_body: undefined, input_body: undefined,
input_body_path: undefined, input_body_path: undefined,
@@ -300,6 +306,7 @@ describe('util', () => {
github_ref: '', github_ref: '',
github_repository: '', github_repository: '',
github_token: '', github_token: '',
input_working_directory: undefined,
input_append_body: false, input_append_body: false,
input_body: undefined, input_body: undefined,
input_body_path: undefined, input_body_path: undefined,
@@ -327,6 +334,7 @@ describe('util', () => {
github_ref: '', github_ref: '',
github_repository: '', github_repository: '',
github_token: '', github_token: '',
input_working_directory: undefined,
input_append_body: false, input_append_body: false,
input_body: undefined, input_body: undefined,
input_body_path: undefined, input_body_path: undefined,
@@ -354,6 +362,7 @@ describe('util', () => {
github_ref: '', github_ref: '',
github_repository: '', github_repository: '',
github_token: '', github_token: '',
input_working_directory: undefined,
input_append_body: true, input_append_body: true,
input_body: undefined, input_body: undefined,
input_body_path: undefined, input_body_path: undefined,
@@ -388,6 +397,10 @@ describe('util', () => {
'tests/data/foo/bar.txt', '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', () => { describe('unmatchedPatterns', () => {
@@ -397,6 +410,12 @@ describe('util', () => {
['tests/data/does/not/exist/*'], ['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', () => { describe('replaceSpacesWithDots', () => {

View File

@@ -27,6 +27,9 @@ inputs:
files: files:
description: "Newline-delimited list of path globs for asset files to upload" description: "Newline-delimited list of path globs for asset files to upload"
required: false required: false
working_directory:
description: "Base directory to resolve 'files' globs against (defaults to job working-directory)"
required: false
overwrite_files: overwrite_files:
description: "Overwrite existing files with the same name. Defaults to true" description: "Overwrite existing files with the same name. Defaults to true"
required: false 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", "name": "action-gh-release",
"version": "2.3.4", "version": "2.4.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "action-gh-release", "name": "action-gh-release",
"version": "2.3.4", "version": "2.4.0",
"dependencies": { "dependencies": {
"@actions/core": "^1.11.1", "@actions/core": "^1.11.1",
"@actions/github": "^6.0.1", "@actions/github": "^6.0.1",
@@ -18,12 +18,12 @@
"devDependencies": { "devDependencies": {
"@types/glob": "^9.0.0", "@types/glob": "^9.0.0",
"@types/mime-types": "^3.0.1", "@types/mime-types": "^3.0.1",
"@types/node": "^20.19.18", "@types/node": "^20.19.19",
"@vercel/ncc": "^0.38.4", "@vercel/ncc": "^0.38.4",
"@vitest/coverage-v8": "^3.2.4", "@vitest/coverage-v8": "^3.2.4",
"prettier": "3.6.2", "prettier": "3.6.2",
"ts-node": "^10.9.2", "ts-node": "^10.9.2",
"typescript": "^5.9.2", "typescript": "^5.9.3",
"typescript-formatter": "^7.2.2", "typescript-formatter": "^7.2.2",
"vitest": "^3.1.4" "vitest": "^3.1.4"
} }
@@ -1482,9 +1482,9 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/@types/node": { "node_modules/@types/node": {
"version": "20.19.18", "version": "20.19.19",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.18.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.19.tgz",
"integrity": "sha512-KeYVbfnbsBCyKG8e3gmUqAfyZNcoj/qpEbHRkQkfZdKOBrU7QQ+BsTdfqLSWX9/m1ytYreMhpKvp+EZi3UFYAg==", "integrity": "sha512-pb1Uqj5WJP7wrcbLU7Ru4QtA0+3kAXrkutGiD26wUKzSMgNNaPARTUDQmElUXp64kh3cWdou3Q0C7qwwxqSFmg==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
@@ -2817,9 +2817,9 @@
} }
}, },
"node_modules/typescript": { "node_modules/typescript": {
"version": "5.9.2", "version": "5.9.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.2.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
"integrity": "sha512-CWBzXQrc/qOkhidw1OzBTQuYRbfyxDXJMVJ1XNwUHGROVmuaeiEm3OslpZ1RV96d7SKKjZKrSJu3+t/xlw3R9A==", "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
"dev": true, "dev": true,
"license": "Apache-2.0", "license": "Apache-2.0",
"bin": { "bin": {

View File

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

View File

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

View File

@@ -1,5 +1,6 @@
import * as glob from 'glob'; import * as glob from 'glob';
import { statSync, readFileSync } from 'fs'; import { statSync, readFileSync } from 'fs';
import * as pathLib from 'path';
export interface Config { export interface Config {
github_token: string; github_token: string;
@@ -12,6 +13,7 @@ export interface Config {
input_body?: string; input_body?: string;
input_body_path?: string; input_body_path?: string;
input_files?: string[]; input_files?: string[];
input_working_directory?: string;
input_overwrite_files?: boolean; input_overwrite_files?: boolean;
input_draft?: boolean; input_draft?: boolean;
input_preserve_order?: boolean; input_preserve_order?: boolean;
@@ -62,6 +64,7 @@ export const parseConfig = (env: Env): Config => {
input_body: env.INPUT_BODY, input_body: env.INPUT_BODY,
input_body_path: env.INPUT_BODY_PATH, input_body_path: env.INPUT_BODY_PATH,
input_files: parseInputFiles(env.INPUT_FILES || ''), input_files: parseInputFiles(env.INPUT_FILES || ''),
input_working_directory: env.INPUT_WORKING_DIRECTORY || undefined,
input_overwrite_files: env.INPUT_OVERWRITE_FILES input_overwrite_files: env.INPUT_OVERWRITE_FILES
? env.INPUT_OVERWRITE_FILES == 'true' ? env.INPUT_OVERWRITE_FILES == 'true'
: undefined, : undefined,
@@ -84,17 +87,34 @@ const parseMakeLatest = (value: string | undefined): 'true' | 'false' | 'legacy'
return undefined; return undefined;
}; };
export const paths = (patterns: string[]): string[] => { export const paths = (patterns: string[], cwd?: string): string[] => {
return patterns.reduce((acc: string[], pattern: string): string[] => { return patterns.reduce((acc: string[], pattern: string): string[] => {
return acc.concat(glob.sync(pattern).filter((path) => statSync(path).isFile())); 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);
}, []); }, []);
}; };
export const unmatchedPatterns = (patterns: string[]): string[] => { export const unmatchedPatterns = (patterns: string[], cwd?: string): string[] => {
return patterns.reduce((acc: string[], pattern: string): string[] => { return patterns.reduce((acc: string[], pattern: string): string[] => {
return acc.concat( const matches = glob.sync(pattern, { cwd, dot: true, absolute: false });
glob.sync(pattern).filter((path) => statSync(path).isFile()).length == 0 ? [pattern] : [], 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] : []);
}, []); }, []);
}; };