Skip to content

Commit

Permalink
feat(github-actions): google-internal-tests action should support g3-…
Browse files Browse the repository at this point in the history
…sync configuration file
  • Loading branch information
devversion committed Oct 15, 2022
1 parent 03c8a7b commit 299eae4
Show file tree
Hide file tree
Showing 4 changed files with 8,049 additions and 5,889 deletions.
17 changes: 3 additions & 14 deletions github-actions/google-internal-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,11 @@ inputs:
github-token:
required: true
description: GitHub Token used for creating the commit statuses.
synced-files:
sync-config:
required: true
description: |
List of file patterns which match files synced into Google. May
be overridden below with the `always-external-files` option.
Multiple patterns should be separated by new lines. Comments using `#`
are supported.
always-external-files:
required: false
description: |
List of file patterns which are always considered external to Google.
Can be used to override files initially matched in `synced-files`.
Multiple patterns should be separated by new lines. Comments using `#`
are supported.
Path to the Google Sync configuration, following the `ng-dev`
`GoogleSyncConfig` interface used in `ng-dev caretaker check`.
run-tests-guide-url:
required: false
description: |
Expand Down
4 changes: 2 additions & 2 deletions github-actions/google-internal-tests/lib/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ ts_library(
name = "lib",
srcs = glob(["*.ts"]),
deps = [
"//ng-dev/caretaker:g3_sync_config",
"@npm//@actions/core",
"@npm//@actions/github",
"@npm//@octokit/rest",
"@npm//@types/minimatch",
"@npm//minimatch",
"@npm//@types/node",
],
)
30 changes: 5 additions & 25 deletions github-actions/google-internal-tests/lib/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as core from '@actions/core';
import {context} from '@actions/github';
import {Octokit, RestEndpointMethodTypes} from '@octokit/rest';
import minimatch from 'minimatch';
import {readConfigFile} from '../../../ng-dev/caretaker/g3-sync-config.js';
import path from 'path';

const syncBranch = 'main';
const statusContext = 'google-internal-tests';
Expand All @@ -23,8 +24,8 @@ async function main() {

const githubToken = core.getInput('github-token', {required: true});
const runTestGuideURL = core.getInput('run-tests-guide-url', {required: false});
const syncedFilesRaw = core.getInput('synced-files', {required: true});
const alwaysExternalFilesRaw = core.getInput('always-external-files', {required: false});
const syncConfigPath = path.resolve(core.getInput('sync-config', {required: true}));
const syncConfig = await readConfigFile(syncConfigPath);

const prNum = context.payload.pull_request!.number;
const prHeadSHA = context.payload.pull_request!.head!.sha;
Expand All @@ -35,9 +36,6 @@ async function main() {
return;
}

const syncedFiles = constructPatterns(syncedFilesRaw);
const alwaysExternalFiles = constructPatterns(alwaysExternalFilesRaw);

const github = new Octokit({auth: githubToken});
const existingGoogleStatus = await findExistingTestStatus(github, prHeadSHA);

Expand All @@ -54,11 +52,7 @@ async function main() {

let affectsGoogle = false;
for (const f of files) {
// Perf: Skip matching the external file patterns if the file is not even synced.
const isSynced = syncedFiles.some((p) => p.match(f.filename));
const isExcluded = !isSynced || alwaysExternalFiles.some((p) => p.match(f.filename));

if (isSynced && !isExcluded) {
if (syncConfig.matchFn(f.filename)) {
affectsGoogle = true;
break;
}
Expand Down Expand Up @@ -86,20 +80,6 @@ async function main() {
});
}

function constructPatterns(rawPatterns: string): minimatch.IMinimatch[] {
const patterns: minimatch.IMinimatch[] = [];
for (let p of rawPatterns.split(/\r?\n/g)) {
p = p.trim();
// Support comments, lines starting with a hashtag.
if (p.startsWith('#')) {
continue;
} else if (p !== '') {
patterns.push(new minimatch.Minimatch(p));
}
}
return patterns;
}

async function findExistingTestStatus(
github: Octokit,
prHeadSHA: string,
Expand Down
Loading

0 comments on commit 299eae4

Please sign in to comment.