Pass a query pattern
This commit is contained in:
Родитель
e6e9a21413
Коммит
b1a3bb4455
|
@ -28,6 +28,7 @@ including links to the lines of source code on GitHub when possible:
|
|||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
||||
**Table of Contents**
|
||||
|
||||
- [Actions for Learning Lab CodeQL Courses](#actions-for-learning-lab-codeql-courses)
|
||||
- [Creating your own course](#creating-your-own-course)
|
||||
- [Creating the Query Checking Action](#creating-the-query-checking-action)
|
||||
- [Testing the action](#testing-the-action)
|
||||
|
@ -207,6 +208,11 @@ run either of these scripts:
|
|||
affect this specific course,
|
||||
without publishing any new images.
|
||||
|
||||
Both scripts take as argument an **optional** regexp string.
|
||||
If this string is passed, only the queries
|
||||
with names matching the regexp will be run.
|
||||
Otherwise all queries are run.
|
||||
|
||||
**In GitHub Actions:**
|
||||
|
||||
If adding a course to this repository,
|
||||
|
|
|
@ -18,9 +18,11 @@ const readFile = promisify(fs.readFile);
|
|||
const writeFile = promisify(fs.writeFile);
|
||||
|
||||
/**
|
||||
* Must be "true" if all queries should be run (and not just changed queries)
|
||||
* RUN_ALL must be "true" if all queries should be run (and not just changed queries)
|
||||
* If specific queries should be run, RUN_ALL cannot be true
|
||||
*/
|
||||
const RUN_ALL = process.env.RUN_ALL === 'true';
|
||||
const QUERY_PATTERN: RegExp = RegExp(String(process.env.QUERY_PATTERN));
|
||||
|
||||
/**
|
||||
* Set to true to avoid using the GitHub API to post a comment
|
||||
|
@ -115,15 +117,16 @@ function isConfig(config: any): config is Config {
|
|||
}
|
||||
|
||||
/**
|
||||
* File paths changed by the user (if we're not just running all queries)
|
||||
* File paths changed by the user (if we're not just running all queries or a specific ones)
|
||||
*
|
||||
* This is used to reduce the number of queries we need to run to only those
|
||||
* that currently interest the user.
|
||||
*/
|
||||
const queriesChanged = new Set<string>();
|
||||
let unableToGetChangedQueries = false;
|
||||
let queryPattern = (process.env.QUERY_PATTERN!="");
|
||||
|
||||
if (!RUN_ALL) {
|
||||
if (!RUN_ALL && !queryPattern) {
|
||||
|
||||
/*
|
||||
* There are a few different ways in which we may determine which queries
|
||||
|
@ -274,7 +277,8 @@ function isConfig(config: any): config is Config {
|
|||
for (const query of Object.keys(config.expectedResults)) {
|
||||
const exists = await access(query, fs.constants.R_OK).then(() => true, () => false);
|
||||
// Run the query if either it's changed, or runAll is true
|
||||
if (exists && (RUN_ALL || unableToGetChangedQueries || queriesChanged.has(query))) {
|
||||
if (exists && (RUN_ALL || unableToGetChangedQueries || queriesChanged.has(query)) || (queryPattern && QUERY_PATTERN.test(query))) {
|
||||
console.log('query: ' + query + ' / RUN_ALL: ' + RUN_ALL + ' / unableToGetChangedQueries: ' + unableToGetChangedQueries + ' / regex test: ' + QUERY_PATTERN.test(query))
|
||||
queriesToRun.push(query);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,4 +16,4 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
|||
docker pull $PARENT_TAG
|
||||
|
||||
# Run ./test-course-shared.sh
|
||||
$DIR/test-course-shared.sh
|
||||
$DIR/test-course-shared.sh $@
|
||||
|
|
|
@ -16,4 +16,4 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
|||
docker build -t $PARENT_TAG $DIR/../codeql-learninglab-check
|
||||
|
||||
# Run ./test-course-shared.sh
|
||||
$DIR/test-course-shared.sh
|
||||
$DIR/test-course-shared.sh $@
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#! /bin/bash
|
||||
|
||||
# Build the course image, and run all queries in
|
||||
# Build the course image, and run all or specific queries in
|
||||
# the course to ensure the expected result
|
||||
#
|
||||
# Should be run with the cwd being the course folder
|
||||
|
@ -19,12 +19,24 @@ mkdir -p $TMP
|
|||
cp -R answers $TMP/answers
|
||||
echo "{}" > $TMP/event.json
|
||||
|
||||
# Get query argument
|
||||
RUN_ALL=true
|
||||
QUERY_PATTERN=""
|
||||
if [ "$1" != "" ]; then
|
||||
RUN_ALL=false
|
||||
QUERY_PATTERN=$1
|
||||
echo "Running specific queries $QUERY_PATTERN"
|
||||
else
|
||||
echo "Running all queries"
|
||||
fi
|
||||
|
||||
# Run docker image
|
||||
docker run -i \
|
||||
-e GITHUB_EVENT_NAME=push \
|
||||
-e GITHUB_EVENT_PATH=/opt/tmp/event.json \
|
||||
-e GITHUB_TOKEN=noop \
|
||||
-e RUN_ALL=true \
|
||||
-e RUN_ALL=$RUN_ALL \
|
||||
-e QUERY_PATTERN=$QUERY_PATTERN \
|
||||
-e SKIP_COMMENT=true \
|
||||
-v $TMP:/opt/tmp:ro \
|
||||
-w /opt/tmp/answers \
|
||||
|
|
Загрузка…
Ссылка в новой задаче