Skip to content

Commit

Permalink
v4 (#5)
Browse files Browse the repository at this point in the history
* Support path exclusion
  • Loading branch information
carmocca committed Nov 13, 2022
1 parent 0320389 commit b074abe
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 63 deletions.
30 changes: 11 additions & 19 deletions dist/check-group/utils/subproj_matching.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,19 @@ var minimatch_1 = __importDefault(require("minimatch"));
var matchFilenamesToSubprojects = function (filenames, subprojConfigs) {
var matchingSubProjs = [];
subprojConfigs.forEach(function (subproj) {
var hasMatching = false;
var updatedSubProj = subproj;
var updatedPaths = [];
var hits = new Set();
subproj.paths.forEach(function (path) {
var updatedPath = path;
if (!updatedPath.matches) {
updatedPath.matches = [];
}
filenames.forEach(function (filename) {
if ((0, minimatch_1.default)(filename, path.location)) {
hasMatching = true;
updatedPath.hit = true;
if (updatedPath.matches) {
updatedPath.matches.push(filename);
}
}
});
updatedPaths.push(updatedPath);
// support for GitHub-style path exclusion
// https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-including-and-excluding-paths
var isNegation = path.startsWith("!");
// https://www.npmjs.com/package/minimatch
var matches = minimatch_1.default.match(filenames, path, { "flipNegate": isNegation });
// if it's a negation, delete from the list of hits, otherwise add
matches.forEach(function (match) { return (isNegation) ? hits.delete(match) : hits.add(match); });
});
if (hasMatching) {
updatedSubProj.paths = updatedPaths;
if (hits.size) {
var updatedSubProj = subproj;
updatedSubProj.paths = Array.from(hits);
matchingSubProjs.push(updatedSubProj);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@ function parseProjectPaths(subprojData) {
if (!("paths" in subprojData) || subprojData["paths"] == null) {
core.setFailed("The list of paths for the '".concat(subprojData["id"], "' group is not defined"));
}
var projPaths = [];
var locations = subprojData["paths"];
locations.forEach(function (loc) {
projPaths.push({
location: loc,
});
});
var projPaths = subprojData["paths"];
if (projPaths.length == 0) {
core.setFailed("The list of paths for the '".concat(subprojData["id"], "' group is empty"));
}
Expand Down
8 changes: 1 addition & 7 deletions src/check-group/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ export interface ProgressReport {
succeeded?: string[];
}

export interface SubProjPath {
location: string;
hit?: boolean;
matches?: string[];
}

export interface SubProjCheck {
/**
* The ID of the check which should
Expand Down Expand Up @@ -53,7 +47,7 @@ export interface SubProjConfig {
* this sub-project within
* the repository.
*/
paths: SubProjPath[];
paths: string[];
/**
* A list of check IDs that
* are expected to pass for
Expand Down
34 changes: 13 additions & 21 deletions src/check-group/utils/subproj_matching.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { SubProjConfig, SubProjPath } from "../types";
import { SubProjConfig } from "../types";
/* eslint-enable @typescript-eslint/no-unused-vars */
import minimatch from "minimatch";

Expand All @@ -15,27 +15,19 @@ export const matchFilenamesToSubprojects = (
): SubProjConfig[] => {
const matchingSubProjs: SubProjConfig[] = [];
subprojConfigs.forEach((subproj) => {
let hasMatching = false;
const updatedSubProj = subproj;
const updatedPaths: SubProjPath[] = [];
subproj.paths.forEach((path) => {
const updatedPath = path;
if (!updatedPath.matches) {
updatedPath.matches = [];
}
filenames.forEach((filename) => {
if (minimatch(filename, path.location)) {
hasMatching = true;
updatedPath.hit = true;
if (updatedPath.matches) {
updatedPath.matches.push(filename);
}
}
});
updatedPaths.push(updatedPath);
const hits: Set<string> = new Set();
subproj.paths.forEach((path: string) => {
// support for GitHub-style path exclusion
// https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-including-and-excluding-paths
const isNegation = path.startsWith("!")
// https://www.npmjs.com/package/minimatch
const matches = minimatch.match(filenames, path, {"flipNegate": isNegation})
// if it's a negation, delete from the list of hits, otherwise add
matches.forEach((match: string) => (isNegation) ? hits.delete(match): hits.add(match))
});
if (hasMatching) {
updatedSubProj.paths = updatedPaths;
if (hits.size) {
const updatedSubProj = subproj;
updatedSubProj.paths = Array.from(hits);
matchingSubProjs.push(updatedSubProj);
}
});
Expand Down
11 changes: 2 additions & 9 deletions src/check-group/utils/user_config_parser/populate_subprojects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
CheckGroupConfig,
SubProjCheck,
SubProjConfig,
SubProjPath,
} from "../../types";
import * as core from '@actions/core'

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

export function parseProjectPaths(subprojData: Record<string, unknown>): SubProjPath[] {
export function parseProjectPaths(subprojData: Record<string, unknown>): string[] {
if (!("paths" in subprojData) || subprojData["paths"] == null) {
core.setFailed(`The list of paths for the '${subprojData["id"]}' group is not defined`);
}
const projPaths: SubProjPath[] = [];
const locations: string[] = subprojData["paths"] as string[];
locations.forEach((loc) => {
projPaths.push({
location: loc,
});
});
const projPaths: string[] = subprojData["paths"] as string[];
if (projPaths.length == 0) {
core.setFailed(`The list of paths for the '${subprojData["id"]}' group is empty`);
}
Expand Down

0 comments on commit b074abe

Please sign in to comment.