mirror of
https://github.com/softprops/action-gh-release.git
synced 2025-10-09 08:56:12 +00:00
fix(util): support brace expansion globs containing commas in parseInputFiles (#672)
* Initial plan * fix(util): support brace expansion globs containing commas in parseInputFiles Co-authored-by: chenrui333 <1580956+chenrui333@users.noreply.github.com> * test(util): add comprehensive edge case coverage for brace expansion parsing Co-authored-by: chenrui333 <1580956+chenrui333@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: chenrui333 <1580956+chenrui333@users.noreply.github.com>
This commit is contained in:
parent
aec2ec56f9
commit
cec1a1113b
3 changed files with 77 additions and 9 deletions
|
@ -39,6 +39,18 @@ describe('util', () => {
|
||||||
'loom',
|
'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', () => {
|
describe('releaseBody', () => {
|
||||||
it('uses input body', () => {
|
it('uses input body', () => {
|
||||||
|
@ -432,3 +444,36 @@ 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',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
39
src/util.ts
39
src/util.ts
|
@ -43,15 +43,38 @@ export const releaseBody = (config: Config): string | undefined => {
|
||||||
|
|
||||||
type Env = { [key: string]: string | undefined };
|
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[] => {
|
export const parseInputFiles = (files: string): string[] => {
|
||||||
return files.split(/\r?\n/).reduce<string[]>(
|
return files
|
||||||
(acc, line) =>
|
.split(/\r?\n/)
|
||||||
acc
|
.flatMap((line) => smartSplit(line))
|
||||||
.concat(line.split(','))
|
.filter((pat) => pat.trim() !== '');
|
||||||
.filter((pat) => pat)
|
|
||||||
.map((pat) => pat.trim()),
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const parseConfig = (env: Env): Config => {
|
export const parseConfig = (env: Env): Config => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue