mirror of
https://github.com/actions/labeler.git
synced 2025-12-10 11:41:56 +00:00
[Beta] Implement the new structure of the match object for the changed-files section (#680)
* Implement the new structure of the match object for changed files section * Replace inner loops with the find method
This commit is contained in:
@@ -2,7 +2,11 @@ import {
|
|||||||
ChangedFilesMatchConfig,
|
ChangedFilesMatchConfig,
|
||||||
checkAllChangedFiles,
|
checkAllChangedFiles,
|
||||||
checkAnyChangedFiles,
|
checkAnyChangedFiles,
|
||||||
toChangedFilesMatchConfig
|
toChangedFilesMatchConfig,
|
||||||
|
checkIfAnyGlobMatchesAnyFile,
|
||||||
|
checkIfAllGlobsMatchAnyFile,
|
||||||
|
checkIfAnyGlobMatchesAllFiles,
|
||||||
|
checkIfAllGlobsMatchAllFiles
|
||||||
} from '../src/changedFiles';
|
} from '../src/changedFiles';
|
||||||
|
|
||||||
jest.mock('@actions/core');
|
jest.mock('@actions/core');
|
||||||
@@ -11,20 +15,28 @@ jest.mock('@actions/github');
|
|||||||
describe('checkAllChangedFiles', () => {
|
describe('checkAllChangedFiles', () => {
|
||||||
const changedFiles = ['foo.txt', 'bar.txt'];
|
const changedFiles = ['foo.txt', 'bar.txt'];
|
||||||
|
|
||||||
describe('when the globs match every file that has been changed', () => {
|
describe('when all given glob pattern configs matched', () => {
|
||||||
const globs = ['*.txt'];
|
const globPatternsConfigs = [
|
||||||
|
{AnyGlobToAnyFile: ['foo.txt']},
|
||||||
|
{AnyGlobToAllFiles: ['*.txt']},
|
||||||
|
{AllGlobsToAllFiles: ['**']}
|
||||||
|
];
|
||||||
|
|
||||||
it('returns true', () => {
|
it('returns true', () => {
|
||||||
const result = checkAllChangedFiles(changedFiles, globs);
|
const result = checkAllChangedFiles(changedFiles, globPatternsConfigs);
|
||||||
expect(result).toBe(true);
|
expect(result).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe(`when the globs don't match every file that has changed`, () => {
|
describe(`when some given glob pattern config did not match`, () => {
|
||||||
const globs = ['foo.txt'];
|
const globPatternsConfigs = [
|
||||||
|
{AnyGlobToAnyFile: ['*.md']},
|
||||||
|
{AnyGlobToAllFiles: ['*.txt']},
|
||||||
|
{AllGlobsToAllFiles: ['**']}
|
||||||
|
];
|
||||||
|
|
||||||
it('returns false', () => {
|
it('returns false', () => {
|
||||||
const result = checkAllChangedFiles(changedFiles, globs);
|
const result = checkAllChangedFiles(changedFiles, globPatternsConfigs);
|
||||||
expect(result).toBe(false);
|
expect(result).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -33,20 +45,26 @@ describe('checkAllChangedFiles', () => {
|
|||||||
describe('checkAnyChangedFiles', () => {
|
describe('checkAnyChangedFiles', () => {
|
||||||
const changedFiles = ['foo.txt', 'bar.txt'];
|
const changedFiles = ['foo.txt', 'bar.txt'];
|
||||||
|
|
||||||
describe('when any glob matches any of the files that have changed', () => {
|
describe('when any given glob pattern config matched', () => {
|
||||||
const globs = ['*.txt', '*.md'];
|
const globPatternsConfigs = [
|
||||||
|
{AnyGlobToAnyFile: ['*.md']},
|
||||||
|
{AnyGlobToAllFiles: ['*.txt']}
|
||||||
|
];
|
||||||
|
|
||||||
it('returns true', () => {
|
it('returns true', () => {
|
||||||
const result = checkAnyChangedFiles(changedFiles, globs);
|
const result = checkAnyChangedFiles(changedFiles, globPatternsConfigs);
|
||||||
expect(result).toBe(true);
|
expect(result).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when none of the globs match any files that have changed', () => {
|
describe('when none of the given glob pattern configs matched', () => {
|
||||||
const globs = ['*.md'];
|
const globPatternsConfigs = [
|
||||||
|
{AnyGlobToAnyFile: ['*.md']},
|
||||||
|
{AnyGlobToAllFiles: ['!*.txt']}
|
||||||
|
];
|
||||||
|
|
||||||
it('returns false', () => {
|
it('returns false', () => {
|
||||||
const result = checkAnyChangedFiles(changedFiles, globs);
|
const result = checkAnyChangedFiles(changedFiles, globPatternsConfigs);
|
||||||
expect(result).toBe(false);
|
expect(result).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -63,44 +81,140 @@ describe('toChangedFilesMatchConfig', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe(`when there is a 'changed-files' key in the config`, () => {
|
describe(`when there is a 'changed-files' key in the config`, () => {
|
||||||
|
describe('but the glob pattern config key is not provided', () => {
|
||||||
|
const config = {'changed-files': ['bar']};
|
||||||
|
|
||||||
|
it('throws the error', () => {
|
||||||
|
expect(() => {
|
||||||
|
toChangedFilesMatchConfig(config);
|
||||||
|
}).toThrow(
|
||||||
|
`The "changed-files" section must have a valid config structure. Please read the action documentation for more information`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('but the glob pattern config key is not valid', () => {
|
||||||
|
const config = {'changed-files': [{NotValidConfigKey: ['bar']}]};
|
||||||
|
|
||||||
|
it('throws the error', () => {
|
||||||
|
expect(() => {
|
||||||
|
toChangedFilesMatchConfig(config);
|
||||||
|
}).toThrow(
|
||||||
|
`Unknown config options were under "changed-files": NotValidConfigKey`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('and the glob pattern config key is provided', () => {
|
||||||
describe('and the value is an array of strings', () => {
|
describe('and the value is an array of strings', () => {
|
||||||
const config = {'changed-files': ['testing']};
|
const config = {'changed-files': [{AnyGlobToAnyFile: ['testing']}]};
|
||||||
|
|
||||||
it('sets the value in the config object', () => {
|
it('sets the value in the config object', () => {
|
||||||
const result = toChangedFilesMatchConfig(config);
|
const result = toChangedFilesMatchConfig(config);
|
||||||
expect(result).toEqual<ChangedFilesMatchConfig>({
|
expect(result).toEqual<ChangedFilesMatchConfig>({
|
||||||
changedFiles: ['testing']
|
changedFiles: [{AnyGlobToAnyFile: ['testing']}]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('and the value is a string', () => {
|
describe('and the value is a string', () => {
|
||||||
const config = {'changed-files': 'testing'};
|
const config = {'changed-files': [{AnyGlobToAnyFile: 'testing'}]};
|
||||||
|
|
||||||
it(`sets the string as an array in the config object`, () => {
|
it(`sets the string as an array in the config object`, () => {
|
||||||
const result = toChangedFilesMatchConfig(config);
|
const result = toChangedFilesMatchConfig(config);
|
||||||
expect(result).toEqual<ChangedFilesMatchConfig>({
|
expect(result).toEqual<ChangedFilesMatchConfig>({
|
||||||
changedFiles: ['testing']
|
changedFiles: [{AnyGlobToAnyFile: ['testing']}]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
describe('but the value is an empty string', () => {
|
});
|
||||||
const config = {'changed-files': ''};
|
});
|
||||||
|
|
||||||
it(`returns an empty object`, () => {
|
describe('checkIfAnyGlobMatchesAnyFile', () => {
|
||||||
const result = toChangedFilesMatchConfig(config);
|
const changedFiles = ['foo.txt', 'bar.txt'];
|
||||||
expect(result).toEqual<ChangedFilesMatchConfig>({});
|
|
||||||
});
|
describe('when any given glob pattern matched any file', () => {
|
||||||
});
|
const globPatterns = ['*.md', 'foo.txt'];
|
||||||
|
|
||||||
describe('but the value is an empty array', () => {
|
it('returns true', () => {
|
||||||
const config = {'changed-files': []};
|
const result = checkIfAnyGlobMatchesAnyFile(changedFiles, globPatterns);
|
||||||
|
expect(result).toBe(true);
|
||||||
it(`returns an empty object`, () => {
|
});
|
||||||
const result = toChangedFilesMatchConfig(config);
|
});
|
||||||
expect(result).toEqual<ChangedFilesMatchConfig>({});
|
|
||||||
});
|
describe('when none of the given glob pattern matched any file', () => {
|
||||||
|
const globPatterns = ['*.md', '!*.txt'];
|
||||||
|
|
||||||
|
it('returns false', () => {
|
||||||
|
const result = checkIfAnyGlobMatchesAnyFile(changedFiles, globPatterns);
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('checkIfAllGlobsMatchAnyFile', () => {
|
||||||
|
const changedFiles = ['foo.txt', 'bar.txt'];
|
||||||
|
|
||||||
|
describe('when all given glob patterns matched any file', () => {
|
||||||
|
const globPatterns = ['**/bar.txt', 'bar.txt'];
|
||||||
|
|
||||||
|
it('returns true', () => {
|
||||||
|
const result = checkIfAllGlobsMatchAnyFile(changedFiles, globPatterns);
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when some of the given glob patterns did not match any file', () => {
|
||||||
|
const globPatterns = ['*.txt', '*.md'];
|
||||||
|
|
||||||
|
it('returns false', () => {
|
||||||
|
const result = checkIfAllGlobsMatchAnyFile(changedFiles, globPatterns);
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('checkIfAnyGlobMatchesAllFiles', () => {
|
||||||
|
const changedFiles = ['foo.txt', 'bar.txt'];
|
||||||
|
|
||||||
|
describe('when any given glob pattern matched all files', () => {
|
||||||
|
const globPatterns = ['*.md', '*.txt'];
|
||||||
|
|
||||||
|
it('returns true', () => {
|
||||||
|
const result = checkIfAnyGlobMatchesAllFiles(changedFiles, globPatterns);
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when none of the given glob patterns matched all files', () => {
|
||||||
|
const globPatterns = ['*.md', 'bar.txt', 'foo.txt'];
|
||||||
|
|
||||||
|
it('returns false', () => {
|
||||||
|
const result = checkIfAnyGlobMatchesAllFiles(changedFiles, globPatterns);
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('checkIfAllGlobsMatchAllFiles', () => {
|
||||||
|
const changedFiles = ['foo.txt', 'bar.txt'];
|
||||||
|
|
||||||
|
describe('when all given glob patterns matched all files', () => {
|
||||||
|
const globPatterns = ['*.txt', '**'];
|
||||||
|
|
||||||
|
it('returns true', () => {
|
||||||
|
const result = checkIfAllGlobsMatchAllFiles(changedFiles, globPatterns);
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when some of the given glob patterns did not match all files', () => {
|
||||||
|
const globPatterns = ['**', 'foo.txt'];
|
||||||
|
|
||||||
|
it('returns false', () => {
|
||||||
|
const result = checkIfAllGlobsMatchAllFiles(changedFiles, globPatterns);
|
||||||
|
expect(result).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
label1:
|
label1:
|
||||||
- any:
|
- any:
|
||||||
- changed-files: ['glob']
|
- changed-files:
|
||||||
|
- AnyGlobToAnyFile: ['glob']
|
||||||
- head-branch: ['regexp']
|
- head-branch: ['regexp']
|
||||||
- base-branch: ['regexp']
|
- base-branch: ['regexp']
|
||||||
- all:
|
- all:
|
||||||
- changed-files: ['glob']
|
- changed-files:
|
||||||
|
- AllGlobsToAllFiles: ['glob']
|
||||||
- head-branch: ['regexp']
|
- head-branch: ['regexp']
|
||||||
- base-branch: ['regexp']
|
- base-branch: ['regexp']
|
||||||
|
|
||||||
label2:
|
label2:
|
||||||
- changed-files: ['glob']
|
- changed-files:
|
||||||
|
- AnyGlobToAnyFile: ['glob']
|
||||||
- head-branch: ['regexp']
|
- head-branch: ['regexp']
|
||||||
- base-branch: ['regexp']
|
- base-branch: ['regexp']
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
tests:
|
tests:
|
||||||
- any:
|
- any:
|
||||||
- head-branch: ['^tests/', '^test/']
|
- head-branch: ['^tests/', '^test/']
|
||||||
- changed-files: ['tests/**/*']
|
- changed-files:
|
||||||
|
- AnyGlobToAnyFile: ['tests/**/*']
|
||||||
- all:
|
- all:
|
||||||
- changed-files: ['!tests/requirements.txt']
|
- changed-files:
|
||||||
|
- AllGlobsToAllFiles: ['!tests/requirements.txt']
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
touched-a-pdf-file:
|
touched-a-pdf-file:
|
||||||
- changed-files: ['*.pdf']
|
- changed-files:
|
||||||
|
- AnyGlobToAnyFile: ['*.pdf']
|
||||||
|
|||||||
@@ -29,14 +29,14 @@ describe('getLabelConfigMapFromObject', () => {
|
|||||||
expected.set('label1', [
|
expected.set('label1', [
|
||||||
{
|
{
|
||||||
any: [
|
any: [
|
||||||
{changedFiles: ['glob']},
|
{changedFiles: [{AnyGlobToAnyFile: ['glob']}]},
|
||||||
{baseBranch: undefined, headBranch: ['regexp']},
|
{baseBranch: undefined, headBranch: ['regexp']},
|
||||||
{baseBranch: ['regexp'], headBranch: undefined}
|
{baseBranch: ['regexp'], headBranch: undefined}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
all: [
|
all: [
|
||||||
{changedFiles: ['glob']},
|
{changedFiles: [{AllGlobsToAllFiles: ['glob']}]},
|
||||||
{baseBranch: undefined, headBranch: ['regexp']},
|
{baseBranch: undefined, headBranch: ['regexp']},
|
||||||
{baseBranch: ['regexp'], headBranch: undefined}
|
{baseBranch: ['regexp'], headBranch: undefined}
|
||||||
]
|
]
|
||||||
@@ -45,7 +45,7 @@ describe('getLabelConfigMapFromObject', () => {
|
|||||||
expected.set('label2', [
|
expected.set('label2', [
|
||||||
{
|
{
|
||||||
any: [
|
any: [
|
||||||
{changedFiles: ['glob']},
|
{changedFiles: [{AnyGlobToAnyFile: ['glob']}]},
|
||||||
{baseBranch: undefined, headBranch: ['regexp']},
|
{baseBranch: undefined, headBranch: ['regexp']},
|
||||||
{baseBranch: ['regexp'], headBranch: undefined}
|
{baseBranch: ['regexp'], headBranch: undefined}
|
||||||
]
|
]
|
||||||
@@ -61,12 +61,12 @@ describe('getLabelConfigMapFromObject', () => {
|
|||||||
describe('toMatchConfig', () => {
|
describe('toMatchConfig', () => {
|
||||||
describe('when all expected config options are present', () => {
|
describe('when all expected config options are present', () => {
|
||||||
const config = {
|
const config = {
|
||||||
'changed-files': ['testing-files'],
|
'changed-files': [{AnyGlobToAnyFile: ['testing-files']}],
|
||||||
'head-branch': ['testing-head'],
|
'head-branch': ['testing-head'],
|
||||||
'base-branch': ['testing-base']
|
'base-branch': ['testing-base']
|
||||||
};
|
};
|
||||||
const expected: BaseMatchConfig = {
|
const expected: BaseMatchConfig = {
|
||||||
changedFiles: ['testing-files'],
|
changedFiles: [{AnyGlobToAnyFile: ['testing-files']}],
|
||||||
headBranch: ['testing-head'],
|
headBranch: ['testing-head'],
|
||||||
baseBranch: ['testing-base']
|
baseBranch: ['testing-base']
|
||||||
};
|
};
|
||||||
@@ -89,7 +89,9 @@ describe('toMatchConfig', () => {
|
|||||||
|
|
||||||
describe('checkMatchConfigs', () => {
|
describe('checkMatchConfigs', () => {
|
||||||
describe('when a single match config is provided', () => {
|
describe('when a single match config is provided', () => {
|
||||||
const matchConfig: MatchConfig[] = [{any: [{changedFiles: ['*.txt']}]}];
|
const matchConfig: MatchConfig[] = [
|
||||||
|
{any: [{changedFiles: [{AnyGlobToAnyFile: ['*.txt']}]}]}
|
||||||
|
];
|
||||||
|
|
||||||
it('returns true when our pattern does match changed files', () => {
|
it('returns true when our pattern does match changed files', () => {
|
||||||
const changedFiles = ['foo.txt', 'bar.txt'];
|
const changedFiles = ['foo.txt', 'bar.txt'];
|
||||||
@@ -107,7 +109,12 @@ describe('checkMatchConfigs', () => {
|
|||||||
|
|
||||||
it('returns true when either the branch or changed files patter matches', () => {
|
it('returns true when either the branch or changed files patter matches', () => {
|
||||||
const matchConfig: MatchConfig[] = [
|
const matchConfig: MatchConfig[] = [
|
||||||
{any: [{changedFiles: ['*.txt']}, {headBranch: ['some-branch']}]}
|
{
|
||||||
|
any: [
|
||||||
|
{changedFiles: [{AnyGlobToAnyFile: ['*.txt']}]},
|
||||||
|
{headBranch: ['some-branch']}
|
||||||
|
]
|
||||||
|
}
|
||||||
];
|
];
|
||||||
const changedFiles = ['foo.txt', 'bar.txt'];
|
const changedFiles = ['foo.txt', 'bar.txt'];
|
||||||
|
|
||||||
@@ -118,7 +125,7 @@ describe('checkMatchConfigs', () => {
|
|||||||
|
|
||||||
describe('when multiple MatchConfigs are supplied', () => {
|
describe('when multiple MatchConfigs are supplied', () => {
|
||||||
const matchConfig: MatchConfig[] = [
|
const matchConfig: MatchConfig[] = [
|
||||||
{any: [{changedFiles: ['*.txt']}]},
|
{any: [{changedFiles: [{AnyGlobToAnyFile: ['*.txt']}]}]},
|
||||||
{any: [{headBranch: ['some-branch']}]}
|
{any: [{headBranch: ['some-branch']}]}
|
||||||
];
|
];
|
||||||
const changedFiles = ['foo.txt', 'bar.md'];
|
const changedFiles = ['foo.txt', 'bar.md'];
|
||||||
@@ -130,7 +137,7 @@ describe('checkMatchConfigs', () => {
|
|||||||
|
|
||||||
it('returns true when only both config matches', () => {
|
it('returns true when only both config matches', () => {
|
||||||
const matchConfig: MatchConfig[] = [
|
const matchConfig: MatchConfig[] = [
|
||||||
{any: [{changedFiles: ['*.txt']}]},
|
{any: [{changedFiles: [{AnyGlobToAnyFile: ['*.txt']}]}]},
|
||||||
{any: [{headBranch: ['head-branch']}]}
|
{any: [{headBranch: ['head-branch']}]}
|
||||||
];
|
];
|
||||||
const result = checkMatchConfigs(changedFiles, matchConfig);
|
const result = checkMatchConfigs(changedFiles, matchConfig);
|
||||||
|
|||||||
197
dist/index.js
vendored
197
dist/index.js
vendored
@@ -150,10 +150,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.checkAllChangedFiles = exports.checkAnyChangedFiles = exports.toChangedFilesMatchConfig = exports.getChangedFiles = void 0;
|
exports.checkIfAllGlobsMatchAllFiles = exports.checkIfAnyGlobMatchesAllFiles = exports.checkIfAllGlobsMatchAnyFile = exports.checkIfAnyGlobMatchesAnyFile = exports.checkAllChangedFiles = exports.checkAnyChangedFiles = exports.toChangedFilesMatchConfig = exports.getChangedFiles = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const github = __importStar(__nccwpck_require__(5438));
|
const github = __importStar(__nccwpck_require__(5438));
|
||||||
const minimatch_1 = __nccwpck_require__(2002);
|
const minimatch_1 = __nccwpck_require__(2002);
|
||||||
|
const ALLOWED_FILES_CONFIG_KEYS = [
|
||||||
|
'AnyGlobToAnyFile',
|
||||||
|
'AnyGlobToAllFiles',
|
||||||
|
'AllGlobsToAnyFile',
|
||||||
|
'AllGlobsToAllFiles'
|
||||||
|
];
|
||||||
function getChangedFiles(client, prNumber) {
|
function getChangedFiles(client, prNumber) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const listFilesOptions = client.rest.pulls.listFiles.endpoint.merge({
|
const listFilesOptions = client.rest.pulls.listFiles.endpoint.merge({
|
||||||
@@ -175,65 +181,174 @@ function toChangedFilesMatchConfig(config) {
|
|||||||
if (!config['changed-files'] || !config['changed-files'].length) {
|
if (!config['changed-files'] || !config['changed-files'].length) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
const changedFilesConfig = config['changed-files'];
|
const changedFilesConfigs = Array.isArray(config['changed-files'])
|
||||||
|
? config['changed-files']
|
||||||
|
: [config['changed-files']];
|
||||||
|
const validChangedFilesConfigs = [];
|
||||||
|
changedFilesConfigs.forEach(changedFilesConfig => {
|
||||||
|
if (!isObject(changedFilesConfig)) {
|
||||||
|
throw new Error(`The "changed-files" section must have a valid config structure. Please read the action documentation for more information`);
|
||||||
|
}
|
||||||
|
const changedFilesConfigKeys = Object.keys(changedFilesConfig);
|
||||||
|
const invalidKeys = changedFilesConfigKeys.filter(key => !ALLOWED_FILES_CONFIG_KEYS.includes(key));
|
||||||
|
if (invalidKeys.length) {
|
||||||
|
throw new Error(`Unknown config options were under "changed-files": ${invalidKeys.join(', ')}`);
|
||||||
|
}
|
||||||
|
changedFilesConfigKeys.forEach(key => {
|
||||||
|
validChangedFilesConfigs.push({
|
||||||
|
[key]: Array.isArray(changedFilesConfig[key])
|
||||||
|
? changedFilesConfig[key]
|
||||||
|
: [changedFilesConfig[key]]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
return {
|
return {
|
||||||
changedFiles: Array.isArray(changedFilesConfig)
|
changedFiles: validChangedFilesConfigs
|
||||||
? changedFilesConfig
|
|
||||||
: [changedFilesConfig]
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
exports.toChangedFilesMatchConfig = toChangedFilesMatchConfig;
|
exports.toChangedFilesMatchConfig = toChangedFilesMatchConfig;
|
||||||
|
function isObject(obj) {
|
||||||
|
return obj !== null && typeof obj === 'object' && !Array.isArray(obj);
|
||||||
|
}
|
||||||
function printPattern(matcher) {
|
function printPattern(matcher) {
|
||||||
return (matcher.negate ? '!' : '') + matcher.pattern;
|
return (matcher.negate ? '!' : '') + matcher.pattern;
|
||||||
}
|
}
|
||||||
function isAnyMatch(changedFile, matchers) {
|
function checkAnyChangedFiles(changedFiles, globPatternsConfigs) {
|
||||||
core.debug(` matching patterns against file ${changedFile}`);
|
core.debug(` checking "changed-files" patterns`);
|
||||||
for (const matcher of matchers) {
|
for (const globPatternsConfig of globPatternsConfigs) {
|
||||||
core.debug(` - ${printPattern(matcher)}`);
|
if (globPatternsConfig.AnyGlobToAnyFile) {
|
||||||
if (matcher.match(changedFile)) {
|
if (checkIfAnyGlobMatchesAnyFile(changedFiles, globPatternsConfig.AnyGlobToAnyFile)) {
|
||||||
core.debug(` ${printPattern(matcher)} matched`);
|
core.debug(` "changed-files" matched`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
core.debug(` no patterns matched`);
|
if (globPatternsConfig.AnyGlobToAllFiles) {
|
||||||
return false;
|
if (checkIfAnyGlobMatchesAllFiles(changedFiles, globPatternsConfig.AnyGlobToAllFiles)) {
|
||||||
}
|
core.debug(` "changed-files" matched`);
|
||||||
function isAllMatch(changedFile, matchers) {
|
|
||||||
core.debug(` matching patterns against file ${changedFile}`);
|
|
||||||
for (const matcher of matchers) {
|
|
||||||
core.debug(` - ${printPattern(matcher)}`);
|
|
||||||
if (!matcher.match(changedFile)) {
|
|
||||||
core.debug(` ${printPattern(matcher)} did not match`);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
core.debug(` all patterns matched`);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
function checkAnyChangedFiles(changedFiles, globs) {
|
|
||||||
const matchers = globs.map(g => new minimatch_1.Minimatch(g));
|
|
||||||
for (const changedFile of changedFiles) {
|
|
||||||
if (isAnyMatch(changedFile, matchers)) {
|
|
||||||
core.debug(` "any" patterns matched against ${changedFile}`);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
core.debug(` "any" patterns did not match any files`);
|
if (globPatternsConfig.AllGlobsToAnyFile) {
|
||||||
|
if (checkIfAllGlobsMatchAnyFile(changedFiles, globPatternsConfig.AllGlobsToAnyFile)) {
|
||||||
|
core.debug(` "changed-files" matched`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (globPatternsConfig.AllGlobsToAllFiles) {
|
||||||
|
if (checkIfAllGlobsMatchAllFiles(changedFiles, globPatternsConfig.AllGlobsToAllFiles)) {
|
||||||
|
core.debug(` "changed-files" matched`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
core.debug(` "changed-files" did not match`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
exports.checkAnyChangedFiles = checkAnyChangedFiles;
|
exports.checkAnyChangedFiles = checkAnyChangedFiles;
|
||||||
function checkAllChangedFiles(changedFiles, globs) {
|
function checkAllChangedFiles(changedFiles, globPatternsConfigs) {
|
||||||
const matchers = globs.map(g => new minimatch_1.Minimatch(g));
|
core.debug(` checking "changed-files" patterns`);
|
||||||
for (const changedFile of changedFiles) {
|
for (const globPatternsConfig of globPatternsConfigs) {
|
||||||
if (!isAllMatch(changedFile, matchers)) {
|
if (globPatternsConfig.AnyGlobToAnyFile) {
|
||||||
core.debug(` "all" patterns did not match against ${changedFile}`);
|
if (!checkIfAnyGlobMatchesAnyFile(changedFiles, globPatternsConfig.AnyGlobToAnyFile)) {
|
||||||
|
core.debug(` "changed-files" did not match`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
core.debug(` "all" patterns matched all files`);
|
if (globPatternsConfig.AnyGlobToAllFiles) {
|
||||||
|
if (!checkIfAnyGlobMatchesAllFiles(changedFiles, globPatternsConfig.AnyGlobToAllFiles)) {
|
||||||
|
core.debug(` "changed-files" did not match`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (globPatternsConfig.AllGlobsToAnyFile) {
|
||||||
|
if (!checkIfAllGlobsMatchAnyFile(changedFiles, globPatternsConfig.AllGlobsToAnyFile)) {
|
||||||
|
core.debug(` "changed-files" did not match`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (globPatternsConfig.AllGlobsToAllFiles) {
|
||||||
|
if (!checkIfAllGlobsMatchAllFiles(changedFiles, globPatternsConfig.AllGlobsToAllFiles)) {
|
||||||
|
core.debug(` "changed-files" did not match`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
core.debug(` "changed-files" patterns matched`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
exports.checkAllChangedFiles = checkAllChangedFiles;
|
exports.checkAllChangedFiles = checkAllChangedFiles;
|
||||||
|
function checkIfAnyGlobMatchesAnyFile(changedFiles, globs) {
|
||||||
|
core.debug(` checking "AnyGlobToAnyFile" config patterns`);
|
||||||
|
const matchers = globs.map(g => new minimatch_1.Minimatch(g));
|
||||||
|
for (const matcher of matchers) {
|
||||||
|
const matchedFile = changedFiles.find(changedFile => {
|
||||||
|
core.debug(` checking "${printPattern(matcher)}" pattern against ${changedFile}`);
|
||||||
|
return matcher.match(changedFile);
|
||||||
|
});
|
||||||
|
if (matchedFile) {
|
||||||
|
core.debug(` "${printPattern(matcher)}" pattern matched ${matchedFile}`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
core.debug(` none of the patterns matched any of the files`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
exports.checkIfAnyGlobMatchesAnyFile = checkIfAnyGlobMatchesAnyFile;
|
||||||
|
function checkIfAllGlobsMatchAnyFile(changedFiles, globs) {
|
||||||
|
core.debug(` checking "AllGlobsToAnyFile" config patterns`);
|
||||||
|
const matchers = globs.map(g => new minimatch_1.Minimatch(g));
|
||||||
|
for (const changedFile of changedFiles) {
|
||||||
|
const mismatchedGlob = matchers.find(matcher => {
|
||||||
|
core.debug(` checking "${printPattern(matcher)}" pattern against ${changedFile}`);
|
||||||
|
return !matcher.match(changedFile);
|
||||||
|
});
|
||||||
|
if (mismatchedGlob) {
|
||||||
|
core.debug(` "${printPattern(mismatchedGlob)}" pattern did not match ${changedFile}`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
core.debug(` all patterns matched ${changedFile}`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
core.debug(` none of the files matched all patterns`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
exports.checkIfAllGlobsMatchAnyFile = checkIfAllGlobsMatchAnyFile;
|
||||||
|
function checkIfAnyGlobMatchesAllFiles(changedFiles, globs) {
|
||||||
|
core.debug(` checking "AnyGlobToAllFiles" config patterns`);
|
||||||
|
const matchers = globs.map(g => new minimatch_1.Minimatch(g));
|
||||||
|
for (const matcher of matchers) {
|
||||||
|
const mismatchedFile = changedFiles.find(changedFile => {
|
||||||
|
core.debug(` checking "${printPattern(matcher)}" pattern against ${changedFile}`);
|
||||||
|
return !matcher.match(changedFile);
|
||||||
|
});
|
||||||
|
if (mismatchedFile) {
|
||||||
|
core.debug(` "${printPattern(matcher)}" pattern did not match ${mismatchedFile}`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
core.debug(` "${printPattern(matcher)}" pattern matched all files`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
core.debug(` none of the patterns matched all files`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
exports.checkIfAnyGlobMatchesAllFiles = checkIfAnyGlobMatchesAllFiles;
|
||||||
|
function checkIfAllGlobsMatchAllFiles(changedFiles, globs) {
|
||||||
|
core.debug(` checking "AllGlobsToAllFiles" config patterns`);
|
||||||
|
const matchers = globs.map(g => new minimatch_1.Minimatch(g));
|
||||||
|
for (const changedFile of changedFiles) {
|
||||||
|
const mismatchedGlob = matchers.find(matcher => {
|
||||||
|
core.debug(` checking "${printPattern(matcher)}" pattern against ${changedFile}`);
|
||||||
|
return !matcher.match(changedFile);
|
||||||
|
});
|
||||||
|
if (mismatchedGlob) {
|
||||||
|
core.debug(` "${printPattern(mismatchedGlob)}" pattern did not match ${changedFile}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
core.debug(` all patterns matched all files`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
exports.checkIfAllGlobsMatchAllFiles = checkIfAllGlobsMatchAllFiles;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
@@ -447,16 +562,19 @@ function checkAny(matchConfigs, changedFiles) {
|
|||||||
for (const matchConfig of matchConfigs) {
|
for (const matchConfig of matchConfigs) {
|
||||||
if (matchConfig.baseBranch) {
|
if (matchConfig.baseBranch) {
|
||||||
if ((0, branch_1.checkAnyBranch)(matchConfig.baseBranch, 'base')) {
|
if ((0, branch_1.checkAnyBranch)(matchConfig.baseBranch, 'base')) {
|
||||||
|
core.debug(` "any" patterns matched`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (matchConfig.changedFiles) {
|
if (matchConfig.changedFiles) {
|
||||||
if ((0, changedFiles_1.checkAnyChangedFiles)(changedFiles, matchConfig.changedFiles)) {
|
if ((0, changedFiles_1.checkAnyChangedFiles)(changedFiles, matchConfig.changedFiles)) {
|
||||||
|
core.debug(` "any" patterns matched`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (matchConfig.headBranch) {
|
if (matchConfig.headBranch) {
|
||||||
if ((0, branch_1.checkAnyBranch)(matchConfig.headBranch, 'head')) {
|
if ((0, branch_1.checkAnyBranch)(matchConfig.headBranch, 'head')) {
|
||||||
|
core.debug(` "any" patterns matched`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -476,6 +594,7 @@ function checkAll(matchConfigs, changedFiles) {
|
|||||||
for (const matchConfig of matchConfigs) {
|
for (const matchConfig of matchConfigs) {
|
||||||
if (matchConfig.baseBranch) {
|
if (matchConfig.baseBranch) {
|
||||||
if (!(0, branch_1.checkAllBranch)(matchConfig.baseBranch, 'base')) {
|
if (!(0, branch_1.checkAllBranch)(matchConfig.baseBranch, 'base')) {
|
||||||
|
core.debug(` "all" patterns did not match`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -485,11 +604,13 @@ function checkAll(matchConfigs, changedFiles) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!(0, changedFiles_1.checkAllChangedFiles)(changedFiles, matchConfig.changedFiles)) {
|
if (!(0, changedFiles_1.checkAllChangedFiles)(changedFiles, matchConfig.changedFiles)) {
|
||||||
|
core.debug(` "all" patterns did not match`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (matchConfig.headBranch) {
|
if (matchConfig.headBranch) {
|
||||||
if (!(0, branch_1.checkAllBranch)(matchConfig.headBranch, 'head')) {
|
if (!(0, branch_1.checkAllBranch)(matchConfig.headBranch, 'head')) {
|
||||||
|
core.debug(` "all" patterns did not match`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,25 @@ import * as github from '@actions/github';
|
|||||||
import {Minimatch} from 'minimatch';
|
import {Minimatch} from 'minimatch';
|
||||||
|
|
||||||
export interface ChangedFilesMatchConfig {
|
export interface ChangedFilesMatchConfig {
|
||||||
changedFiles?: string[];
|
changedFiles?: ChangedFilesGlobPatternsConfig[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ChangedFilesGlobPatternsConfig {
|
||||||
|
AnyGlobToAnyFile?: string[];
|
||||||
|
AnyGlobToAllFiles?: string[];
|
||||||
|
AllGlobsToAnyFile?: string[];
|
||||||
|
AllGlobsToAllFiles?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
type ClientType = ReturnType<typeof github.getOctokit>;
|
type ClientType = ReturnType<typeof github.getOctokit>;
|
||||||
|
|
||||||
|
const ALLOWED_FILES_CONFIG_KEYS = [
|
||||||
|
'AnyGlobToAnyFile',
|
||||||
|
'AnyGlobToAllFiles',
|
||||||
|
'AllGlobsToAnyFile',
|
||||||
|
'AllGlobsToAllFiles'
|
||||||
|
];
|
||||||
|
|
||||||
export async function getChangedFiles(
|
export async function getChangedFiles(
|
||||||
client: ClientType,
|
client: ClientType,
|
||||||
prNumber: number
|
prNumber: number
|
||||||
@@ -35,76 +49,305 @@ export function toChangedFilesMatchConfig(
|
|||||||
if (!config['changed-files'] || !config['changed-files'].length) {
|
if (!config['changed-files'] || !config['changed-files'].length) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
const changedFilesConfigs = Array.isArray(config['changed-files'])
|
||||||
|
? config['changed-files']
|
||||||
|
: [config['changed-files']];
|
||||||
|
|
||||||
const changedFilesConfig = config['changed-files'];
|
const validChangedFilesConfigs: ChangedFilesGlobPatternsConfig[] = [];
|
||||||
|
|
||||||
|
changedFilesConfigs.forEach(changedFilesConfig => {
|
||||||
|
if (!isObject(changedFilesConfig)) {
|
||||||
|
throw new Error(
|
||||||
|
`The "changed-files" section must have a valid config structure. Please read the action documentation for more information`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const changedFilesConfigKeys = Object.keys(changedFilesConfig);
|
||||||
|
const invalidKeys = changedFilesConfigKeys.filter(
|
||||||
|
key => !ALLOWED_FILES_CONFIG_KEYS.includes(key)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (invalidKeys.length) {
|
||||||
|
throw new Error(
|
||||||
|
`Unknown config options were under "changed-files": ${invalidKeys.join(
|
||||||
|
', '
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
changedFilesConfigKeys.forEach(key => {
|
||||||
|
validChangedFilesConfigs.push({
|
||||||
|
[key]: Array.isArray(changedFilesConfig[key])
|
||||||
|
? changedFilesConfig[key]
|
||||||
|
: [changedFilesConfig[key]]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
changedFiles: Array.isArray(changedFilesConfig)
|
changedFiles: validChangedFilesConfigs
|
||||||
? changedFilesConfig
|
|
||||||
: [changedFilesConfig]
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isObject(obj: unknown): obj is object {
|
||||||
|
return obj !== null && typeof obj === 'object' && !Array.isArray(obj);
|
||||||
|
}
|
||||||
|
|
||||||
function printPattern(matcher: Minimatch): string {
|
function printPattern(matcher: Minimatch): string {
|
||||||
return (matcher.negate ? '!' : '') + matcher.pattern;
|
return (matcher.negate ? '!' : '') + matcher.pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isAnyMatch(changedFile: string, matchers: Minimatch[]): boolean {
|
|
||||||
core.debug(` matching patterns against file ${changedFile}`);
|
|
||||||
for (const matcher of matchers) {
|
|
||||||
core.debug(` - ${printPattern(matcher)}`);
|
|
||||||
if (matcher.match(changedFile)) {
|
|
||||||
core.debug(` ${printPattern(matcher)} matched`);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
core.debug(` no patterns matched`);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isAllMatch(changedFile: string, matchers: Minimatch[]): boolean {
|
|
||||||
core.debug(` matching patterns against file ${changedFile}`);
|
|
||||||
for (const matcher of matchers) {
|
|
||||||
core.debug(` - ${printPattern(matcher)}`);
|
|
||||||
if (!matcher.match(changedFile)) {
|
|
||||||
core.debug(` ${printPattern(matcher)} did not match`);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
core.debug(` all patterns matched`);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function checkAnyChangedFiles(
|
export function checkAnyChangedFiles(
|
||||||
changedFiles: string[],
|
changedFiles: string[],
|
||||||
globs: string[]
|
globPatternsConfigs: ChangedFilesGlobPatternsConfig[]
|
||||||
): boolean {
|
): boolean {
|
||||||
const matchers = globs.map(g => new Minimatch(g));
|
core.debug(` checking "changed-files" patterns`);
|
||||||
for (const changedFile of changedFiles) {
|
|
||||||
if (isAnyMatch(changedFile, matchers)) {
|
for (const globPatternsConfig of globPatternsConfigs) {
|
||||||
core.debug(` "any" patterns matched against ${changedFile}`);
|
if (globPatternsConfig.AnyGlobToAnyFile) {
|
||||||
|
if (
|
||||||
|
checkIfAnyGlobMatchesAnyFile(
|
||||||
|
changedFiles,
|
||||||
|
globPatternsConfig.AnyGlobToAnyFile
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
core.debug(` "changed-files" matched`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug(` "any" patterns did not match any files`);
|
if (globPatternsConfig.AnyGlobToAllFiles) {
|
||||||
|
if (
|
||||||
|
checkIfAnyGlobMatchesAllFiles(
|
||||||
|
changedFiles,
|
||||||
|
globPatternsConfig.AnyGlobToAllFiles
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
core.debug(` "changed-files" matched`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (globPatternsConfig.AllGlobsToAnyFile) {
|
||||||
|
if (
|
||||||
|
checkIfAllGlobsMatchAnyFile(
|
||||||
|
changedFiles,
|
||||||
|
globPatternsConfig.AllGlobsToAnyFile
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
core.debug(` "changed-files" matched`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (globPatternsConfig.AllGlobsToAllFiles) {
|
||||||
|
if (
|
||||||
|
checkIfAllGlobsMatchAllFiles(
|
||||||
|
changedFiles,
|
||||||
|
globPatternsConfig.AllGlobsToAllFiles
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
core.debug(` "changed-files" matched`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
core.debug(` "changed-files" did not match`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function checkAllChangedFiles(
|
export function checkAllChangedFiles(
|
||||||
changedFiles: string[],
|
changedFiles: string[],
|
||||||
globs: string[]
|
globPatternsConfigs: ChangedFilesGlobPatternsConfig[]
|
||||||
): boolean {
|
): boolean {
|
||||||
const matchers = globs.map(g => new Minimatch(g));
|
core.debug(` checking "changed-files" patterns`);
|
||||||
for (const changedFile of changedFiles) {
|
|
||||||
if (!isAllMatch(changedFile, matchers)) {
|
for (const globPatternsConfig of globPatternsConfigs) {
|
||||||
core.debug(` "all" patterns did not match against ${changedFile}`);
|
if (globPatternsConfig.AnyGlobToAnyFile) {
|
||||||
|
if (
|
||||||
|
!checkIfAnyGlobMatchesAnyFile(
|
||||||
|
changedFiles,
|
||||||
|
globPatternsConfig.AnyGlobToAnyFile
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
core.debug(` "changed-files" did not match`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug(` "all" patterns matched all files`);
|
if (globPatternsConfig.AnyGlobToAllFiles) {
|
||||||
|
if (
|
||||||
|
!checkIfAnyGlobMatchesAllFiles(
|
||||||
|
changedFiles,
|
||||||
|
globPatternsConfig.AnyGlobToAllFiles
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
core.debug(` "changed-files" did not match`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (globPatternsConfig.AllGlobsToAnyFile) {
|
||||||
|
if (
|
||||||
|
!checkIfAllGlobsMatchAnyFile(
|
||||||
|
changedFiles,
|
||||||
|
globPatternsConfig.AllGlobsToAnyFile
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
core.debug(` "changed-files" did not match`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (globPatternsConfig.AllGlobsToAllFiles) {
|
||||||
|
if (
|
||||||
|
!checkIfAllGlobsMatchAllFiles(
|
||||||
|
changedFiles,
|
||||||
|
globPatternsConfig.AllGlobsToAllFiles
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
core.debug(` "changed-files" did not match`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
core.debug(` "changed-files" patterns matched`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function checkIfAnyGlobMatchesAnyFile(
|
||||||
|
changedFiles: string[],
|
||||||
|
globs: string[]
|
||||||
|
): boolean {
|
||||||
|
core.debug(` checking "AnyGlobToAnyFile" config patterns`);
|
||||||
|
const matchers = globs.map(g => new Minimatch(g));
|
||||||
|
|
||||||
|
for (const matcher of matchers) {
|
||||||
|
const matchedFile = changedFiles.find(changedFile => {
|
||||||
|
core.debug(
|
||||||
|
` checking "${printPattern(
|
||||||
|
matcher
|
||||||
|
)}" pattern against ${changedFile}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return matcher.match(changedFile);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (matchedFile) {
|
||||||
|
core.debug(
|
||||||
|
` "${printPattern(matcher)}" pattern matched ${matchedFile}`
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
core.debug(` none of the patterns matched any of the files`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function checkIfAllGlobsMatchAnyFile(
|
||||||
|
changedFiles: string[],
|
||||||
|
globs: string[]
|
||||||
|
): boolean {
|
||||||
|
core.debug(` checking "AllGlobsToAnyFile" config patterns`);
|
||||||
|
const matchers = globs.map(g => new Minimatch(g));
|
||||||
|
|
||||||
|
for (const changedFile of changedFiles) {
|
||||||
|
const mismatchedGlob = matchers.find(matcher => {
|
||||||
|
core.debug(
|
||||||
|
` checking "${printPattern(
|
||||||
|
matcher
|
||||||
|
)}" pattern against ${changedFile}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return !matcher.match(changedFile);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (mismatchedGlob) {
|
||||||
|
core.debug(
|
||||||
|
` "${printPattern(
|
||||||
|
mismatchedGlob
|
||||||
|
)}" pattern did not match ${changedFile}`
|
||||||
|
);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
core.debug(` all patterns matched ${changedFile}`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
core.debug(` none of the files matched all patterns`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function checkIfAnyGlobMatchesAllFiles(
|
||||||
|
changedFiles: string[],
|
||||||
|
globs: string[]
|
||||||
|
): boolean {
|
||||||
|
core.debug(` checking "AnyGlobToAllFiles" config patterns`);
|
||||||
|
const matchers = globs.map(g => new Minimatch(g));
|
||||||
|
|
||||||
|
for (const matcher of matchers) {
|
||||||
|
const mismatchedFile = changedFiles.find(changedFile => {
|
||||||
|
core.debug(
|
||||||
|
` checking "${printPattern(
|
||||||
|
matcher
|
||||||
|
)}" pattern against ${changedFile}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return !matcher.match(changedFile);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (mismatchedFile) {
|
||||||
|
core.debug(
|
||||||
|
` "${printPattern(
|
||||||
|
matcher
|
||||||
|
)}" pattern did not match ${mismatchedFile}`
|
||||||
|
);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
core.debug(` "${printPattern(matcher)}" pattern matched all files`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
core.debug(` none of the patterns matched all files`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function checkIfAllGlobsMatchAllFiles(
|
||||||
|
changedFiles: string[],
|
||||||
|
globs: string[]
|
||||||
|
): boolean {
|
||||||
|
core.debug(` checking "AllGlobsToAllFiles" config patterns`);
|
||||||
|
const matchers = globs.map(g => new Minimatch(g));
|
||||||
|
|
||||||
|
for (const changedFile of changedFiles) {
|
||||||
|
const mismatchedGlob = matchers.find(matcher => {
|
||||||
|
core.debug(
|
||||||
|
` checking "${printPattern(
|
||||||
|
matcher
|
||||||
|
)}" pattern against ${changedFile}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return !matcher.match(changedFile);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (mismatchedGlob) {
|
||||||
|
core.debug(
|
||||||
|
` "${printPattern(
|
||||||
|
mismatchedGlob
|
||||||
|
)}" pattern did not match ${changedFile}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
core.debug(` all patterns matched all files`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -236,18 +236,21 @@ export function checkAny(
|
|||||||
for (const matchConfig of matchConfigs) {
|
for (const matchConfig of matchConfigs) {
|
||||||
if (matchConfig.baseBranch) {
|
if (matchConfig.baseBranch) {
|
||||||
if (checkAnyBranch(matchConfig.baseBranch, 'base')) {
|
if (checkAnyBranch(matchConfig.baseBranch, 'base')) {
|
||||||
|
core.debug(` "any" patterns matched`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matchConfig.changedFiles) {
|
if (matchConfig.changedFiles) {
|
||||||
if (checkAnyChangedFiles(changedFiles, matchConfig.changedFiles)) {
|
if (checkAnyChangedFiles(changedFiles, matchConfig.changedFiles)) {
|
||||||
|
core.debug(` "any" patterns matched`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matchConfig.headBranch) {
|
if (matchConfig.headBranch) {
|
||||||
if (checkAnyBranch(matchConfig.headBranch, 'head')) {
|
if (checkAnyBranch(matchConfig.headBranch, 'head')) {
|
||||||
|
core.debug(` "any" patterns matched`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -274,6 +277,7 @@ export function checkAll(
|
|||||||
for (const matchConfig of matchConfigs) {
|
for (const matchConfig of matchConfigs) {
|
||||||
if (matchConfig.baseBranch) {
|
if (matchConfig.baseBranch) {
|
||||||
if (!checkAllBranch(matchConfig.baseBranch, 'base')) {
|
if (!checkAllBranch(matchConfig.baseBranch, 'base')) {
|
||||||
|
core.debug(` "all" patterns did not match`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -285,12 +289,14 @@ export function checkAll(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!checkAllChangedFiles(changedFiles, matchConfig.changedFiles)) {
|
if (!checkAllChangedFiles(changedFiles, matchConfig.changedFiles)) {
|
||||||
|
core.debug(` "all" patterns did not match`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matchConfig.headBranch) {
|
if (matchConfig.headBranch) {
|
||||||
if (!checkAllBranch(matchConfig.headBranch, 'head')) {
|
if (!checkAllBranch(matchConfig.headBranch, 'head')) {
|
||||||
|
core.debug(` "all" patterns did not match`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user