Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.

Commit b1a3bb4

Browse files
committed
Pass a query pattern
1 parent e6e9a21 commit b1a3bb4

File tree

5 files changed

+41
-19
lines changed

5 files changed

+41
-19
lines changed

README.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,18 @@ including links to the lines of source code on GitHub when possible:
2828
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
2929
**Table of Contents**
3030

31-
- [Creating your own course](#creating-your-own-course)
32-
- [Creating the Query Checking Action](#creating-the-query-checking-action)
33-
- [Testing the action](#testing-the-action)
34-
- [Adding new queries & calculating the contents for the CSV files](#adding-new-queries--calculating-the-contents-for-the-csv-files)
35-
- [Publishing your action](#publishing-your-action)
36-
- [Contributing your GitHub Action to this repository](#contributing-your-github-action-to-this-repository)
37-
- [Creating the Learning Lab Course](#creating-the-learning-lab-course)
38-
- [Example Courses](#example-courses)
39-
- [Contributing](#contributing)
40-
- [Releasing new versions or updating dependencies](#releasing-new-versions-or-updating-dependencies)
41-
- [License](#license)
31+
- [Actions for Learning Lab CodeQL Courses](#actions-for-learning-lab-codeql-courses)
32+
- [Creating your own course](#creating-your-own-course)
33+
- [Creating the Query Checking Action](#creating-the-query-checking-action)
34+
- [Testing the action](#testing-the-action)
35+
- [Adding new queries & calculating the contents for the CSV files](#adding-new-queries--calculating-the-contents-for-the-csv-files)
36+
- [Publishing your action](#publishing-your-action)
37+
- [Contributing your GitHub Action to this repository](#contributing-your-github-action-to-this-repository)
38+
- [Creating the Learning Lab Course](#creating-the-learning-lab-course)
39+
- [Example Courses](#example-courses)
40+
- [Contributing](#contributing)
41+
- [Releasing new versions or updating dependencies](#releasing-new-versions-or-updating-dependencies)
42+
- [License](#license)
4243

4344
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
4445

@@ -207,6 +208,11 @@ run either of these scripts:
207208
affect this specific course,
208209
without publishing any new images.
209210

211+
Both scripts take as argument an **optional** regexp string.
212+
If this string is passed, only the queries
213+
with names matching the regexp will be run.
214+
Otherwise all queries are run.
215+
210216
**In GitHub Actions:**
211217

212218
If adding a course to this repository,

codeql-learninglab-check/package/src/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ const readFile = promisify(fs.readFile);
1818
const writeFile = promisify(fs.writeFile);
1919

2020
/**
21-
* Must be "true" if all queries should be run (and not just changed queries)
21+
* RUN_ALL must be "true" if all queries should be run (and not just changed queries)
22+
* If specific queries should be run, RUN_ALL cannot be true
2223
*/
2324
const RUN_ALL = process.env.RUN_ALL === 'true';
25+
const QUERY_PATTERN: RegExp = RegExp(String(process.env.QUERY_PATTERN));
2426

2527
/**
2628
* Set to true to avoid using the GitHub API to post a comment
@@ -115,15 +117,16 @@ function isConfig(config: any): config is Config {
115117
}
116118

117119
/**
118-
* File paths changed by the user (if we're not just running all queries)
120+
* File paths changed by the user (if we're not just running all queries or a specific ones)
119121
*
120122
* This is used to reduce the number of queries we need to run to only those
121123
* that currently interest the user.
122124
*/
123125
const queriesChanged = new Set<string>();
124126
let unableToGetChangedQueries = false;
127+
let queryPattern = (process.env.QUERY_PATTERN!="");
125128

126-
if (!RUN_ALL) {
129+
if (!RUN_ALL && !queryPattern) {
127130

128131
/*
129132
* There are a few different ways in which we may determine which queries
@@ -274,7 +277,8 @@ function isConfig(config: any): config is Config {
274277
for (const query of Object.keys(config.expectedResults)) {
275278
const exists = await access(query, fs.constants.R_OK).then(() => true, () => false);
276279
// Run the query if either it's changed, or runAll is true
277-
if (exists && (RUN_ALL || unableToGetChangedQueries || queriesChanged.has(query))) {
280+
if (exists && (RUN_ALL || unableToGetChangedQueries || queriesChanged.has(query)) || (queryPattern && QUERY_PATTERN.test(query))) {
281+
console.log('query: ' + query + ' / RUN_ALL: ' + RUN_ALL + ' / unableToGetChangedQueries: ' + unableToGetChangedQueries + ' / regex test: ' + QUERY_PATTERN.test(query))
278282
queriesToRun.push(query);
279283
}
280284
}

scripts/test-course-actual.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
1616
docker pull $PARENT_TAG
1717

1818
# Run ./test-course-shared.sh
19-
$DIR/test-course-shared.sh
19+
$DIR/test-course-shared.sh $@

scripts/test-course-latest.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
1616
docker build -t $PARENT_TAG $DIR/../codeql-learninglab-check
1717

1818
# Run ./test-course-shared.sh
19-
$DIR/test-course-shared.sh
19+
$DIR/test-course-shared.sh $@

scripts/test-course-shared.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! /bin/bash
22

3-
# Build the course image, and run all queries in
3+
# Build the course image, and run all or specific queries in
44
# the course to ensure the expected result
55
#
66
# Should be run with the cwd being the course folder
@@ -19,12 +19,24 @@ mkdir -p $TMP
1919
cp -R answers $TMP/answers
2020
echo "{}" > $TMP/event.json
2121

22+
# Get query argument
23+
RUN_ALL=true
24+
QUERY_PATTERN=""
25+
if [ "$1" != "" ]; then
26+
RUN_ALL=false
27+
QUERY_PATTERN=$1
28+
echo "Running specific queries $QUERY_PATTERN"
29+
else
30+
echo "Running all queries"
31+
fi
32+
2233
# Run docker image
2334
docker run -i \
2435
-e GITHUB_EVENT_NAME=push \
2536
-e GITHUB_EVENT_PATH=/opt/tmp/event.json \
2637
-e GITHUB_TOKEN=noop \
27-
-e RUN_ALL=true \
38+
-e RUN_ALL=$RUN_ALL \
39+
-e QUERY_PATTERN=$QUERY_PATTERN \
2840
-e SKIP_COMMENT=true \
2941
-v $TMP:/opt/tmp:ro \
3042
-w /opt/tmp/answers \

0 commit comments

Comments
 (0)