Skip to content
This repository was archived by the owner on Aug 28, 2025. It is now read-only.

Commit 9ac73a5

Browse files
committed
Merge branch 'master' into feat/v4
2 parents 1392461 + b074abe commit 9ac73a5

File tree

5 files changed

+28
-63
lines changed

5 files changed

+28
-63
lines changed

dist/check-group/core/subproj_matching.js

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,19 @@ var minimatch_1 = __importDefault(require("minimatch"));
1515
var matchFilenamesToSubprojects = function (filenames, subprojConfigs) {
1616
var matchingSubProjs = [];
1717
subprojConfigs.forEach(function (subproj) {
18-
var hasMatching = false;
19-
var updatedSubProj = subproj;
20-
var updatedPaths = [];
18+
var hits = new Set();
2119
subproj.paths.forEach(function (path) {
22-
var updatedPath = path;
23-
if (!updatedPath.matches) {
24-
updatedPath.matches = [];
25-
}
26-
filenames.forEach(function (filename) {
27-
if ((0, minimatch_1.default)(filename, path.location)) {
28-
hasMatching = true;
29-
updatedPath.hit = true;
30-
if (updatedPath.matches) {
31-
updatedPath.matches.push(filename);
32-
}
33-
}
34-
});
35-
updatedPaths.push(updatedPath);
20+
// support for GitHub-style path exclusion
21+
// https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-including-and-excluding-paths
22+
var isNegation = path.startsWith("!");
23+
// https://www.npmjs.com/package/minimatch
24+
var matches = minimatch_1.default.match(filenames, path, { "flipNegate": isNegation });
25+
// if it's a negation, delete from the list of hits, otherwise add
26+
matches.forEach(function (match) { return (isNegation) ? hits.delete(match) : hits.add(match); });
3627
});
37-
if (hasMatching) {
38-
updatedSubProj.paths = updatedPaths;
28+
if (hits.size) {
29+
var updatedSubProj = subproj;
30+
updatedSubProj.paths = Array.from(hits);
3931
matchingSubProjs.push(updatedSubProj);
4032
}
4133
});

dist/check-group/core/user_config_parser/populate_subprojects.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,7 @@ function parseProjectPaths(subprojData) {
3939
if (!("paths" in subprojData) || subprojData["paths"] == null) {
4040
core.setFailed("The list of paths for the '".concat(subprojData["id"], "' group is not defined"));
4141
}
42-
var projPaths = [];
43-
var locations = subprojData["paths"];
44-
locations.forEach(function (loc) {
45-
projPaths.push({
46-
location: loc,
47-
});
48-
});
42+
var projPaths = subprojData["paths"];
4943
if (projPaths.length == 0) {
5044
core.setFailed("The list of paths for the '".concat(subprojData["id"], "' group is empty"));
5145
}

src/check-group/core/subproj_matching.ts

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-unused-vars */
2-
import { SubProjConfig, SubProjPath } from "../types";
2+
import { SubProjConfig } from "../types";
33
/* eslint-enable @typescript-eslint/no-unused-vars */
44
import minimatch from "minimatch";
55

@@ -15,27 +15,19 @@ export const matchFilenamesToSubprojects = (
1515
): SubProjConfig[] => {
1616
const matchingSubProjs: SubProjConfig[] = [];
1717
subprojConfigs.forEach((subproj) => {
18-
let hasMatching = false;
19-
const updatedSubProj = subproj;
20-
const updatedPaths: SubProjPath[] = [];
21-
subproj.paths.forEach((path) => {
22-
const updatedPath = path;
23-
if (!updatedPath.matches) {
24-
updatedPath.matches = [];
25-
}
26-
filenames.forEach((filename) => {
27-
if (minimatch(filename, path.location)) {
28-
hasMatching = true;
29-
updatedPath.hit = true;
30-
if (updatedPath.matches) {
31-
updatedPath.matches.push(filename);
32-
}
33-
}
34-
});
35-
updatedPaths.push(updatedPath);
18+
const hits: Set<string> = new Set();
19+
subproj.paths.forEach((path: string) => {
20+
// support for GitHub-style path exclusion
21+
// https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-including-and-excluding-paths
22+
const isNegation = path.startsWith("!")
23+
// https://www.npmjs.com/package/minimatch
24+
const matches = minimatch.match(filenames, path, {"flipNegate": isNegation})
25+
// if it's a negation, delete from the list of hits, otherwise add
26+
matches.forEach((match: string) => (isNegation) ? hits.delete(match): hits.add(match))
3627
});
37-
if (hasMatching) {
38-
updatedSubProj.paths = updatedPaths;
28+
if (hits.size) {
29+
const updatedSubProj = subproj;
30+
updatedSubProj.paths = Array.from(hits);
3931
matchingSubProjs.push(updatedSubProj);
4032
}
4133
});

src/check-group/core/user_config_parser/populate_subprojects.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
CheckGroupConfig,
77
SubProjCheck,
88
SubProjConfig,
9-
SubProjPath,
109
} from "../../types";
1110
import * as core from '@actions/core'
1211

@@ -17,17 +16,11 @@ export function parseProjectId(subprojData: Record<string, unknown>): string {
1716
return subprojData["id"] as string;
1817
}
1918

20-
export function parseProjectPaths(subprojData: Record<string, unknown>): SubProjPath[] {
19+
export function parseProjectPaths(subprojData: Record<string, unknown>): string[] {
2120
if (!("paths" in subprojData) || subprojData["paths"] == null) {
2221
core.setFailed(`The list of paths for the '${subprojData["id"]}' group is not defined`);
2322
}
24-
const projPaths: SubProjPath[] = [];
25-
const locations: string[] = subprojData["paths"] as string[];
26-
locations.forEach((loc) => {
27-
projPaths.push({
28-
location: loc,
29-
});
30-
});
23+
const projPaths: string[] = subprojData["paths"] as string[];
3124
if (projPaths.length == 0) {
3225
core.setFailed(`The list of paths for the '${subprojData["id"]}' group is empty`);
3326
}

src/check-group/types.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ export interface ProgressReport {
1818
succeeded?: string[];
1919
}
2020

21-
export interface SubProjPath {
22-
location: string;
23-
hit?: boolean;
24-
matches?: string[];
25-
}
26-
2721
export interface SubProjCheck {
2822
/**
2923
* The ID of the check which should
@@ -53,7 +47,7 @@ export interface SubProjConfig {
5347
* this sub-project within
5448
* the repository.
5549
*/
56-
paths: SubProjPath[];
50+
paths: string[];
5751
/**
5852
* A list of check IDs that
5953
* are expected to pass for

0 commit comments

Comments
 (0)