Compare commits

...

51 Commits

Author SHA1 Message Date
Edoardo Pirovano cbabe47a0b Merge pull request #871 from github/mergeback/v1.0.27-to-main-cd783c8a
Mergeback v1.0.27 refs/heads/v1 into main
2022-01-11 22:22:02 +00:00
github-actions[bot] f8a48f464d Update checked-in dependencies 2022-01-11 21:57:25 +00:00
github-actions[bot] f6f23f8671 1.0.28 2022-01-11 21:43:35 +00:00
github-actions[bot] c2a7379048 Update changelog and version after v1.0.27 2022-01-11 21:43:33 +00:00
Edoardo Pirovano cd783c8a29 Merge pull request #870 from github/update-v1.0.27-faa9ba73
Merge main into v1
2022-01-11 21:42:44 +00:00
github-actions[bot] 300c8b6dcb 1.0.27 2022-01-11 20:35:30 +00:00
Edoardo Pirovano faa9ba7363 Merge pull request #869 from github/edoardo/windows-11-error
Refuse to run on Windows 11
2022-01-11 20:34:11 +00:00
Edoardo Pirovano d2a0fc83dc Refuse to run on Windows 11 2022-01-11 18:34:33 +00:00
Edoardo Pirovano 71112ab35d Merge pull request #868 from edoardopirovano/debug-artifact-name
Make name of debugging artifact and DB within it configurable
2022-01-07 17:54:41 +00:00
Edoardo Pirovano e677af3fd0 Make name of debugging artifact and DB within it configurable 2022-01-07 15:10:26 +00:00
Henry Mercer 848e5140d4 Merge pull request #857 from github/henrymercer/ml-powered-queries
Add support for running ML-powered queries for JS `security-extended` behind `ml_powered_queries` feature flag
2022-01-06 17:55:06 +00:00
Henry Mercer e7fe6da378 Allow patch version of ML-powered queries pack to be bumped 2022-01-06 11:58:03 +00:00
Henry Mercer 2159631658 Only run ML-powered queries with v2.7.5 or newer of the CLI 2022-01-06 11:58:03 +00:00
Henry Mercer 9de1702400 Document use of redundant feature flag API call 2022-01-06 11:58:02 +00:00
Henry Mercer efded22908 Bump the version of the ATM query pack to 0.0.2 2022-01-06 11:57:33 +00:00
Henry Mercer 5602bd50bf Test loading of ML-powered queries 2022-01-06 11:57:33 +00:00
Henry Mercer 2f4be8e34b Run ML-powered queries for JS security-extended behind feature flag 2022-01-06 11:57:33 +00:00
Edoardo Pirovano 9763bdd6ec Merge pull request #860 from edoardopirovano/always-upload-db
Always upload DB when in debug mode
2022-01-04 18:25:33 +00:00
Edoardo Pirovano 00d4d60204 Always upload DB when in debug mode 2022-01-04 16:49:31 +00:00
Edoardo Pirovano e5d84de18b Merge pull request #861 from github/remove-debug-output
Remove debugging output
2022-01-02 10:05:46 +00:00
Edoardo Pirovano ea1acc573a Merge branch 'main' into remove-debug-output 2022-01-02 09:41:49 +00:00
Edoardo Pirovano 79ea6d6a7c Merge pull request #862 from github/aeisenberg/fix-python-tests
Force virtualenv version
2022-01-02 09:41:38 +00:00
Andrew Eisenberg 3e50d096f8 Force virtualenv version
Force the virtualenv version to be 20.11 or less.
The 20.12 version is failing for python 2 right now.
2022-01-01 19:13:10 -08:00
Edoardo Pirovano cca1cfdacf Remove debugging output 2021-12-31 16:32:08 +00:00
Edoardo Pirovano cdea582765 Merge pull request #859 from github/update-supported-enterprise-server-versions
Update supported GitHub Enterprise Server versions.
2021-12-29 09:39:28 +00:00
GitHub 3e59dee9e2 Update supported GitHub Enterprise Server versions. 2021-12-29 00:07:19 +00:00
Henry Mercer 249c7ffce1 Merge pull request #856 from github/henrymercer/feature-flagging
Feature flagging via the GitHub API
2021-12-16 16:18:46 +00:00
Henry Mercer 254816c2d2 Stub feature flag API endpoint in tests 2021-12-16 13:39:18 +00:00
Henry Mercer 6d62c245ec Represent feature flags using an enum
Replaces the previous string literal type
2021-12-16 13:38:34 +00:00
Henry Mercer 5e87034b3b Explicitly pass repository to feature flags constructor
As suggested in review: The `GITHUB_REPOSITORY` environment variable is
only available on Actions. Passing it in explicitly avoids potentially
crashing if this code is called from the runner.
2021-12-15 17:03:43 +00:00
Henry Mercer 621e0794ac Throw an error if the feature flag API request errors 2021-12-15 16:34:26 +00:00
Henry Mercer d6499fad61 Use new feature flag architecture when uploading databases 2021-12-15 13:17:05 +00:00
Henry Mercer 04671efa1d Add support for feature flagging via the GitHub API 2021-12-15 13:16:33 +00:00
Andrew Eisenberg e1f05902cd Merge pull request #855 from github/correct-changelog
Move changelog entry into correct place
2021-12-14 11:06:40 -08:00
Thomas Horstmeyer f9e96fa857 Move changelog entry into correct place 2021-12-14 13:49:52 +00:00
Andrew Eisenberg 14a5537e13 Merge pull request #853 from github/aeisenberg/remove-scheduled
Remove scheduled releases
2021-12-13 19:14:37 -08:00
Andrew Eisenberg d3eb4974a3 Merge branch 'main' into aeisenberg/remove-scheduled 2021-12-13 18:37:38 -08:00
Edoardo Pirovano 39216d10d3 Merge pull request #854 from edoardopirovano/remove-dotnet-restore
Remove `dotnet restore` calls from CI checks
2021-12-13 23:29:58 +00:00
Edoardo Pirovano 265a7db16a Remove dotnet restore calls from CI checks 2021-12-13 18:04:46 +00:00
Andrew Eisenberg f623d4cec3 Remove scheduled releases
The action will be released roughly every two weeks along
with the CodeQL CLI release process.
2021-12-13 09:34:53 -08:00
Chris Gavin eacec3646a Merge pull request #843 from github/wait-for-processing-by-default
Start waiting for processing by default.
2021-12-13 12:19:11 +00:00
Chris Gavin e0e2abc1a5 Merge branch 'main' into wait-for-processing-by-default 2021-12-13 12:04:22 +00:00
Chris Gavin 716b5980cd Merge pull request #844 from github/duplicated-output
Stop printing all output twice.
2021-12-13 11:57:11 +00:00
Chris Gavin 1d83f2a0bc Merge branch 'main' into duplicated-output 2021-12-13 11:44:22 +00:00
Andrew Eisenberg ce77f88627 Merge pull request #849 from github/mergeback/v1.0.26-to-main-5f532563
Mergeback v1.0.26 refs/heads/v1 into main
2021-12-10 13:41:53 -08:00
github-actions[bot] a777b51ef7 Update checked-in dependencies 2021-12-10 19:09:21 +00:00
github-actions[bot] 88fbabe21d 1.0.27 2021-12-10 18:40:13 +00:00
github-actions[bot] eeb215b041 Update changelog and version after v1.0.26 2021-12-10 18:40:11 +00:00
Chris Gavin b7b7607959 Stop printing all output twice. 2021-12-09 13:21:32 +00:00
Chris Gavin 7bcc6564d4 Add more context to a change note.
Co-authored-by: Thomas Horstmeyer <73262256+cannist@users.noreply.github.com>
2021-12-09 12:53:20 +00:00
Chris Gavin b661ef1697 Start waiting for processing by default. 2021-12-09 10:21:34 +00:00
93 changed files with 1285 additions and 439 deletions
-1
View File
@@ -28,7 +28,6 @@ runs:
echo "::set-output name=tools-url::https://github.com/dsp-testing/codeql-cli-nightlies/releases/download/codeql-bundle-$VERSION-manual/codeql-bundle.tar.gz" echo "::set-output name=tools-url::https://github.com/dsp-testing/codeql-cli-nightlies/releases/download/codeql-bundle-$VERSION-manual/codeql-bundle.tar.gz"
elif [[ ${{ inputs.version }} == *"stable"* ]]; then elif [[ ${{ inputs.version }} == *"stable"* ]]; then
export VERSION=`echo ${{ inputs.version }} | sed -e 's/^.*\-//'` export VERSION=`echo ${{ inputs.version }} | sed -e 's/^.*\-//'`
echo "Hello $VERSION"
echo "::set-output name=tools-url::https://github.com/github/codeql-action/releases/download/codeql-bundle-$VERSION/codeql-bundle.tar.gz" echo "::set-output name=tools-url::https://github.com/github/codeql-action/releases/download/codeql-bundle-$VERSION/codeql-bundle.tar.gz"
elif [[ ${{ inputs.version }} == "latest" ]]; then elif [[ ${{ inputs.version }} == "latest" ]]; then
echo "::set-output name=tools-url::latest" echo "::set-output name=tools-url::latest"
+4 -4
View File
@@ -41,12 +41,12 @@ jobs:
uses: ./.github/prepare-test uses: ./.github/prepare-test
with: with:
version: ${{ matrix.version }} version: ${{ matrix.version }}
- name: Initialize dotnet
run: dotnet restore
- uses: ./../action/init - uses: ./../action/init
with: with:
tools: ${{ steps.prepare-test.outputs.tools-url }} tools: ${{ steps.prepare-test.outputs.tools-url }}
debug: true debug: true
debug-artifact-name: my-debug-artifacts
debug-database-name: my-db
- name: Build code - name: Build code
shell: bash shell: bash
run: ./build.sh run: ./build.sh
@@ -54,7 +54,7 @@ jobs:
id: analysis id: analysis
- uses: actions/download-artifact@v2 - uses: actions/download-artifact@v2
with: with:
name: debug-artifacts-${{ matrix.os }}-${{ matrix.version }} name: my-debug-artifacts-${{ matrix.os }}-${{ matrix.version }}
- shell: bash - shell: bash
run: | run: |
LANGUAGES="cpp csharp go java javascript python" LANGUAGES="cpp csharp go java javascript python"
@@ -64,7 +64,7 @@ jobs:
echo "Missing a SARIF file for $language" echo "Missing a SARIF file for $language"
exit 1 exit 1
fi fi
if [[ ! -f "$language.zip" ]] ; then if [[ ! -f "my-db-$language.zip" ]] ; then
echo "Missing a database bundle for $language" echo "Missing a database bundle for $language"
exit 1 exit 1
fi fi
-2
View File
@@ -44,8 +44,6 @@ jobs:
uses: ./.github/prepare-test uses: ./.github/prepare-test
with: with:
version: ${{ matrix.version }} version: ${{ matrix.version }}
- name: Initialize dotnet
run: dotnet restore
- uses: actions/setup-go@v2 - uses: actions/setup-go@v2
with: with:
go-version: ^1.13.1 go-version: ^1.13.1
-2
View File
@@ -41,8 +41,6 @@ jobs:
uses: ./.github/prepare-test uses: ./.github/prepare-test
with: with:
version: ${{ matrix.version }} version: ${{ matrix.version }}
- name: Initialize dotnet
run: dotnet restore
- uses: ./../action/init - uses: ./../action/init
with: with:
db-location: ${{ runner.temp }}/customDbLocation db-location: ${{ runner.temp }}/customDbLocation
-2
View File
@@ -35,8 +35,6 @@ jobs:
uses: ./.github/prepare-test uses: ./.github/prepare-test
with: with:
version: ${{ matrix.version }} version: ${{ matrix.version }}
- name: Initialize dotnet
run: dotnet restore
- uses: ./../action/init - uses: ./../action/init
with: with:
config-file: .github/codeql/codeql-config-packaging3.yml config-file: .github/codeql/codeql-config-packaging3.yml
-2
View File
@@ -35,8 +35,6 @@ jobs:
uses: ./.github/prepare-test uses: ./.github/prepare-test
with: with:
version: ${{ matrix.version }} version: ${{ matrix.version }}
- name: Initialize dotnet
run: dotnet restore
- uses: ./../action/init - uses: ./../action/init
with: with:
config-file: .github/codeql/codeql-config-packaging.yml config-file: .github/codeql/codeql-config-packaging.yml
-2
View File
@@ -35,8 +35,6 @@ jobs:
uses: ./.github/prepare-test uses: ./.github/prepare-test
with: with:
version: ${{ matrix.version }} version: ${{ matrix.version }}
- name: Initialize dotnet
run: dotnet restore
- uses: ./../action/init - uses: ./../action/init
with: with:
config-file: .github/codeql/codeql-config-packaging2.yml config-file: .github/codeql/codeql-config-packaging2.yml
-2
View File
@@ -44,8 +44,6 @@ jobs:
uses: ./.github/prepare-test uses: ./.github/prepare-test
with: with:
version: ${{ matrix.version }} version: ${{ matrix.version }}
- name: Initialize dotnet
run: dotnet restore
- uses: ./../action/init - uses: ./../action/init
with: with:
tools: ${{ steps.prepare-test.outputs.tools-url }} tools: ${{ steps.prepare-test.outputs.tools-url }}
-2
View File
@@ -35,8 +35,6 @@ jobs:
uses: ./.github/prepare-test uses: ./.github/prepare-test
with: with:
version: ${{ matrix.version }} version: ${{ matrix.version }}
- name: Initialize dotnet
run: dotnet restore
- uses: ./../action/init - uses: ./../action/init
with: with:
config-file: .github/codeql/codeql-config-packaging3.yml config-file: .github/codeql/codeql-config-packaging3.yml
-2
View File
@@ -35,8 +35,6 @@ jobs:
uses: ./.github/prepare-test uses: ./.github/prepare-test
with: with:
version: ${{ matrix.version }} version: ${{ matrix.version }}
- name: Initialize dotnet
run: dotnet restore
- name: Fetch a CodeQL bundle - name: Fetch a CodeQL bundle
shell: bash shell: bash
env: env:
-2
View File
@@ -41,8 +41,6 @@ jobs:
uses: ./.github/prepare-test uses: ./.github/prepare-test
with: with:
version: ${{ matrix.version }} version: ${{ matrix.version }}
- name: Initialize dotnet
run: dotnet restore
- uses: ./../action/init - uses: ./../action/init
with: with:
db-location: ${{ runner.temp }}/customDbLocation db-location: ${{ runner.temp }}/customDbLocation
-9
View File
@@ -164,9 +164,6 @@ jobs:
npm install npm install
npm run build-runner npm run build-runner
- name: Initialize dotnet
run: dotnet restore
- name: Run init - name: Run init
run: | run: |
../action/runner/dist/codeql-runner-linux init --repository $GITHUB_REPOSITORY --languages csharp --github-url $GITHUB_SERVER_URL --github-auth ${{ github.token }} ../action/runner/dist/codeql-runner-linux init --repository $GITHUB_REPOSITORY --languages csharp --github-url $GITHUB_SERVER_URL --github-auth ${{ github.token }}
@@ -204,9 +201,6 @@ jobs:
npm install npm install
npm run build-runner npm run build-runner
- name: Initialize dotnet
run: dotnet restore
- name: Run init - name: Run init
run: | run: |
../action/runner/dist/codeql-runner-win.exe init --repository $Env:GITHUB_REPOSITORY --languages csharp --github-url $Env:GITHUB_SERVER_URL --github-auth ${{ github.token }} ../action/runner/dist/codeql-runner-win.exe init --repository $Env:GITHUB_REPOSITORY --languages csharp --github-url $Env:GITHUB_SERVER_URL --github-auth ${{ github.token }}
@@ -252,9 +246,6 @@ jobs:
npm install npm install
npm run build-runner npm run build-runner
- name: Initialize dotnet
run: dotnet restore
- name: Run init - name: Run init
run: | run: |
../action/runner/dist/codeql-runner-macos init --repository $GITHUB_REPOSITORY --languages csharp --github-url $GITHUB_SERVER_URL --github-auth ${{ github.token }} ../action/runner/dist/codeql-runner-macos init --repository $GITHUB_REPOSITORY --languages csharp --github-url $GITHUB_SERVER_URL --github-auth ${{ github.token }}
@@ -1,7 +1,5 @@
name: Update release branch name: Update release branch
on: on:
schedule:
- cron: 0 9 * * 1
repository_dispatch: repository_dispatch:
# Example of how to trigger this: # Example of how to trigger this:
# curl -H "Authorization: Bearer <token>" -X POST https://api.github.com/repos/github/codeql-action/dispatches -d '{"event_type":"update-release-branch"}' # curl -H "Authorization: Bearer <token>" -X POST https://api.github.com/repos/github/codeql-action/dispatches -d '{"event_type":"update-release-branch"}'
+9
View File
@@ -1,5 +1,14 @@
# CodeQL Action and CodeQL Runner Changelog # CodeQL Action and CodeQL Runner Changelog
## [UNRELEASED]
No user facing changes.
## 1.0.27 - 11 Jan 2022
- The `analyze` and `upload-sarif` actions will now wait up to 2 minutes for processing to complete after they have uploaded the results so they can report any processing errors that occurred. This behavior can be disabled by setting the `wait-for-processing` action input to `"false"`.
## 1.0.26 - 10 Dec 2021 ## 1.0.26 - 10 Dec 2021
- Update default CodeQL bundle version to 2.7.3. [#842](https://github.com/github/codeql-action/pull/842) - Update default CodeQL bundle version to 2.7.3. [#842](https://github.com/github/codeql-action/pull/842)
+1 -1
View File
@@ -55,7 +55,7 @@ inputs:
wait-for-processing: wait-for-processing:
description: If true, the Action will wait for the uploaded SARIF to be processed before completing. description: If true, the Action will wait for the uploaded SARIF to be processed before completing.
required: true required: true
default: "false" default: "true"
token: token:
default: ${{ github.token }} default: ${{ github.token }}
matrix: matrix:
+10
View File
@@ -59,6 +59,16 @@ inputs:
description: Enable debugging mode. This will result in more output being produced which may be useful when debugging certain issues. description: Enable debugging mode. This will result in more output being produced which may be useful when debugging certain issues.
required: false required: false
default: 'false' default: 'false'
debug-artifact-name:
description: >-
The name of the artifact to store debugging information in.
This is only used when debug mode is enabled.
required: false
debug-database-name:
description: >-
The name of the database uploaded to the debugging artifact.
This is only used when debug mode is enabled.
required: false
outputs: outputs:
codeql-path: codeql-path:
description: The path of the CodeQL binary used for analysis description: The path of the CodeQL binary used for analysis
+6
View File
@@ -43,6 +43,8 @@ const util = __importStar(require("./util"));
dbLocation: path.resolve(tmpDir, "codeql_databases"), dbLocation: path.resolve(tmpDir, "codeql_databases"),
packs: {}, packs: {},
debugMode: false, debugMode: false,
debugArtifactName: util.DEFAULT_DEBUG_ARTIFACT_NAME,
debugDatabaseName: util.DEFAULT_DEBUG_DATABASE_NAME,
}; };
analysisPaths.includeAndExcludeAnalysisPaths(config); analysisPaths.includeAndExcludeAnalysisPaths(config);
t.is(process.env["LGTM_INDEX_INCLUDE"], undefined); t.is(process.env["LGTM_INDEX_INCLUDE"], undefined);
@@ -65,6 +67,8 @@ const util = __importStar(require("./util"));
dbLocation: path.resolve(tmpDir, "codeql_databases"), dbLocation: path.resolve(tmpDir, "codeql_databases"),
packs: {}, packs: {},
debugMode: false, debugMode: false,
debugArtifactName: util.DEFAULT_DEBUG_ARTIFACT_NAME,
debugDatabaseName: util.DEFAULT_DEBUG_DATABASE_NAME,
}; };
analysisPaths.includeAndExcludeAnalysisPaths(config); analysisPaths.includeAndExcludeAnalysisPaths(config);
t.is(process.env["LGTM_INDEX_INCLUDE"], "path1\npath2"); t.is(process.env["LGTM_INDEX_INCLUDE"], "path1\npath2");
@@ -88,6 +92,8 @@ const util = __importStar(require("./util"));
dbLocation: path.resolve(tempDir, "codeql_databases"), dbLocation: path.resolve(tempDir, "codeql_databases"),
packs: {}, packs: {},
debugMode: false, debugMode: false,
debugArtifactName: util.DEFAULT_DEBUG_ARTIFACT_NAME,
debugDatabaseName: util.DEFAULT_DEBUG_DATABASE_NAME,
}; };
analysisPaths.includeAndExcludeAnalysisPaths(config); analysisPaths.includeAndExcludeAnalysisPaths(config);
t.is(process.env["LGTM_INDEX_INCLUDE"], undefined); t.is(process.env["LGTM_INDEX_INCLUDE"], undefined);
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"analysis-paths.test.js","sourceRoot":"","sources":["../src/analysis-paths.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAE7B,8CAAuB;AAEvB,gEAAkD;AAClD,mDAA6C;AAC7C,6CAA+B;AAE/B,IAAA,0BAAU,EAAC,aAAI,CAAC,CAAC;AAEjB,IAAA,aAAI,EAAC,YAAY,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAC7B,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC5C,MAAM,MAAM,GAAG;YACb,SAAS,EAAE,EAAE;YACb,OAAO,EAAE,EAAE;YACX,WAAW,EAAE,EAAE;YACf,KAAK,EAAE,EAAE;YACT,iBAAiB,EAAE,EAAE;YACrB,OAAO,EAAE,MAAM;YACf,YAAY,EAAE,MAAM;YACpB,SAAS,EAAE,EAAE;YACb,aAAa,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,MAAM,EAAwB;YACxE,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,kBAAkB,CAAC;YACpD,KAAK,EAAE,EAAE;YACT,SAAS,EAAE,KAAK;SACjB,CAAC;QACF,a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AC;QAC/D,MAAM,MAAM,GAAG;YACb,SAAS,EAAE,EAAE;YACb,OAAO,EAAE,EAAE;YACX,WAAW,EAAE,EAAE;YACf,KAAK,EAAE,EAAE;YACT,iBAAiB,EAAE,EAAE;YACrB,OAAO;YACP,YAAY;YACZ,SAAS,EAAE,EAAE;YACb,aAAa,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,MAAM,EAAwB;YACxE,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,kBAAkB,CAAC;YACrD,KAAK,EAAE,EAAE;YACT,SAAS,EAAE,KAAK;YAChB,iBAAiB,EAAE,IAAI,CAAC,2BAA2B;YACnD,iBAAiB,EAAE,IAAI,CAAC,2BAA2B;SACpD,CAAC;QACF,aAAa,CAAC,8BAA8B,CAAC,MAAM,CAAC,CAAC;QACrD,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE,SAAS,CAAC,CAAC;QACnD,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE,oBAAoB,CAAC,CAAC;QAC9D,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE,SAAS,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
+2
View File
@@ -45,6 +45,7 @@ const util = __importStar(require("./util"));
.resolves({}); .resolves({});
sinon.stub(actionsUtil, "sendStatusReport").resolves(true); sinon.stub(actionsUtil, "sendStatusReport").resolves(true);
sinon.stub(configUtils, "getConfig").resolves({ sinon.stub(configUtils, "getConfig").resolves({
gitHubVersion: { type: util.GitHubVariant.DOTCOM },
languages: [], languages: [],
}); });
const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput"); const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput");
@@ -53,6 +54,7 @@ const util = __importStar(require("./util"));
const optionalInputStub = sinon.stub(actionsUtil, "getOptionalInput"); const optionalInputStub = sinon.stub(actionsUtil, "getOptionalInput");
optionalInputStub.withArgs("cleanup-level").returns("none"); optionalInputStub.withArgs("cleanup-level").returns("none");
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir); (0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
(0, testing_utils_1.mockFeatureFlagApiEndpoint)(200, {});
// When there are no action inputs for RAM and threads, the action uses // When there are no action inputs for RAM and threads, the action uses
// environment variables (passed down from the init action) to set RAM and // environment variables (passed down from the init action) to set RAM and
// threads usage. // threads usage.
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"analyze-action-env.test.js","sourceRoot":"","sources":["../src/analyze-action-env.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAuB;AACvB,6CAA+B;AAE/B,4DAA8C;AAC9C,mDAAqC;AACrC,4DAA8C;AAC9C,mDAA+D;AAC/D,6CAA+B;AAE/B,IAAA,0BAAU,EAAC,aAAI,CAAC,CAAC;AAEjB,4EAA4E;AAC5E,4EAA4E;AAC5E,+EAA+E;AAC/E,+EAA+E;AAC/E,gFAAgF;AAChF,iCAAiC;AAEjC,IAAA,aAAI,EAAC,8DAA8D,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAC/E,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QACrC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,GAAG,iBAAiB,CAAC;QACrD,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,GAAG,iBAAiB,CAAC;QACrD,KAAK;aACF,IAAI,CAAC,WAAW,EAAE,wBAAwB,CAAC;aAC3C,QAAQ,CAAC,EAAkC,CAAC,CAAC;QAChD,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC3D,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,WAA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AC7D,CAAC,CAAC,SAAS,CAAC,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;QAC9D,CAAC,CAAC,SAAS,CAAC,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
+2
View File
@@ -45,6 +45,7 @@ const util = __importStar(require("./util"));
.resolves({}); .resolves({});
sinon.stub(actionsUtil, "sendStatusReport").resolves(true); sinon.stub(actionsUtil, "sendStatusReport").resolves(true);
sinon.stub(configUtils, "getConfig").resolves({ sinon.stub(configUtils, "getConfig").resolves({
gitHubVersion: { type: util.GitHubVariant.DOTCOM },
languages: [], languages: [],
}); });
const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput"); const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput");
@@ -53,6 +54,7 @@ const util = __importStar(require("./util"));
const optionalInputStub = sinon.stub(actionsUtil, "getOptionalInput"); const optionalInputStub = sinon.stub(actionsUtil, "getOptionalInput");
optionalInputStub.withArgs("cleanup-level").returns("none"); optionalInputStub.withArgs("cleanup-level").returns("none");
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir); (0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
(0, testing_utils_1.mockFeatureFlagApiEndpoint)(200, {});
process.env["CODEQL_THREADS"] = "1"; process.env["CODEQL_THREADS"] = "1";
process.env["CODEQL_RAM"] = "4992"; process.env["CODEQL_RAM"] = "4992";
// Action inputs have precedence over environment variables. // Action inputs have precedence over environment variables.
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"analyze-action-input.test.js","sourceRoot":"","sources":["../src/analyze-action-input.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAuB;AACvB,6CAA+B;AAE/B,4DAA8C;AAC9C,mDAAqC;AACrC,4DAA8C;AAC9C,mDAA+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codeql_1 = require("./codeql"); const codeql_1 = require("./codeql");
const config_utils_1 = require("./config-utils"); const config_utils_1 = require("./config-utils");
const database_upload_1 = require("./database-upload"); const database_upload_1 = require("./database-upload");
const feature_flags_1 = require("./feature-flags");
const logging_1 = require("./logging"); const logging_1 = require("./logging");
const repository_1 = require("./repository"); const repository_1 = require("./repository");
const upload_lib = __importStar(require("./upload-lib")); const upload_lib = __importStar(require("./upload-lib"));
@@ -71,12 +72,19 @@ async function run() {
const outputDir = actionsUtil.getRequiredInput("output"); const outputDir = actionsUtil.getRequiredInput("output");
const threads = util.getThreadsFlag(actionsUtil.getOptionalInput("threads") || process.env["CODEQL_THREADS"], logger); const threads = util.getThreadsFlag(actionsUtil.getOptionalInput("threads") || process.env["CODEQL_THREADS"], logger);
const memory = util.getMemoryFlag(actionsUtil.getOptionalInput("ram") || process.env["CODEQL_RAM"]); const memory = util.getMemoryFlag(actionsUtil.getOptionalInput("ram") || process.env["CODEQL_RAM"]);
const repositoryNwo = (0, repository_1.parseRepositoryNwo)(util.getRequiredEnvParam("GITHUB_REPOSITORY"));
const featureFlags = new feature_flags_1.GitHubFeatureFlags(config.gitHubVersion, apiDetails, repositoryNwo, logger);
// We currently perform an API request in both the `init` and `analyze` Actions to determine
// what feature flags are enabled. At the time of writing, this redundant API call is acceptable
// to us, but if we wanted to avoid it, we could do so by serializing the feature flags as part
// of the config file.
void featureFlags.preloadFeatureFlags();
await (0, analyze_1.runFinalize)(outputDir, threads, memory, config, logger); await (0, analyze_1.runFinalize)(outputDir, threads, memory, config, logger);
if (actionsUtil.getRequiredInput("skip-queries") !== "true") { if (actionsUtil.getRequiredInput("skip-queries") !== "true") {
runStats = await (0, analyze_1.runQueries)(outputDir, memory, util.getAddSnippetsFlag(actionsUtil.getRequiredInput("add-snippets")), threads, actionsUtil.getOptionalInput("category"), config, logger); runStats = await (0, analyze_1.runQueries)(outputDir, memory, util.getAddSnippetsFlag(actionsUtil.getRequiredInput("add-snippets")), threads, actionsUtil.getOptionalInput("category"), config, logger);
if (config.debugMode) { if (config.debugMode) {
// Upload the SARIF files as an Actions artifact for debugging // Upload the SARIF files as an Actions artifact for debugging
await uploadDebugArtifacts(config.languages.map((lang) => path.resolve(outputDir, `${lang}.sarif`)), outputDir); await uploadDebugArtifacts(config.languages.map((lang) => path.resolve(outputDir, `${lang}.sarif`)), outputDir, config.debugArtifactName);
} }
} }
const codeql = await (0, codeql_1.getCodeQL)(config.codeQLCmd); const codeql = await (0, codeql_1.getCodeQL)(config.codeQLCmd);
@@ -90,10 +98,10 @@ async function run() {
// Multilanguage tracing: there are additional logs in the root of the cluster // Multilanguage tracing: there are additional logs in the root of the cluster
toUpload.push(...listFolder(path.resolve(config.dbLocation, "log"))); toUpload.push(...listFolder(path.resolve(config.dbLocation, "log")));
} }
await uploadDebugArtifacts(toUpload, config.dbLocation); await uploadDebugArtifacts(toUpload, config.dbLocation, config.debugArtifactName);
if (!(await (0, util_1.codeQlVersionAbove)(codeql, codeql_1.CODEQL_VERSION_NEW_TRACING))) { if (!(await (0, util_1.codeQlVersionAbove)(codeql, codeql_1.CODEQL_VERSION_NEW_TRACING))) {
// Before multi-language tracing, we wrote a compound-build-tracer.log in the temp dir // Before multi-language tracing, we wrote a compound-build-tracer.log in the temp dir
await uploadDebugArtifacts([path.resolve(config.tempDir, "compound-build-tracer.log")], config.tempDir); await uploadDebugArtifacts([path.resolve(config.tempDir, "compound-build-tracer.log")], config.tempDir, config.debugArtifactName);
} }
} }
if (actionsUtil.getOptionalInput("cleanup-level") !== "none") { if (actionsUtil.getOptionalInput("cleanup-level") !== "none") {
@@ -110,19 +118,12 @@ async function run() {
else { else {
logger.info("Not uploading results"); logger.info("Not uploading results");
} }
const repositoryNwo = (0, repository_1.parseRepositoryNwo)(util.getRequiredEnvParam("GITHUB_REPOSITORY")); // Possibly upload the database bundles for remote queries
await (0, database_upload_1.uploadDatabases)(repositoryNwo, config, apiDetails, logger); // Possibly upload the database bundles for remote queries await (0, database_upload_1.uploadDatabases)(repositoryNwo, config, featureFlags, apiDetails, logger);
if (uploadResult !== undefined && if (uploadResult !== undefined &&
actionsUtil.getRequiredInput("wait-for-processing") === "true") { actionsUtil.getRequiredInput("wait-for-processing") === "true") {
await upload_lib.waitForProcessing((0, repository_1.parseRepositoryNwo)(util.getRequiredEnvParam("GITHUB_REPOSITORY")), uploadResult.sarifID, apiDetails, (0, logging_1.getActionsLogger)()); await upload_lib.waitForProcessing((0, repository_1.parseRepositoryNwo)(util.getRequiredEnvParam("GITHUB_REPOSITORY")), uploadResult.sarifID, apiDetails, (0, logging_1.getActionsLogger)());
} }
if (config.debugMode) {
// Upload the database bundles as an Actions artifact for debugging
const toUpload = [];
for (const language of config.languages)
toUpload.push(await (0, util_1.bundleDb)(config, language, codeql));
await uploadDebugArtifacts(toUpload, config.dbLocation);
}
} }
catch (origError) { catch (origError) {
const error = origError instanceof Error ? origError : new Error(String(origError)); const error = origError instanceof Error ? origError : new Error(String(origError));
@@ -138,6 +139,19 @@ async function run() {
return; return;
} }
finally { finally {
if (config !== undefined && config.debugMode) {
try {
// Upload the database bundles as an Actions artifact for debugging
const toUpload = [];
for (const language of config.languages) {
toUpload.push(await (0, util_1.bundleDb)(config, language, await (0, codeql_1.getCodeQL)(config.codeQLCmd), `${config.debugDatabaseName}-${language}`));
}
await uploadDebugArtifacts(toUpload, config.dbLocation, config.debugArtifactName);
}
catch (error) {
console.log(`Failed to upload database debug bundles: ${error}`);
}
}
if (core.isDebug() && config !== undefined) { if (core.isDebug() && config !== undefined) {
core.info("Debug mode is on. Printing CodeQL debug logs..."); core.info("Debug mode is on. Printing CodeQL debug logs...");
for (const language of config.languages) { for (const language of config.languages) {
@@ -173,14 +187,14 @@ async function run() {
await sendStatusReport(startedAt, undefined); await sendStatusReport(startedAt, undefined);
} }
} }
async function uploadDebugArtifacts(toUpload, rootDir) { async function uploadDebugArtifacts(toUpload, rootDir, artifactName) {
let suffix = ""; let suffix = "";
const matrix = actionsUtil.getRequiredInput("matrix"); const matrix = actionsUtil.getRequiredInput("matrix");
if (matrix !== undefined && matrix !== "null") { if (matrix !== undefined && matrix !== "null") {
for (const entry of Object.entries(JSON.parse(matrix)).sort()) for (const entry of Object.entries(JSON.parse(matrix)).sort())
suffix += `-${entry[1]}`; suffix += `-${entry[1]}`;
} }
await artifact.create().uploadArtifact(actionsUtil.sanitizeArifactName(`${util_1.DEBUG_ARTIFACT_NAME}${suffix}`), toUpload.map((file) => path.normalize(file)), path.normalize(rootDir)); await artifact.create().uploadArtifact(actionsUtil.sanitizeArifactName(`${artifactName}${suffix}`), toUpload.map((file) => path.normalize(file)), path.normalize(rootDir));
} }
function listFolder(dir) { function listFolder(dir) {
const entries = fs.readdirSync(dir, { withFileTypes: true }); const entries = fs.readdirSync(dir, { withFileTypes: true });
File diff suppressed because one or more lines are too long
+2
View File
@@ -126,6 +126,8 @@ const util = __importStar(require("./util"));
dbLocation: path.resolve(tmpDir, "codeql_databases"), dbLocation: path.resolve(tmpDir, "codeql_databases"),
packs, packs,
debugMode: false, debugMode: false,
debugArtifactName: util.DEFAULT_DEBUG_ARTIFACT_NAME,
debugDatabaseName: util.DEFAULT_DEBUG_DATABASE_NAME,
}; };
fs.mkdirSync(util.getCodeQLDatabasePath(config, language), { fs.mkdirSync(util.getCodeQLDatabasePath(config, language), {
recursive: true, recursive: true,
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1 +1 @@
{ "maximumVersion": "3.3", "minimumVersion": "3.0" } { "maximumVersion": "3.4", "minimumVersion": "3.0" }
Generated
+4 -2
View File
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.getExtraOptions = exports.getCodeQLForTesting = exports.getCachedCodeQL = exports.setCodeQL = exports.getCodeQL = exports.convertToSemVer = exports.getCodeQLURLVersion = exports.setupCodeQL = exports.getCodeQLActionRepository = exports.CODEQL_VERSION_NEW_TRACING = exports.CODEQL_VERSION_COUNTS_LINES = exports.CommandInvocationError = void 0; exports.getExtraOptions = exports.getCodeQLForTesting = exports.getCachedCodeQL = exports.setCodeQL = exports.getCodeQL = exports.convertToSemVer = exports.getCodeQLURLVersion = exports.setupCodeQL = exports.getCodeQLActionRepository = exports.CODEQL_VERSION_NEW_TRACING = exports.CODEQL_VERSION_ML_POWERED_QUERIES = exports.CODEQL_VERSION_COUNTS_LINES = exports.CommandInvocationError = void 0;
const fs = __importStar(require("fs")); const fs = __importStar(require("fs"));
const path = __importStar(require("path")); const path = __importStar(require("path"));
const toolrunner = __importStar(require("@actions/exec/lib/toolrunner")); const toolrunner = __importStar(require("@actions/exec/lib/toolrunner"));
@@ -74,6 +74,7 @@ const CODEQL_VERSION_GROUP_RULES = "2.5.5";
const CODEQL_VERSION_SARIF_GROUP = "2.5.3"; const CODEQL_VERSION_SARIF_GROUP = "2.5.3";
exports.CODEQL_VERSION_COUNTS_LINES = "2.6.2"; exports.CODEQL_VERSION_COUNTS_LINES = "2.6.2";
const CODEQL_VERSION_CUSTOM_QUERY_HELP = "2.7.1"; const CODEQL_VERSION_CUSTOM_QUERY_HELP = "2.7.1";
exports.CODEQL_VERSION_ML_POWERED_QUERIES = "2.7.5";
/** /**
* This variable controls using the new style of tracing from the CodeQL * This variable controls using the new style of tracing from the CodeQL
* CLI. In particular, with versions above this we will use both indirect * CLI. In particular, with versions above this we will use both indirect
@@ -637,12 +638,13 @@ async function getCodeQLForCmd(cmd, checkVersion) {
]; ];
await runTool(cmd, codeqlArgs); await runTool(cmd, codeqlArgs);
}, },
async databaseBundle(databasePath, outputFilePath) { async databaseBundle(databasePath, outputFilePath, databaseName) {
const args = [ const args = [
"database", "database",
"bundle", "bundle",
databasePath, databasePath,
`--output=${outputFilePath}`, `--output=${outputFilePath}`,
`--name=${databaseName}`,
]; ];
await new toolrunner.ToolRunner(cmd, args).exec(); await new toolrunner.ToolRunner(cmd, args).exec();
}, },
+1 -1
View File
File diff suppressed because one or more lines are too long
+38 -16
View File
@@ -25,8 +25,11 @@ const path = __importStar(require("path"));
const yaml = __importStar(require("js-yaml")); const yaml = __importStar(require("js-yaml"));
const semver = __importStar(require("semver")); const semver = __importStar(require("semver"));
const api = __importStar(require("./api-client")); const api = __importStar(require("./api-client"));
const codeql_1 = require("./codeql");
const externalQueries = __importStar(require("./external-queries")); const externalQueries = __importStar(require("./external-queries"));
const feature_flags_1 = require("./feature-flags");
const languages_1 = require("./languages"); const languages_1 = require("./languages");
const util_1 = require("./util");
// Property names from the user-supplied config file. // Property names from the user-supplied config file.
const NAME_PROPERTY = "name"; const NAME_PROPERTY = "name";
const DISABLE_DEFAULT_QUERIES_PROPERTY = "disable-default-queries"; const DISABLE_DEFAULT_QUERIES_PROPERTY = "disable-default-queries";
@@ -116,11 +119,26 @@ const builtinSuites = ["security-extended", "security-and-quality"];
* Determine the set of queries associated with suiteName's suites and add them to resultMap. * Determine the set of queries associated with suiteName's suites and add them to resultMap.
* Throws an error if suiteName is not a valid builtin suite. * Throws an error if suiteName is not a valid builtin suite.
*/ */
async function addBuiltinSuiteQueries(languages, codeQL, resultMap, suiteName, configFile) { async function addBuiltinSuiteQueries(languages, codeQL, resultMap, packs, suiteName, featureFlags, configFile) {
const found = builtinSuites.find((suite) => suite === suiteName); const found = builtinSuites.find((suite) => suite === suiteName);
if (!found) { if (!found) {
throw new Error(getQueryUsesInvalid(configFile, suiteName)); throw new Error(getQueryUsesInvalid(configFile, suiteName));
} }
// If we're running the JavaScript security-extended analysis (or a superset of it) and the repo
// is opted into the ML-powered queries beta, then add the ML-powered query pack so that we run
// the ML-powered queries.
if (languages.includes("javascript") &&
(found === "security-extended" || found === "security-and-quality") &&
(await featureFlags.getValue(feature_flags_1.FeatureFlag.MlPoweredQueriesEnabled)) &&
(await (0, util_1.codeQlVersionAbove)(codeQL, codeql_1.CODEQL_VERSION_ML_POWERED_QUERIES))) {
if (!packs.javascript) {
packs.javascript = [];
}
packs.javascript.push({
packName: "codeql/javascript-experimental-atm-queries",
version: "~0.0.2",
});
}
const suites = languages.map((l) => `${l}-${suiteName}.qls`); const suites = languages.map((l) => `${l}-${suiteName}.qls`);
await runResolveQueries(codeQL, resultMap, suites, undefined); await runResolveQueries(codeQL, resultMap, suites, undefined);
} }
@@ -180,7 +198,7 @@ async function addRemoteQueries(codeQL, resultMap, queryUses, tempDir, apiDetail
* local paths starting with './', or references to remote repos, or * local paths starting with './', or references to remote repos, or
* a finite set of hardcoded terms for builtin suites. * a finite set of hardcoded terms for builtin suites.
*/ */
async function parseQueryUses(languages, codeQL, resultMap, queryUses, tempDir, workspacePath, apiDetails, logger, configFile) { async function parseQueryUses(languages, codeQL, resultMap, packs, queryUses, tempDir, workspacePath, apiDetails, featureFlags, logger, configFile) {
queryUses = queryUses.trim(); queryUses = queryUses.trim();
if (queryUses === "") { if (queryUses === "") {
throw new Error(getQueryUsesInvalid(configFile)); throw new Error(getQueryUsesInvalid(configFile));
@@ -192,7 +210,7 @@ async function parseQueryUses(languages, codeQL, resultMap, queryUses, tempDir,
} }
// Check for one of the builtin suites // Check for one of the builtin suites
if (queryUses.indexOf("/") === -1 && queryUses.indexOf("@") === -1) { if (queryUses.indexOf("/") === -1 && queryUses.indexOf("@") === -1) {
await addBuiltinSuiteQueries(languages, codeQL, resultMap, queryUses, configFile); await addBuiltinSuiteQueries(languages, codeQL, resultMap, packs, queryUses, featureFlags, configFile);
return; return;
} }
// Otherwise, must be a reference to another repo // Otherwise, must be a reference to another repo
@@ -404,12 +422,12 @@ async function getLanguages(codeQL, languagesInput, repository, apiDetails, logg
} }
return parsedLanguages; return parsedLanguages;
} }
async function addQueriesFromWorkflow(codeQL, queriesInput, languages, resultMap, tempDir, workspacePath, apiDetails, logger) { async function addQueriesAndPacksFromWorkflow(codeQL, queriesInput, languages, resultMap, packs, tempDir, workspacePath, apiDetails, featureFlags, logger) {
queriesInput = queriesInput.trim(); queriesInput = queriesInput.trim();
// "+" means "don't override config file" - see shouldAddConfigFileQueries // "+" means "don't override config file" - see shouldAddConfigFileQueries
queriesInput = queriesInput.replace(/^\+/, ""); queriesInput = queriesInput.replace(/^\+/, "");
for (const query of queriesInput.split(",")) { for (const query of queriesInput.split(",")) {
await parseQueryUses(languages, codeQL, resultMap, query, tempDir, workspacePath, apiDetails, logger); await parseQueryUses(languages, codeQL, resultMap, packs, query, tempDir, workspacePath, apiDetails, featureFlags, logger);
} }
} }
// Returns true if either no queries were provided in the workflow. // Returns true if either no queries were provided in the workflow.
@@ -425,7 +443,7 @@ function shouldAddConfigFileQueries(queriesInput) {
/** /**
* Get the default config for when the user has not supplied one. * Get the default config for when the user has not supplied one.
*/ */
async function getDefaultConfig(languagesInput, queriesInput, packsInput, dbLocation, debugMode, repository, tempDir, toolCacheDir, codeQL, workspacePath, gitHubVersion, apiDetails, logger) { async function getDefaultConfig(languagesInput, queriesInput, packsInput, dbLocation, debugMode, debugArtifactName, debugDatabaseName, repository, tempDir, toolCacheDir, codeQL, workspacePath, gitHubVersion, apiDetails, featureFlags, logger) {
var _a; var _a;
const languages = await getLanguages(codeQL, languagesInput, repository, apiDetails, logger); const languages = await getLanguages(codeQL, languagesInput, repository, apiDetails, logger);
const queries = {}; const queries = {};
@@ -436,10 +454,10 @@ async function getDefaultConfig(languagesInput, queriesInput, packsInput, dbLoca
}; };
} }
await addDefaultQueries(codeQL, languages, queries); await addDefaultQueries(codeQL, languages, queries);
if (queriesInput) {
await addQueriesFromWorkflow(codeQL, queriesInput, languages, queries, tempDir, workspacePath, apiDetails, logger);
}
const packs = (_a = parsePacksFromInput(packsInput, languages)) !== null && _a !== void 0 ? _a : {}; const packs = (_a = parsePacksFromInput(packsInput, languages)) !== null && _a !== void 0 ? _a : {};
if (queriesInput) {
await addQueriesAndPacksFromWorkflow(codeQL, queriesInput, languages, queries, packs, tempDir, workspacePath, apiDetails, featureFlags, logger);
}
return { return {
languages, languages,
queries, queries,
@@ -453,13 +471,15 @@ async function getDefaultConfig(languagesInput, queriesInput, packsInput, dbLoca
gitHubVersion, gitHubVersion,
dbLocation: dbLocationOrDefault(dbLocation, tempDir), dbLocation: dbLocationOrDefault(dbLocation, tempDir),
debugMode, debugMode,
debugArtifactName,
debugDatabaseName,
}; };
} }
exports.getDefaultConfig = getDefaultConfig; exports.getDefaultConfig = getDefaultConfig;
/** /**
* Load the config from the given file. * Load the config from the given file.
*/ */
async function loadConfig(languagesInput, queriesInput, packsInput, configFile, dbLocation, debugMode, repository, tempDir, toolCacheDir, codeQL, workspacePath, gitHubVersion, apiDetails, logger) { async function loadConfig(languagesInput, queriesInput, packsInput, configFile, dbLocation, debugMode, debugArtifactName, debugDatabaseName, repository, tempDir, toolCacheDir, codeQL, workspacePath, gitHubVersion, apiDetails, featureFlags, logger) {
var _a; var _a;
let parsedYAML; let parsedYAML;
if (isLocal(configFile)) { if (isLocal(configFile)) {
@@ -500,12 +520,13 @@ async function loadConfig(languagesInput, queriesInput, packsInput, configFile,
if (!disableDefaultQueries) { if (!disableDefaultQueries) {
await addDefaultQueries(codeQL, languages, queries); await addDefaultQueries(codeQL, languages, queries);
} }
const packs = parsePacks((_a = parsedYAML[PACKS_PROPERTY]) !== null && _a !== void 0 ? _a : {}, packsInput, languages, configFile);
// If queries were provided using `with` in the action configuration, // If queries were provided using `with` in the action configuration,
// they should take precedence over the queries in the config file // they should take precedence over the queries in the config file
// unless they're prefixed with "+", in which case they supplement those // unless they're prefixed with "+", in which case they supplement those
// in the config file. // in the config file.
if (queriesInput) { if (queriesInput) {
await addQueriesFromWorkflow(codeQL, queriesInput, languages, queries, tempDir, workspacePath, apiDetails, logger); await addQueriesAndPacksFromWorkflow(codeQL, queriesInput, languages, queries, packs, tempDir, workspacePath, apiDetails, featureFlags, logger);
} }
if (shouldAddConfigFileQueries(queriesInput) && if (shouldAddConfigFileQueries(queriesInput) &&
QUERIES_PROPERTY in parsedYAML) { QUERIES_PROPERTY in parsedYAML) {
@@ -518,7 +539,7 @@ async function loadConfig(languagesInput, queriesInput, packsInput, configFile,
typeof query[QUERIES_USES_PROPERTY] !== "string") { typeof query[QUERIES_USES_PROPERTY] !== "string") {
throw new Error(getQueryUsesInvalid(configFile)); throw new Error(getQueryUsesInvalid(configFile));
} }
await parseQueryUses(languages, codeQL, queries, query[QUERIES_USES_PROPERTY], tempDir, workspacePath, apiDetails, logger, configFile); await parseQueryUses(languages, codeQL, queries, packs, query[QUERIES_USES_PROPERTY], tempDir, workspacePath, apiDetails, featureFlags, logger, configFile);
} }
} }
if (PATHS_IGNORE_PROPERTY in parsedYAML) { if (PATHS_IGNORE_PROPERTY in parsedYAML) {
@@ -543,7 +564,6 @@ async function loadConfig(languagesInput, queriesInput, packsInput, configFile,
paths.push(validateAndSanitisePath(includePath, PATHS_PROPERTY, configFile, logger)); paths.push(validateAndSanitisePath(includePath, PATHS_PROPERTY, configFile, logger));
} }
} }
const packs = parsePacks((_a = parsedYAML[PACKS_PROPERTY]) !== null && _a !== void 0 ? _a : {}, packsInput, languages, configFile);
return { return {
languages, languages,
queries, queries,
@@ -557,6 +577,8 @@ async function loadConfig(languagesInput, queriesInput, packsInput, configFile,
gitHubVersion, gitHubVersion,
dbLocation: dbLocationOrDefault(dbLocation, tempDir), dbLocation: dbLocationOrDefault(dbLocation, tempDir),
debugMode, debugMode,
debugArtifactName,
debugDatabaseName,
}; };
} }
/** /**
@@ -682,16 +704,16 @@ function dbLocationOrDefault(dbLocation, tempDir) {
* This will parse the config from the user input if present, or generate * This will parse the config from the user input if present, or generate
* a default config. The parsed config is then stored to a known location. * a default config. The parsed config is then stored to a known location.
*/ */
async function initConfig(languagesInput, queriesInput, packsInput, configFile, dbLocation, debugMode, repository, tempDir, toolCacheDir, codeQL, workspacePath, gitHubVersion, apiDetails, logger) { async function initConfig(languagesInput, queriesInput, packsInput, configFile, dbLocation, debugMode, debugArtifactName, debugDatabaseName, repository, tempDir, toolCacheDir, codeQL, workspacePath, gitHubVersion, apiDetails, featureFlags, logger) {
var _a, _b, _c; var _a, _b, _c;
let config; let config;
// If no config file was provided create an empty one // If no config file was provided create an empty one
if (!configFile) { if (!configFile) {
logger.debug("No configuration file was provided"); logger.debug("No configuration file was provided");
config = await getDefaultConfig(languagesInput, queriesInput, packsInput, dbLocation, debugMode, repository, tempDir, toolCacheDir, codeQL, workspacePath, gitHubVersion, apiDetails, logger); config = await getDefaultConfig(languagesInput, queriesInput, packsInput, dbLocation, debugMode, debugArtifactName, debugDatabaseName, repository, tempDir, toolCacheDir, codeQL, workspacePath, gitHubVersion, apiDetails, featureFlags, logger);
} }
else { else {
config = await loadConfig(languagesInput, queriesInput, packsInput, configFile, dbLocation, debugMode, repository, tempDir, toolCacheDir, codeQL, workspacePath, gitHubVersion, apiDetails, logger); config = await loadConfig(languagesInput, queriesInput, packsInput, configFile, dbLocation, debugMode, debugArtifactName, debugDatabaseName, repository, tempDir, toolCacheDir, codeQL, workspacePath, gitHubVersion, apiDetails, featureFlags, logger);
} }
// The list of queries should not be empty for any language. If it is then // The list of queries should not be empty for any language. If it is then
// it is a user configuration error. // it is a user configuration error.
File diff suppressed because one or more lines are too long
+71 -24
View File
@@ -31,6 +31,7 @@ const sinon = __importStar(require("sinon"));
const api = __importStar(require("./api-client")); const api = __importStar(require("./api-client"));
const codeql_1 = require("./codeql"); const codeql_1 = require("./codeql");
const configUtils = __importStar(require("./config-utils")); const configUtils = __importStar(require("./config-utils"));
const feature_flags_1 = require("./feature-flags");
const languages_1 = require("./languages"); const languages_1 = require("./languages");
const logging_1 = require("./logging"); const logging_1 = require("./logging");
const testing_utils_1 = require("./testing-utils"); const testing_utils_1 = require("./testing-utils");
@@ -88,8 +89,8 @@ function mockListLanguages(languages) {
}; };
}, },
}); });
const config = await configUtils.initConfig(languages, undefined, undefined, undefined, undefined, false, { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, logger); const config = await configUtils.initConfig(languages, undefined, undefined, undefined, undefined, false, "", "", { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, feature_flags_1.createFeatureFlags)([]), logger);
t.deepEqual(config, await configUtils.getDefaultConfig(languages, undefined, undefined, undefined, false, { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, logger)); t.deepEqual(config, await configUtils.getDefaultConfig(languages, undefined, undefined, undefined, false, "", "", { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, feature_flags_1.createFeatureFlags)([]), logger));
}); });
}); });
(0, ava_1.default)("loading config saves config", async (t) => { (0, ava_1.default)("loading config saves config", async (t) => {
@@ -111,7 +112,7 @@ function mockListLanguages(languages) {
t.false(fs.existsSync(configUtils.getPathToParsedConfigFile(tmpDir))); t.false(fs.existsSync(configUtils.getPathToParsedConfigFile(tmpDir)));
// Sanity check that getConfig returns undefined before we have called initConfig // Sanity check that getConfig returns undefined before we have called initConfig
t.deepEqual(await configUtils.getConfig(tmpDir, logger), undefined); t.deepEqual(await configUtils.getConfig(tmpDir, logger), undefined);
const config1 = await configUtils.initConfig("javascript,python", undefined, undefined, undefined, undefined, false, { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, logger); const config1 = await configUtils.initConfig("javascript,python", undefined, undefined, undefined, undefined, false, "", "", { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, feature_flags_1.createFeatureFlags)([]), logger);
// The saved config file should now exist // The saved config file should now exist
t.true(fs.existsSync(configUtils.getPathToParsedConfigFile(tmpDir))); t.true(fs.existsSync(configUtils.getPathToParsedConfigFile(tmpDir)));
// And that same newly-initialised config should now be returned by getConfig // And that same newly-initialised config should now be returned by getConfig
@@ -122,7 +123,7 @@ function mockListLanguages(languages) {
(0, ava_1.default)("load input outside of workspace", async (t) => { (0, ava_1.default)("load input outside of workspace", async (t) => {
return await util.withTmpDir(async (tmpDir) => { return await util.withTmpDir(async (tmpDir) => {
try { try {
await configUtils.initConfig(undefined, undefined, undefined, "../input", undefined, false, { owner: "github", repo: "example " }, tmpDir, tmpDir, (0, codeql_1.getCachedCodeQL)(), tmpDir, gitHubVersion, sampleApiDetails, (0, logging_1.getRunnerLogger)(true)); await configUtils.initConfig(undefined, undefined, undefined, "../input", undefined, false, "", "", { owner: "github", repo: "example " }, tmpDir, tmpDir, (0, codeql_1.getCachedCodeQL)(), tmpDir, gitHubVersion, sampleApiDetails, (0, feature_flags_1.createFeatureFlags)([]), (0, logging_1.getRunnerLogger)(true));
throw new Error("initConfig did not throw error"); throw new Error("initConfig did not throw error");
} }
catch (err) { catch (err) {
@@ -135,7 +136,7 @@ function mockListLanguages(languages) {
// no filename given, just a repo // no filename given, just a repo
const configFile = "octo-org/codeql-config@main"; const configFile = "octo-org/codeql-config@main";
try { try {
await configUtils.initConfig(undefined, undefined, undefined, configFile, undefined, false, { owner: "github", repo: "example " }, tmpDir, tmpDir, (0, codeql_1.getCachedCodeQL)(), tmpDir, gitHubVersion, sampleApiDetails, (0, logging_1.getRunnerLogger)(true)); await configUtils.initConfig(undefined, undefined, undefined, configFile, undefined, false, "", "", { owner: "github", repo: "example " }, tmpDir, tmpDir, (0, codeql_1.getCachedCodeQL)(), tmpDir, gitHubVersion, sampleApiDetails, (0, feature_flags_1.createFeatureFlags)([]), (0, logging_1.getRunnerLogger)(true));
throw new Error("initConfig did not throw error"); throw new Error("initConfig did not throw error");
} }
catch (err) { catch (err) {
@@ -149,7 +150,7 @@ function mockListLanguages(languages) {
const configFile = "input"; const configFile = "input";
t.false(fs.existsSync(path.join(tmpDir, configFile))); t.false(fs.existsSync(path.join(tmpDir, configFile)));
try { try {
await configUtils.initConfig(languages, undefined, undefined, configFile, undefined, false, { owner: "github", repo: "example " }, tmpDir, tmpDir, (0, codeql_1.getCachedCodeQL)(), tmpDir, gitHubVersion, sampleApiDetails, (0, logging_1.getRunnerLogger)(true)); await configUtils.initConfig(languages, undefined, undefined, configFile, undefined, false, "", "", { owner: "github", repo: "example " }, tmpDir, tmpDir, (0, codeql_1.getCachedCodeQL)(), tmpDir, gitHubVersion, sampleApiDetails, (0, feature_flags_1.createFeatureFlags)([]), (0, logging_1.getRunnerLogger)(true));
throw new Error("initConfig did not throw error"); throw new Error("initConfig did not throw error");
} }
catch (err) { catch (err) {
@@ -215,10 +216,12 @@ function mockListLanguages(languages) {
dbLocation: path.resolve(tmpDir, "codeql_databases"), dbLocation: path.resolve(tmpDir, "codeql_databases"),
packs: {}, packs: {},
debugMode: false, debugMode: false,
debugArtifactName: "my-artifact",
debugDatabaseName: "my-db",
}; };
const languages = "javascript"; const languages = "javascript";
const configFilePath = createConfigFile(inputFileContents, tmpDir); const configFilePath = createConfigFile(inputFileContents, tmpDir);
const actualConfig = await configUtils.initConfig(languages, undefined, undefined, configFilePath, undefined, false, { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, logging_1.getRunnerLogger)(true)); const actualConfig = await configUtils.initConfig(languages, undefined, undefined, configFilePath, undefined, false, "my-artifact", "my-db", { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, feature_flags_1.createFeatureFlags)([]), (0, logging_1.getRunnerLogger)(true));
// Should exactly equal the object we constructed earlier // Should exactly equal the object we constructed earlier
t.deepEqual(actualConfig, expectedConfig); t.deepEqual(actualConfig, expectedConfig);
}); });
@@ -254,7 +257,7 @@ function mockListLanguages(languages) {
fs.mkdirSync(path.join(tmpDir, "foo")); fs.mkdirSync(path.join(tmpDir, "foo"));
const languages = "javascript"; const languages = "javascript";
const configFilePath = createConfigFile(inputFileContents, tmpDir); const configFilePath = createConfigFile(inputFileContents, tmpDir);
await configUtils.initConfig(languages, undefined, undefined, configFilePath, undefined, false, { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, logging_1.getRunnerLogger)(true)); await configUtils.initConfig(languages, undefined, undefined, configFilePath, undefined, false, "", "", { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, feature_flags_1.createFeatureFlags)([]), (0, logging_1.getRunnerLogger)(true));
// Check resolve queries was called correctly // Check resolve queries was called correctly
t.deepEqual(resolveQueriesArgs.length, 1); t.deepEqual(resolveQueriesArgs.length, 1);
t.deepEqual(resolveQueriesArgs[0].queries, [ t.deepEqual(resolveQueriesArgs[0].queries, [
@@ -297,7 +300,7 @@ function queriesToResolvedQueryForm(queries) {
}, },
}); });
const languages = "javascript"; const languages = "javascript";
const config = await configUtils.initConfig(languages, undefined, undefined, configFilePath, undefined, false, { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, logging_1.getRunnerLogger)(true)); const config = await configUtils.initConfig(languages, undefined, undefined, configFilePath, undefined, false, "", "", { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, feature_flags_1.createFeatureFlags)([]), (0, logging_1.getRunnerLogger)(true));
// Check resolveQueries was called correctly // Check resolveQueries was called correctly
// It'll be called once for the default queries // It'll be called once for the default queries
// and once for `./foo` from the config file. // and once for `./foo` from the config file.
@@ -330,7 +333,7 @@ function queriesToResolvedQueryForm(queries) {
}, },
}); });
const languages = "javascript"; const languages = "javascript";
const config = await configUtils.initConfig(languages, testQueries, undefined, configFilePath, undefined, false, { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, logging_1.getRunnerLogger)(true)); const config = await configUtils.initConfig(languages, testQueries, undefined, configFilePath, undefined, false, "", "", { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, feature_flags_1.createFeatureFlags)([]), (0, logging_1.getRunnerLogger)(true));
// Check resolveQueries was called correctly // Check resolveQueries was called correctly
// It'll be called once for the default queries and once for `./override`, // It'll be called once for the default queries and once for `./override`,
// but won't be called for './foo' from the config file. // but won't be called for './foo' from the config file.
@@ -362,7 +365,7 @@ function queriesToResolvedQueryForm(queries) {
}, },
}); });
const languages = "javascript"; const languages = "javascript";
const config = await configUtils.initConfig(languages, testQueries, undefined, configFilePath, undefined, false, { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, logging_1.getRunnerLogger)(true)); const config = await configUtils.initConfig(languages, testQueries, undefined, configFilePath, undefined, false, "", "", { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, feature_flags_1.createFeatureFlags)([]), (0, logging_1.getRunnerLogger)(true));
// Check resolveQueries was called correctly // Check resolveQueries was called correctly
// It'll be called once for `./workflow-query`, // It'll be called once for `./workflow-query`,
// but won't be called for the default one since that was disabled // but won't be called for the default one since that was disabled
@@ -388,7 +391,7 @@ function queriesToResolvedQueryForm(queries) {
}, },
}); });
const languages = "javascript"; const languages = "javascript";
const config = await configUtils.initConfig(languages, testQueries, undefined, undefined, undefined, false, { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, logging_1.getRunnerLogger)(true)); const config = await configUtils.initConfig(languages, testQueries, undefined, undefined, undefined, false, "", "", { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, feature_flags_1.createFeatureFlags)([]), (0, logging_1.getRunnerLogger)(true));
// Check resolveQueries was called correctly: // Check resolveQueries was called correctly:
// It'll be called once for the default queries, // It'll be called once for the default queries,
// and then once for each of the two queries from the workflow // and then once for each of the two queries from the workflow
@@ -427,7 +430,7 @@ function queriesToResolvedQueryForm(queries) {
}, },
}); });
const languages = "javascript"; const languages = "javascript";
const config = await configUtils.initConfig(languages, testQueries, undefined, configFilePath, undefined, false, { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, logging_1.getRunnerLogger)(true)); const config = await configUtils.initConfig(languages, testQueries, undefined, configFilePath, undefined, false, "", "", { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, feature_flags_1.createFeatureFlags)([]), (0, logging_1.getRunnerLogger)(true));
// Check resolveQueries was called correctly // Check resolveQueries was called correctly
// It'll be called once for the default queries, // It'll be called once for the default queries,
// once for each of additional1 and additional2, // once for each of additional1 and additional2,
@@ -466,7 +469,7 @@ function queriesToResolvedQueryForm(queries) {
}, },
}); });
try { try {
await configUtils.initConfig(languages, queries, undefined, undefined, undefined, false, { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, logging_1.getRunnerLogger)(true)); await configUtils.initConfig(languages, queries, undefined, undefined, undefined, false, "", "", { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, feature_flags_1.createFeatureFlags)([]), (0, logging_1.getRunnerLogger)(true));
t.fail("initConfig did not throw error"); t.fail("initConfig did not throw error");
} }
catch (err) { catch (err) {
@@ -509,7 +512,7 @@ function queriesToResolvedQueryForm(queries) {
fs.mkdirSync(path.join(tmpDir, "foo/bar/dev"), { recursive: true }); fs.mkdirSync(path.join(tmpDir, "foo/bar/dev"), { recursive: true });
const configFile = "octo-org/codeql-config/config.yaml@main"; const configFile = "octo-org/codeql-config/config.yaml@main";
const languages = "javascript"; const languages = "javascript";
await configUtils.initConfig(languages, undefined, undefined, configFile, undefined, false, { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, logging_1.getRunnerLogger)(true)); await configUtils.initConfig(languages, undefined, undefined, configFile, undefined, false, "", "", { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, feature_flags_1.createFeatureFlags)([]), (0, logging_1.getRunnerLogger)(true));
t.assert(spyGetContents.called); t.assert(spyGetContents.called);
}); });
}); });
@@ -519,7 +522,7 @@ function queriesToResolvedQueryForm(queries) {
mockGetContents(dummyResponse); mockGetContents(dummyResponse);
const repoReference = "octo-org/codeql-config/config.yaml@main"; const repoReference = "octo-org/codeql-config/config.yaml@main";
try { try {
await configUtils.initConfig(undefined, undefined, undefined, repoReference, undefined, false, { owner: "github", repo: "example " }, tmpDir, tmpDir, (0, codeql_1.getCachedCodeQL)(), tmpDir, gitHubVersion, sampleApiDetails, (0, logging_1.getRunnerLogger)(true)); await configUtils.initConfig(undefined, undefined, undefined, repoReference, undefined, false, "", "", { owner: "github", repo: "example " }, tmpDir, tmpDir, (0, codeql_1.getCachedCodeQL)(), tmpDir, gitHubVersion, sampleApiDetails, (0, feature_flags_1.createFeatureFlags)([]), (0, logging_1.getRunnerLogger)(true));
throw new Error("initConfig did not throw error"); throw new Error("initConfig did not throw error");
} }
catch (err) { catch (err) {
@@ -535,7 +538,7 @@ function queriesToResolvedQueryForm(queries) {
mockGetContents(dummyResponse); mockGetContents(dummyResponse);
const repoReference = "octo-org/codeql-config/config.yaml@main"; const repoReference = "octo-org/codeql-config/config.yaml@main";
try { try {
await configUtils.initConfig(undefined, undefined, undefined, repoReference, undefined, false, { owner: "github", repo: "example " }, tmpDir, tmpDir, (0, codeql_1.getCachedCodeQL)(), tmpDir, gitHubVersion, sampleApiDetails, (0, logging_1.getRunnerLogger)(true)); await configUtils.initConfig(undefined, undefined, undefined, repoReference, undefined, false, "", "", { owner: "github", repo: "example " }, tmpDir, tmpDir, (0, codeql_1.getCachedCodeQL)(), tmpDir, gitHubVersion, sampleApiDetails, (0, feature_flags_1.createFeatureFlags)([]), (0, logging_1.getRunnerLogger)(true));
throw new Error("initConfig did not throw error"); throw new Error("initConfig did not throw error");
} }
catch (err) { catch (err) {
@@ -552,7 +555,7 @@ function queriesToResolvedQueryForm(queries) {
}, },
}); });
try { try {
await configUtils.initConfig(undefined, undefined, undefined, undefined, undefined, false, { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, logging_1.getRunnerLogger)(true)); await configUtils.initConfig(undefined, undefined, undefined, undefined, undefined, false, "", "", { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, feature_flags_1.createFeatureFlags)([]), (0, logging_1.getRunnerLogger)(true));
throw new Error("initConfig did not throw error"); throw new Error("initConfig did not throw error");
} }
catch (err) { catch (err) {
@@ -564,7 +567,7 @@ function queriesToResolvedQueryForm(queries) {
return await util.withTmpDir(async (tmpDir) => { return await util.withTmpDir(async (tmpDir) => {
const languages = "rubbish,english"; const languages = "rubbish,english";
try { try {
await configUtils.initConfig(languages, undefined, undefined, undefined, undefined, false, { owner: "github", repo: "example " }, tmpDir, tmpDir, (0, codeql_1.getCachedCodeQL)(), tmpDir, gitHubVersion, sampleApiDetails, (0, logging_1.getRunnerLogger)(true)); await configUtils.initConfig(languages, undefined, undefined, undefined, undefined, false, "", "", { owner: "github", repo: "example " }, tmpDir, tmpDir, (0, codeql_1.getCachedCodeQL)(), tmpDir, gitHubVersion, sampleApiDetails, (0, feature_flags_1.createFeatureFlags)([]), (0, logging_1.getRunnerLogger)(true));
throw new Error("initConfig did not throw error"); throw new Error("initConfig did not throw error");
} }
catch (err) { catch (err) {
@@ -592,7 +595,7 @@ function queriesToResolvedQueryForm(queries) {
const configFile = path.join(tmpDir, "codeql-config.yaml"); const configFile = path.join(tmpDir, "codeql-config.yaml");
fs.writeFileSync(configFile, inputFileContents); fs.writeFileSync(configFile, inputFileContents);
const languages = "javascript"; const languages = "javascript";
const { packs } = await configUtils.initConfig(languages, undefined, undefined, configFile, undefined, false, { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, logging_1.getRunnerLogger)(true)); const { packs } = await configUtils.initConfig(languages, undefined, undefined, configFile, undefined, false, "", "", { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, feature_flags_1.createFeatureFlags)([]), (0, logging_1.getRunnerLogger)(true));
t.deepEqual(packs, { t.deepEqual(packs, {
[languages_1.Language.javascript]: [ [languages_1.Language.javascript]: [
{ {
@@ -631,7 +634,7 @@ function queriesToResolvedQueryForm(queries) {
fs.writeFileSync(configFile, inputFileContents); fs.writeFileSync(configFile, inputFileContents);
fs.mkdirSync(path.join(tmpDir, "foo")); fs.mkdirSync(path.join(tmpDir, "foo"));
const languages = "javascript,python,cpp"; const languages = "javascript,python,cpp";
const { packs, queries } = await configUtils.initConfig(languages, undefined, undefined, configFile, undefined, false, { owner: "github", repo: "example" }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, logging_1.getRunnerLogger)(true)); const { packs, queries } = await configUtils.initConfig(languages, undefined, undefined, configFile, undefined, false, "", "", { owner: "github", repo: "example" }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, feature_flags_1.createFeatureFlags)([]), (0, logging_1.getRunnerLogger)(true));
t.deepEqual(packs, { t.deepEqual(packs, {
[languages_1.Language.javascript]: [ [languages_1.Language.javascript]: [
{ {
@@ -684,7 +687,7 @@ function doInvalidInputTest(testName, inputFileContents, expectedErrorMessageGen
const inputFile = path.join(tmpDir, configFile); const inputFile = path.join(tmpDir, configFile);
fs.writeFileSync(inputFile, inputFileContents, "utf8"); fs.writeFileSync(inputFile, inputFileContents, "utf8");
try { try {
await configUtils.initConfig(languages, undefined, undefined, configFile, undefined, false, { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, logging_1.getRunnerLogger)(true)); await configUtils.initConfig(languages, undefined, undefined, configFile, undefined, false, "", "", { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, feature_flags_1.createFeatureFlags)([]), (0, logging_1.getRunnerLogger)(true));
throw new Error("initConfig did not throw error"); throw new Error("initConfig did not throw error");
} }
catch (err) { catch (err) {
@@ -867,6 +870,50 @@ parseInputAndConfigErrorMacro.title = (providedTitle) => `Parse Packs input and
(0, ava_1.default)("input with two languages", parseInputAndConfigErrorMacro, {}, "c/d", [languages_1.Language.cpp, languages_1.Language.csharp], /multi-language analysis/); (0, ava_1.default)("input with two languages", parseInputAndConfigErrorMacro, {}, "c/d", [languages_1.Language.cpp, languages_1.Language.csharp], /multi-language analysis/);
(0, ava_1.default)("input with + only", parseInputAndConfigErrorMacro, {}, " + ", [languages_1.Language.cpp], /remove the '\+'/); (0, ava_1.default)("input with + only", parseInputAndConfigErrorMacro, {}, " + ", [languages_1.Language.cpp], /remove the '\+'/);
(0, ava_1.default)("input with invalid pack name", parseInputAndConfigErrorMacro, {}, " xxx", [languages_1.Language.cpp], /"xxx" is not a valid pack/); (0, ava_1.default)("input with invalid pack name", parseInputAndConfigErrorMacro, {}, " xxx", [languages_1.Language.cpp], /"xxx" is not a valid pack/);
// errors async function mlPoweredQueriesMacro(t, codeQLVersion, isMlPoweredQueriesFlagEnabled, queriesInput, shouldRunMlPoweredQueries) {
// input w invalid pack name return await util.withTmpDir(async (tmpDir) => {
const codeQL = (0, codeql_1.setCodeQL)({
async getVersion() {
return codeQLVersion;
},
async resolveQueries() {
return {
byLanguage: {
javascript: { "fake-query.ql": {} },
},
noDeclaredLanguage: {},
multipleDeclaredLanguages: {},
};
},
});
const { packs } = await configUtils.initConfig("javascript", queriesInput, undefined, undefined, undefined, false, "", "", { owner: "github", repo: "example " }, tmpDir, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, feature_flags_1.createFeatureFlags)(isMlPoweredQueriesFlagEnabled
? [feature_flags_1.FeatureFlag.MlPoweredQueriesEnabled]
: []), (0, logging_1.getRunnerLogger)(true));
if (shouldRunMlPoweredQueries) {
t.deepEqual(packs, {
[languages_1.Language.javascript]: [
{
packName: "codeql/javascript-experimental-atm-queries",
version: "~0.0.2",
},
],
});
}
else {
t.deepEqual(packs, {});
}
});
}
mlPoweredQueriesMacro.title = (_providedTitle, codeQLVersion, isMlPoweredQueriesFlagEnabled, queriesInput, shouldRunMlPoweredQueries) => {
const queriesInputDescription = queriesInput
? `'queries: ${queriesInput}'`
: "default config";
return `ML-powered queries ${shouldRunMlPoweredQueries ? "are" : "aren't"} loaded for ${queriesInputDescription} using CLI v${codeQLVersion} when feature flag is ${isMlPoweredQueriesFlagEnabled ? "enabled" : "disabled"}`;
};
// macro, isMlPoweredQueriesFlagEnabled, queriesInput, shouldRunMlPoweredQueries
(0, ava_1.default)(mlPoweredQueriesMacro, "2.7.4", true, "security-extended", false);
(0, ava_1.default)(mlPoweredQueriesMacro, "2.7.5", false, "security-extended", false);
(0, ava_1.default)(mlPoweredQueriesMacro, "2.7.5", true, undefined, false);
(0, ava_1.default)(mlPoweredQueriesMacro, "2.7.5", true, "security-extended", true);
(0, ava_1.default)(mlPoweredQueriesMacro, "2.7.5", true, "security-and-quality", true);
//# sourceMappingURL=config-utils.test.js.map //# sourceMappingURL=config-utils.test.js.map
File diff suppressed because one or more lines are too long
+7 -19
View File
@@ -24,9 +24,10 @@ const fs = __importStar(require("fs"));
const actionsUtil = __importStar(require("./actions-util")); const actionsUtil = __importStar(require("./actions-util"));
const api_client_1 = require("./api-client"); const api_client_1 = require("./api-client");
const codeql_1 = require("./codeql"); const codeql_1 = require("./codeql");
const feature_flags_1 = require("./feature-flags");
const util = __importStar(require("./util")); const util = __importStar(require("./util"));
const util_1 = require("./util"); const util_1 = require("./util");
async function uploadDatabases(repositoryNwo, config, apiDetails, logger) { async function uploadDatabases(repositoryNwo, config, featureFlags, apiDetails, logger) {
if (actionsUtil.getRequiredInput("upload-database") !== "true") { if (actionsUtil.getRequiredInput("upload-database") !== "true") {
logger.debug("Database upload disabled in workflow. Skipping upload."); logger.debug("Database upload disabled in workflow. Skipping upload.");
return; return;
@@ -41,32 +42,19 @@ async function uploadDatabases(repositoryNwo, config, apiDetails, logger) {
logger.debug("Not analyzing default branch. Skipping upload."); logger.debug("Not analyzing default branch. Skipping upload.");
return; return;
} }
const client = (0, api_client_1.getApiClient)(apiDetails); if (!(await featureFlags.getValue(feature_flags_1.FeatureFlag.DatabaseUploadsEnabled))) {
let useUploadDomain; logger.debug("Repository is not opted in to database uploads. Skipping upload.");
try {
const response = await client.request("GET /repos/:owner/:repo/code-scanning/codeql/databases", {
owner: repositoryNwo.owner,
repo: repositoryNwo.repo,
});
useUploadDomain = response.data["uploads_domain_enabled"];
}
catch (e) {
if (util.isHTTPError(e) && e.status === 404) {
logger.debug("Repository is not opted in to database uploads. Skipping upload.");
}
else {
console.log(e);
logger.info(`Skipping database upload due to unknown error: ${e}`);
}
return; return;
} }
const client = (0, api_client_1.getApiClient)(apiDetails);
const codeql = await (0, codeql_1.getCodeQL)(config.codeQLCmd); const codeql = await (0, codeql_1.getCodeQL)(config.codeQLCmd);
const useUploadDomain = await featureFlags.getValue(feature_flags_1.FeatureFlag.UploadsDomainEnabled);
for (const language of config.languages) { for (const language of config.languages) {
// Upload the database bundle. // Upload the database bundle.
// Although we are uploading arbitrary file contents to the API, it's worth // Although we are uploading arbitrary file contents to the API, it's worth
// noting that it's the API's job to validate that the contents is acceptable. // noting that it's the API's job to validate that the contents is acceptable.
// This API method is available to anyone with write access to the repo. // This API method is available to anyone with write access to the repo.
const payload = fs.readFileSync(await (0, util_1.bundleDb)(config, language, codeql)); const payload = fs.readFileSync(await (0, util_1.bundleDb)(config, language, codeql, language));
try { try {
if (useUploadDomain) { if (useUploadDomain) {
await client.request(`POST https://uploads.github.com/repos/:owner/:repo/code-scanning/codeql/databases/:language?name=:name`, { await client.request(`POST https://uploads.github.com/repos/:owner/:repo/code-scanning/codeql/databases/:language?name=:name`, {
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"database-upload.js","sourceRoot":"","sources":["../src/database-upload.ts"],"names":[],"mappings":";;;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AM,IAAA,eAAQ,EAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,CACnD,CAAC;QACF,IAAI;YACF,IAAI,eAAe,EAAE;gBACnB,MAAM,MAAM,CAAC,OAAO,CAClB,wGAAwG,EACxG;oBACE,KAAK,EAAE,aAAa,CAAC,KAAK;oBAC1B,IAAI,EAAE,aAAa,CAAC,IAAI;oBACxB,QAAQ;oBACR,IAAI,EAAE,GAAG,QAAQ,WAAW;oBAC5B,IAAI,EAAE,OAAO;oBACb,OAAO,EAAE;wBACP,aAAa,EAAE,SAAS,UAAU,CAAC,IAAI,EAAE;qBAC1C;iBACF,CACF,CAAC;aACH;iBAAM;gBACL,MAAM,MAAM,CAAC,OAAO,CAClB,kEAAkE,EAClE;oBACE,KAAK,EAAE,aAAa,CAAC,KAAK;oBAC1B,IAAI,EAAE,aAAa,CAAC,IAAI;oBACxB,QAAQ;oBACR,IAAI,EAAE,OAAO;iBACd,CACF,CAAC;aACH;YACD,MAAM,CAAC,KAAK,CAAC,sCAAsC,QAAQ,EAAE,CAAC,CAAC;SAChE;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACf,4CAA4C;YAC5C,MAAM,CAAC,OAAO,CAAC,iCAAiC,QAAQ,KAAK,CAAC,EAAE,CAAC,CAAC;SACnE;KACF;AACH,CAAC;AA9ED,0CA8EC"}
+30 -81
View File
@@ -30,6 +30,7 @@ const actionsUtil = __importStar(require("./actions-util"));
const apiClient = __importStar(require("./api-client")); const apiClient = __importStar(require("./api-client"));
const codeql_1 = require("./codeql"); const codeql_1 = require("./codeql");
const database_upload_1 = require("./database-upload"); const database_upload_1 = require("./database-upload");
const feature_flags_1 = require("./feature-flags");
const languages_1 = require("./languages"); const languages_1 = require("./languages");
const testing_utils_1 = require("./testing-utils"); const testing_utils_1 = require("./testing-utils");
const util_1 = require("./util"); const util_1 = require("./util");
@@ -37,6 +38,10 @@ const util_1 = require("./util");
ava_1.default.beforeEach(() => { ava_1.default.beforeEach(() => {
(0, util_1.initializeEnvironment)(util_1.Mode.actions, "1.2.3"); (0, util_1.initializeEnvironment)(util_1.Mode.actions, "1.2.3");
}); });
const uploadToUploadsDomainFlags = (0, feature_flags_1.createFeatureFlags)([
feature_flags_1.FeatureFlag.DatabaseUploadsEnabled,
feature_flags_1.FeatureFlag.UploadsDomainEnabled,
]);
const testRepoName = { owner: "github", repo: "example" }; const testRepoName = { owner: "github", repo: "example" };
const testApiDetails = { const testApiDetails = {
auth: "1234", auth: "1234",
@@ -56,60 +61,23 @@ function getTestConfig(tmpDir) {
dbLocation: tmpDir, dbLocation: tmpDir,
packs: {}, packs: {},
debugMode: false, debugMode: false,
debugArtifactName: util_1.DEFAULT_DEBUG_ARTIFACT_NAME,
debugDatabaseName: util_1.DEFAULT_DEBUG_DATABASE_NAME,
}; };
} }
function getRecordingLogger(messages) { async function mockHttpRequests(featureFlags, databaseUploadStatusCode) {
return {
debug: (message) => {
messages.push({ type: "debug", message });
console.debug(message);
},
info: (message) => {
messages.push({ type: "info", message });
console.info(message);
},
warning: (message) => {
messages.push({ type: "warning", message });
console.warn(message);
},
error: (message) => {
messages.push({ type: "error", message });
console.error(message);
},
isDebug: () => true,
startGroup: () => undefined,
endGroup: () => undefined,
};
}
function mockHttpRequests(optInStatusCode, useUploadDomain, databaseUploadStatusCode) {
// Passing an auth token is required, so we just use a dummy value // Passing an auth token is required, so we just use a dummy value
const client = github.getOctokit("123"); const client = github.getOctokit("123");
const requestSpy = sinon.stub(client, "request"); const requestSpy = sinon.stub(client, "request");
const optInSpy = requestSpy.withArgs("GET /repos/:owner/:repo/code-scanning/codeql/databases"); const url = (await featureFlags.getValue(feature_flags_1.FeatureFlag.UploadsDomainEnabled))
if (optInStatusCode < 300) { ? "POST https://uploads.github.com/repos/:owner/:repo/code-scanning/codeql/databases/:language?name=:name"
optInSpy.resolves({ : "PUT /repos/:owner/:repo/code-scanning/codeql/databases/:language";
status: optInStatusCode, const databaseUploadSpy = requestSpy.withArgs(url);
data: { if (databaseUploadStatusCode < 300) {
useUploadDomain, databaseUploadSpy.resolves(undefined);
},
headers: {},
url: "GET /repos/:owner/:repo/code-scanning/codeql/databases",
});
} }
else { else {
optInSpy.throws(new util_1.HTTPError("some error message", optInStatusCode)); databaseUploadSpy.throws(new util_1.HTTPError("some error message", databaseUploadStatusCode));
}
if (databaseUploadStatusCode !== undefined) {
const url = useUploadDomain
? "POST https://uploads.github.com/repos/:owner/:repo/code-scanning/codeql/databases/:language?name=:name"
: "PUT /repos/:owner/:repo/code-scanning/codeql/databases/:language";
const databaseUploadSpy = requestSpy.withArgs(url);
if (databaseUploadStatusCode < 300) {
databaseUploadSpy.resolves(undefined);
}
else {
databaseUploadSpy.throws(new util_1.HTTPError("some error message", databaseUploadStatusCode));
}
} }
sinon.stub(apiClient, "getApiClient").value(() => client); sinon.stub(apiClient, "getApiClient").value(() => client);
} }
@@ -122,7 +90,7 @@ function mockHttpRequests(optInStatusCode, useUploadDomain, databaseUploadStatus
.returns("false"); .returns("false");
sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true); sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true);
const loggedMessages = []; const loggedMessages = [];
await (0, database_upload_1.uploadDatabases)(testRepoName, getTestConfig(tmpDir), testApiDetails, getRecordingLogger(loggedMessages)); await (0, database_upload_1.uploadDatabases)(testRepoName, getTestConfig(tmpDir), uploadToUploadsDomainFlags, testApiDetails, (0, testing_utils_1.getRecordingLogger)(loggedMessages));
t.assert(loggedMessages.find((v) => v.type === "debug" && t.assert(loggedMessages.find((v) => v.type === "debug" &&
v.message === "Database upload disabled in workflow. Skipping upload.") !== undefined); v.message === "Database upload disabled in workflow. Skipping upload.") !== undefined);
}); });
@@ -138,7 +106,7 @@ function mockHttpRequests(optInStatusCode, useUploadDomain, databaseUploadStatus
const config = getTestConfig(tmpDir); const config = getTestConfig(tmpDir);
config.gitHubVersion = { type: util_1.GitHubVariant.GHES, version: "3.0" }; config.gitHubVersion = { type: util_1.GitHubVariant.GHES, version: "3.0" };
const loggedMessages = []; const loggedMessages = [];
await (0, database_upload_1.uploadDatabases)(testRepoName, config, testApiDetails, getRecordingLogger(loggedMessages)); await (0, database_upload_1.uploadDatabases)(testRepoName, config, (0, feature_flags_1.createFeatureFlags)([]), testApiDetails, (0, testing_utils_1.getRecordingLogger)(loggedMessages));
t.assert(loggedMessages.find((v) => v.type === "debug" && t.assert(loggedMessages.find((v) => v.type === "debug" &&
v.message === "Not running against github.com. Skipping upload.") !== undefined); v.message === "Not running against github.com. Skipping upload.") !== undefined);
}); });
@@ -154,7 +122,7 @@ function mockHttpRequests(optInStatusCode, useUploadDomain, databaseUploadStatus
const config = getTestConfig(tmpDir); const config = getTestConfig(tmpDir);
config.gitHubVersion = { type: util_1.GitHubVariant.GHAE }; config.gitHubVersion = { type: util_1.GitHubVariant.GHAE };
const loggedMessages = []; const loggedMessages = [];
await (0, database_upload_1.uploadDatabases)(testRepoName, config, testApiDetails, getRecordingLogger(loggedMessages)); await (0, database_upload_1.uploadDatabases)(testRepoName, config, (0, feature_flags_1.createFeatureFlags)([]), testApiDetails, (0, testing_utils_1.getRecordingLogger)(loggedMessages));
t.assert(loggedMessages.find((v) => v.type === "debug" && t.assert(loggedMessages.find((v) => v.type === "debug" &&
v.message === "Not running against github.com. Skipping upload.") !== undefined); v.message === "Not running against github.com. Skipping upload.") !== undefined);
}); });
@@ -168,12 +136,12 @@ function mockHttpRequests(optInStatusCode, useUploadDomain, databaseUploadStatus
.returns("true"); .returns("true");
sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(false); sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(false);
const loggedMessages = []; const loggedMessages = [];
await (0, database_upload_1.uploadDatabases)(testRepoName, getTestConfig(tmpDir), testApiDetails, getRecordingLogger(loggedMessages)); await (0, database_upload_1.uploadDatabases)(testRepoName, getTestConfig(tmpDir), uploadToUploadsDomainFlags, testApiDetails, (0, testing_utils_1.getRecordingLogger)(loggedMessages));
t.assert(loggedMessages.find((v) => v.type === "debug" && t.assert(loggedMessages.find((v) => v.type === "debug" &&
v.message === "Not analyzing default branch. Skipping upload.") !== undefined); v.message === "Not analyzing default branch. Skipping upload.") !== undefined);
}); });
}); });
(0, ava_1.default)("Abort database upload if opt-in request returns 404", async (t) => { (0, ava_1.default)("Abort database upload if feature flag is disabled", async (t) => {
await (0, util_1.withTmpDir)(async (tmpDir) => { await (0, util_1.withTmpDir)(async (tmpDir) => {
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir); (0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
sinon sinon
@@ -181,40 +149,18 @@ function mockHttpRequests(optInStatusCode, useUploadDomain, databaseUploadStatus
.withArgs("upload-database") .withArgs("upload-database")
.returns("true"); .returns("true");
sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true); sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true);
mockHttpRequests(404);
(0, codeql_1.setCodeQL)({ (0, codeql_1.setCodeQL)({
async databaseBundle() { async databaseBundle() {
return; return;
}, },
}); });
const loggedMessages = []; const loggedMessages = [];
await (0, database_upload_1.uploadDatabases)(testRepoName, getTestConfig(tmpDir), testApiDetails, getRecordingLogger(loggedMessages)); await (0, database_upload_1.uploadDatabases)(testRepoName, getTestConfig(tmpDir), (0, feature_flags_1.createFeatureFlags)([feature_flags_1.FeatureFlag.UploadsDomainEnabled]), testApiDetails, (0, testing_utils_1.getRecordingLogger)(loggedMessages));
t.assert(loggedMessages.find((v) => v.type === "debug" && t.assert(loggedMessages.find((v) => v.type === "debug" &&
v.message === v.message ===
"Repository is not opted in to database uploads. Skipping upload.") !== undefined); "Repository is not opted in to database uploads. Skipping upload.") !== undefined);
}); });
}); });
(0, ava_1.default)("Abort database upload if opt-in request fails with something other than 404", async (t) => {
await (0, util_1.withTmpDir)(async (tmpDir) => {
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
sinon
.stub(actionsUtil, "getRequiredInput")
.withArgs("upload-database")
.returns("true");
sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true);
mockHttpRequests(500);
(0, codeql_1.setCodeQL)({
async databaseBundle() {
return;
},
});
const loggedMessages = [];
await (0, database_upload_1.uploadDatabases)(testRepoName, getTestConfig(tmpDir), testApiDetails, getRecordingLogger(loggedMessages));
t.assert(loggedMessages.find((v) => v.type === "info" &&
v.message ===
"Skipping database upload due to unknown error: Error: some error message") !== undefined);
});
});
(0, ava_1.default)("Don't crash if uploading a database fails", async (t) => { (0, ava_1.default)("Don't crash if uploading a database fails", async (t) => {
await (0, util_1.withTmpDir)(async (tmpDir) => { await (0, util_1.withTmpDir)(async (tmpDir) => {
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir); (0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
@@ -223,14 +169,17 @@ function mockHttpRequests(optInStatusCode, useUploadDomain, databaseUploadStatus
.withArgs("upload-database") .withArgs("upload-database")
.returns("true"); .returns("true");
sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true); sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true);
mockHttpRequests(200, false, 500); const featureFlags = (0, feature_flags_1.createFeatureFlags)([
feature_flags_1.FeatureFlag.DatabaseUploadsEnabled,
]);
await mockHttpRequests(featureFlags, 500);
(0, codeql_1.setCodeQL)({ (0, codeql_1.setCodeQL)({
async databaseBundle(_, outputFilePath) { async databaseBundle(_, outputFilePath) {
fs.writeFileSync(outputFilePath, ""); fs.writeFileSync(outputFilePath, "");
}, },
}); });
const loggedMessages = []; const loggedMessages = [];
await (0, database_upload_1.uploadDatabases)(testRepoName, getTestConfig(tmpDir), testApiDetails, getRecordingLogger(loggedMessages)); await (0, database_upload_1.uploadDatabases)(testRepoName, getTestConfig(tmpDir), featureFlags, testApiDetails, (0, testing_utils_1.getRecordingLogger)(loggedMessages));
t.assert(loggedMessages.find((v) => v.type === "warning" && t.assert(loggedMessages.find((v) => v.type === "warning" &&
v.message === v.message ===
"Failed to upload database for javascript: Error: some error message") !== undefined); "Failed to upload database for javascript: Error: some error message") !== undefined);
@@ -244,14 +193,14 @@ function mockHttpRequests(optInStatusCode, useUploadDomain, databaseUploadStatus
.withArgs("upload-database") .withArgs("upload-database")
.returns("true"); .returns("true");
sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true); sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true);
mockHttpRequests(200, false, 201); await mockHttpRequests(uploadToUploadsDomainFlags, 201);
(0, codeql_1.setCodeQL)({ (0, codeql_1.setCodeQL)({
async databaseBundle(_, outputFilePath) { async databaseBundle(_, outputFilePath) {
fs.writeFileSync(outputFilePath, ""); fs.writeFileSync(outputFilePath, "");
}, },
}); });
const loggedMessages = []; const loggedMessages = [];
await (0, database_upload_1.uploadDatabases)(testRepoName, getTestConfig(tmpDir), testApiDetails, getRecordingLogger(loggedMessages)); await (0, database_upload_1.uploadDatabases)(testRepoName, getTestConfig(tmpDir), uploadToUploadsDomainFlags, testApiDetails, (0, testing_utils_1.getRecordingLogger)(loggedMessages));
t.assert(loggedMessages.find((v) => v.type === "debug" && t.assert(loggedMessages.find((v) => v.type === "debug" &&
v.message === "Successfully uploaded database for javascript") !== undefined); v.message === "Successfully uploaded database for javascript") !== undefined);
}); });
@@ -264,14 +213,14 @@ function mockHttpRequests(optInStatusCode, useUploadDomain, databaseUploadStatus
.withArgs("upload-database") .withArgs("upload-database")
.returns("true"); .returns("true");
sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true); sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true);
mockHttpRequests(200, true, 201); await mockHttpRequests(uploadToUploadsDomainFlags, 201);
(0, codeql_1.setCodeQL)({ (0, codeql_1.setCodeQL)({
async databaseBundle(_, outputFilePath) { async databaseBundle(_, outputFilePath) {
fs.writeFileSync(outputFilePath, ""); fs.writeFileSync(outputFilePath, "");
}, },
}); });
const loggedMessages = []; const loggedMessages = [];
await (0, database_upload_1.uploadDatabases)(testRepoName, getTestConfig(tmpDir), testApiDetails, getRecordingLogger(loggedMessages)); await (0, database_upload_1.uploadDatabases)(testRepoName, getTestConfig(tmpDir), uploadToUploadsDomainFlags, testApiDetails, (0, testing_utils_1.getRecordingLogger)(loggedMessages));
t.assert(loggedMessages.find((v) => v.type === "debug" && t.assert(loggedMessages.find((v) => v.type === "debug" &&
v.message === "Successfully uploaded database for javascript") !== undefined); v.message === "Successfully uploaded database for javascript") !== undefined);
}); });
File diff suppressed because one or more lines are too long
+91
View File
@@ -0,0 +1,91 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createFeatureFlags = exports.GitHubFeatureFlags = exports.FeatureFlag = void 0;
const api_client_1 = require("./api-client");
const util = __importStar(require("./util"));
var FeatureFlag;
(function (FeatureFlag) {
FeatureFlag["DatabaseUploadsEnabled"] = "database_uploads_enabled";
FeatureFlag["MlPoweredQueriesEnabled"] = "ml_powered_queries_enabled";
FeatureFlag["UploadsDomainEnabled"] = "uploads_domain_enabled";
})(FeatureFlag = exports.FeatureFlag || (exports.FeatureFlag = {}));
class GitHubFeatureFlags {
constructor(gitHubVersion, apiDetails, repositoryNwo, logger) {
this.gitHubVersion = gitHubVersion;
this.apiDetails = apiDetails;
this.repositoryNwo = repositoryNwo;
this.logger = logger;
}
async getValue(flag) {
const response = (await this.getApiResponse())[flag];
if (response === undefined) {
this.logger.debug(`Feature flag '${flag}' undefined in API response, considering it disabled.`);
return false;
}
return response;
}
async preloadFeatureFlags() {
await this.getApiResponse();
}
async getApiResponse() {
const loadApiResponse = async () => {
// Do nothing when not running against github.com
if (this.gitHubVersion.type !== util.GitHubVariant.DOTCOM) {
this.logger.debug("Not running against github.com. Disabling all feature flags.");
return {};
}
const client = (0, api_client_1.getApiClient)(this.apiDetails);
try {
const response = await client.request("GET /repos/:owner/:repo/code-scanning/codeql-action/features", {
owner: this.repositoryNwo.owner,
repo: this.repositoryNwo.repo,
});
return response.data;
}
catch (e) {
// Some feature flags, such as `ml_powered_queries_enabled` affect the produced alerts.
// Considering these feature flags disabled in the event of a transient error could
// therefore lead to alert churn. As a result, we crash if we cannot determine the value of
// the feature flags.
throw new Error(`Encountered an error while trying to load feature flags: ${e}`);
}
};
const apiResponse = this.cachedApiResponse || (await loadApiResponse());
this.cachedApiResponse = apiResponse;
return apiResponse;
}
}
exports.GitHubFeatureFlags = GitHubFeatureFlags;
/**
* Create a feature flags instance with the specified set of enabled flags.
*
* This should be only used within tests.
*/
function createFeatureFlags(enabledFlags) {
return {
getValue: async (flag) => {
return enabledFlags.includes(flag);
},
};
}
exports.createFeatureFlags = createFeatureFlags;
//# sourceMappingURL=feature-flags.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"feature-flags.js","sourceRoot":"","sources":["../src/feature-flags.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA8D;AAG9D,6CAA+B;AAM/B,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,kEAAmD,CAAA;IACnD,qEAAsD,CAAA;IACtD,8DAA+C,CAAA;AACjD,CAAC,EAJW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAItB;AAUD,MAAa,kBAAkB;IAG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2F;gBAC3F,qBAAqB;gBACrB,MAAM,IAAI,KAAK,CACb,4DAA4D,CAAC,EAAE,CAChE,CAAC;aACH;QACH,CAAC,CAAC;QAEF,MAAM,WAAW,GAAG,IAAI,CAAC,iBAAiB,IAAI,CAAC,MAAM,eAAe,EAAE,CAAC,CAAC;QACxE,IAAI,CAAC,iBAAiB,GAAG,WAAW,CAAC;QACrC,OAAO,WAAW,CAAC;IACrB,CAAC;CACF;AA3DD,gDA2DC;AAED;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,YAA2B;IAC5D,OAAO;QACL,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YACvB,OAAO,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACrC,CAAC;KACF,CAAC;AACJ,CAAC;AAND,gDAMC"}
+98
View File
@@ -0,0 +1,98 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ava_1 = __importDefault(require("ava"));
const feature_flags_1 = require("./feature-flags");
const logging_1 = require("./logging");
const repository_1 = require("./repository");
const testing_utils_1 = require("./testing-utils");
const util_1 = require("./util");
(0, testing_utils_1.setupTests)(ava_1.default);
ava_1.default.beforeEach(() => {
(0, util_1.initializeEnvironment)(util_1.Mode.actions, "1.2.3");
});
const testApiDetails = {
auth: "1234",
url: "https://github.com",
};
const testRepositoryNwo = (0, repository_1.parseRepositoryNwo)("github/example");
const ALL_FEATURE_FLAGS_DISABLED_VARIANTS = [
{
description: "GHES",
gitHubVersion: { type: util_1.GitHubVariant.GHES, version: "3.0.0" },
},
{ description: "GHAE", gitHubVersion: { type: util_1.GitHubVariant.GHAE } },
];
for (const variant of ALL_FEATURE_FLAGS_DISABLED_VARIANTS) {
(0, ava_1.default)(`All feature flags are disabled if running against ${variant.description}`, async (t) => {
await (0, util_1.withTmpDir)(async (tmpDir) => {
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
const loggedMessages = [];
const featureFlags = new feature_flags_1.GitHubFeatureFlags(variant.gitHubVersion, testApiDetails, testRepositoryNwo, (0, testing_utils_1.getRecordingLogger)(loggedMessages));
for (const flag of Object.values(feature_flags_1.FeatureFlag)) {
t.assert((await featureFlags.getValue(flag)) === false);
}
t.assert(loggedMessages.find((v) => v.type === "debug" &&
v.message ===
"Not running against github.com. Disabling all feature flags.") !== undefined);
});
});
}
(0, ava_1.default)("Feature flags are disabled if they're not returned in API response", async (t) => {
await (0, util_1.withTmpDir)(async (tmpDir) => {
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
const loggedMessages = [];
const featureFlags = new feature_flags_1.GitHubFeatureFlags({ type: util_1.GitHubVariant.DOTCOM }, testApiDetails, testRepositoryNwo, (0, testing_utils_1.getRecordingLogger)(loggedMessages));
(0, testing_utils_1.mockFeatureFlagApiEndpoint)(200, {});
for (const flag of Object.values(feature_flags_1.FeatureFlag)) {
t.assert((await featureFlags.getValue(flag)) === false);
}
for (const featureFlag of [
"database_uploads_enabled",
"ml_powered_queries_enabled",
"uploads_domain_enabled",
]) {
t.assert(loggedMessages.find((v) => v.type === "debug" &&
v.message ===
`Feature flag '${featureFlag}' undefined in API response, considering it disabled.`) !== undefined);
}
});
});
(0, ava_1.default)("Feature flags exception is propagated if the API request errors", async (t) => {
await (0, util_1.withTmpDir)(async (tmpDir) => {
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
const featureFlags = new feature_flags_1.GitHubFeatureFlags({ type: util_1.GitHubVariant.DOTCOM }, testApiDetails, testRepositoryNwo, (0, logging_1.getRunnerLogger)(true));
(0, testing_utils_1.mockFeatureFlagApiEndpoint)(500, {});
await t.throwsAsync(async () => featureFlags.preloadFeatureFlags(), {
message: "Encountered an error while trying to load feature flags: Error: some error message",
});
});
});
const FEATURE_FLAGS = [
"database_uploads_enabled",
"ml_powered_queries_enabled",
"uploads_domain_enabled",
];
for (const featureFlag of FEATURE_FLAGS) {
(0, ava_1.default)(`Feature flag '${featureFlag}' is enabled if enabled in the API response`, async (t) => {
await (0, util_1.withTmpDir)(async (tmpDir) => {
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
const featureFlags = new feature_flags_1.GitHubFeatureFlags({ type: util_1.GitHubVariant.DOTCOM }, testApiDetails, testRepositoryNwo, (0, logging_1.getRunnerLogger)(true));
const expectedFeatureFlags = {};
for (const f of FEATURE_FLAGS) {
expectedFeatureFlags[f] = false;
}
expectedFeatureFlags[featureFlag] = true;
(0, testing_utils_1.mockFeatureFlagApiEndpoint)(200, expectedFeatureFlags);
const actualFeatureFlags = {
database_uploads_enabled: await featureFlags.getValue(feature_flags_1.FeatureFlag.DatabaseUploadsEnabled),
ml_powered_queries_enabled: await featureFlags.getValue(feature_flags_1.FeatureFlag.MlPoweredQueriesEnabled),
uploads_domain_enabled: await featureFlags.getValue(feature_flags_1.FeatureFlag.UploadsDomainEnabled),
};
t.deepEqual(actualFeatureFlags, expectedFeatureFlags);
});
});
}
//# sourceMappingURL=feature-flags.test.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"feature-flags.test.js","sourceRoot":"","sources":["../src/feature-flags.test.ts"],"names":[],"mappings":";;;;;AAAA,8CAAuB;AAGvB,mDAAkE;AAClE,uCAA4C;AAC5C,6CAAkD;AAClD,mDAMyB;AAEzB,iCAAgF;AAEhF,IAAA,0BAAU,EAAC,aAAI,CAAC,CAAC;AAEjB,aAAI,CAAC,UAAU,CAAC,GAAG,EAAE;IACnB,IAAA,4BAAqB,EAAC,WAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC/C,CAAC,CAAC,CAAC;AAEH,MAAM,cAAc,GAAqB;IACvC,IAAI,EAAE,MAAM;IACZ,GAAG,EAAE,oBAAoB;CAC1B,CAAC;AAEF,MAAM,iBAAiB,GAAG,IAAA,+BAAkB,EAAC,gBAAgB,CAAC,CAAC;AAE/D,MAAM,mCAAmC,GAGpC;IACH;QACE,WAAW,EAAE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oB,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;CACJ"}
+9 -1
View File
@@ -23,6 +23,7 @@ const path = __importStar(require("path"));
const core = __importStar(require("@actions/core")); const core = __importStar(require("@actions/core"));
const actions_util_1 = require("./actions-util"); const actions_util_1 = require("./actions-util");
const codeql_1 = require("./codeql"); const codeql_1 = require("./codeql");
const feature_flags_1 = require("./feature-flags");
const init_1 = require("./init"); const init_1 = require("./init");
const languages_1 = require("./languages"); const languages_1 = require("./languages");
const logging_1 = require("./logging"); const logging_1 = require("./logging");
@@ -78,6 +79,9 @@ async function run() {
}; };
const gitHubVersion = await (0, util_1.getGitHubVersion)(apiDetails); const gitHubVersion = await (0, util_1.getGitHubVersion)(apiDetails);
(0, util_1.checkGitHubVersionInRange)(gitHubVersion, logger, util_1.Mode.actions); (0, util_1.checkGitHubVersionInRange)(gitHubVersion, logger, util_1.Mode.actions);
const repositoryNwo = (0, repository_1.parseRepositoryNwo)((0, util_1.getRequiredEnvParam)("GITHUB_REPOSITORY"));
const featureFlags = new feature_flags_1.GitHubFeatureFlags(gitHubVersion, apiDetails, repositoryNwo, logger);
void featureFlags.preloadFeatureFlags();
try { try {
const workflowErrors = await (0, actions_util_1.validateWorkflow)(); const workflowErrors = await (0, actions_util_1.validateWorkflow)();
if (!(await (0, actions_util_1.sendStatusReport)(await (0, actions_util_1.createStatusReportBase)("init", "starting", startedAt, workflowErrors)))) { if (!(await (0, actions_util_1.sendStatusReport)(await (0, actions_util_1.createStatusReportBase)("init", "starting", startedAt, workflowErrors)))) {
@@ -87,7 +91,11 @@ async function run() {
codeql = initCodeQLResult.codeql; codeql = initCodeQLResult.codeql;
toolsVersion = initCodeQLResult.toolsVersion; toolsVersion = initCodeQLResult.toolsVersion;
await (0, util_1.enrichEnvironment)(util_1.Mode.actions, codeql); await (0, util_1.enrichEnvironment)(util_1.Mode.actions, codeql);
config = await (0, init_1.initConfig)((0, actions_util_1.getOptionalInput)("languages"), (0, actions_util_1.getOptionalInput)("queries"), (0, actions_util_1.getOptionalInput)("packs"), (0, actions_util_1.getOptionalInput)("config-file"), (0, actions_util_1.getOptionalInput)("db-location"), (0, actions_util_1.getOptionalInput)("debug") === "true", (0, repository_1.parseRepositoryNwo)((0, util_1.getRequiredEnvParam)("GITHUB_REPOSITORY")), (0, actions_util_1.getTemporaryDirectory)(), (0, util_1.getRequiredEnvParam)("RUNNER_TOOL_CACHE"), codeql, (0, util_1.getRequiredEnvParam)("GITHUB_WORKSPACE"), gitHubVersion, apiDetails, logger); config = await (0, init_1.initConfig)((0, actions_util_1.getOptionalInput)("languages"), (0, actions_util_1.getOptionalInput)("queries"), (0, actions_util_1.getOptionalInput)("packs"), (0, actions_util_1.getOptionalInput)("config-file"), (0, actions_util_1.getOptionalInput)("db-location"), (0, actions_util_1.getOptionalInput)("debug") === "true", (0, actions_util_1.getOptionalInput)("debug-artifact-name") || util_1.DEFAULT_DEBUG_ARTIFACT_NAME, (0, actions_util_1.getOptionalInput)("debug-database-name") || util_1.DEFAULT_DEBUG_DATABASE_NAME, repositoryNwo, (0, actions_util_1.getTemporaryDirectory)(), (0, util_1.getRequiredEnvParam)("RUNNER_TOOL_CACHE"), codeql, (0, util_1.getRequiredEnvParam)("GITHUB_WORKSPACE"), gitHubVersion, apiDetails, featureFlags, logger);
if (config.languages.some(languages_1.isTracedLanguage)) {
// We currently do not support tracing on Windows 11 and Windows Server 2022
(0, util_1.checkNotWindows11)();
}
if (config.languages.includes(languages_1.Language.python) && if (config.languages.includes(languages_1.Language.python) &&
(0, actions_util_1.getRequiredInput)("setup-python-dependencies") === "true") { (0, actions_util_1.getRequiredInput)("setup-python-dependencies") === "true") {
try { try {
File diff suppressed because one or more lines are too long
Generated
+2 -2
View File
@@ -38,9 +38,9 @@ async function initCodeQL(codeqlURL, apiDetails, tempDir, toolCacheDir, variant,
return { codeql, toolsVersion }; return { codeql, toolsVersion };
} }
exports.initCodeQL = initCodeQL; exports.initCodeQL = initCodeQL;
async function initConfig(languagesInput, queriesInput, packsInput, configFile, dbLocation, debugMode, repository, tempDir, toolCacheDir, codeQL, workspacePath, gitHubVersion, apiDetails, logger) { async function initConfig(languagesInput, queriesInput, packsInput, configFile, dbLocation, debugMode, debugArtifactName, debugDatabaseName, repository, tempDir, toolCacheDir, codeQL, workspacePath, gitHubVersion, apiDetails, featureFlags, logger) {
logger.startGroup("Load language configuration"); logger.startGroup("Load language configuration");
const config = await configUtils.initConfig(languagesInput, queriesInput, packsInput, configFile, dbLocation, debugMode, repository, tempDir, toolCacheDir, codeQL, workspacePath, gitHubVersion, apiDetails, logger); const config = await configUtils.initConfig(languagesInput, queriesInput, packsInput, configFile, dbLocation, debugMode, debugArtifactName, debugDatabaseName, repository, tempDir, toolCacheDir, codeQL, workspacePath, gitHubVersion, apiDetails, featureFlags, logger);
analysisPaths.printPathFiltersWarning(config, logger); analysisPaths.printPathFiltersWarning(config, logger);
logger.endGroup(); logger.endGroup();
return config; return config;
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAE7B,yEAA2D;AAC3D,kEAAoD;AAEpD,gEAAkD;AAElD,qCAA2E;AAC3E,4DAA8C;AAG9C,mDAAwE;AACxE,6CAA+B;AAC/B,iCAA4C;AAErC,KAAK,UAAU,UAAU,CAC9B,SAA6B,EAC7B,UAA4B,EAC5B,OAAe,EACf,YAAoB,EACpB,OAA2B,EAC3B,MAAc;IAEd,MAAM,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC;IACxC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,IAAA,oBAAW,EAChD,SAAS,EACT,UAAU,EACV,OAAO,EACP,YAAY,EACZ,OAAO,EACP,MAAM,EACN,IAAI,CACL,CAAC;IACF,MAAM,MAAM,CAAC,YAAY,EAAE,CAAC;IAC5B,MAAM,CAA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EAAE;YAChC,MAAM,IAAI,UAAU,CAAC,UAAU,CAAC,MAAM,SAAS,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE;gBACvE,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,mBAAmB,CAAC;aAC9C,CAAC,CAAC,IAAI,EAAE,CAAC;SACX;aAAM;YACL,MAAM,IAAI,UAAU,CAAC,UAAU,CAC7B,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAC7C,CAAC,IAAI,EAAE,CAAC;SACV;QACD,MAAM,MAAM,GAAG,0BAA0B,CAAC;QAC1C,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE;YAChC,MAAM,IAAI,UAAU,CAAC,UAAU,CAAC,MAAM,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;gBAC/D,IAAI;gBACJ,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC;gBAChC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;aAC/B,CAAC,CAAC,IAAI,EAAE,CAAC;SACX;aAAM;YACL,MAAM,IAAI,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,EAAE;gBAChE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;aAC/B,CAAC,CAAC,IAAI,EAAE,CAAC;SACX;KACF;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,CAAC,QAAQ,EAAE,CAAC;QAClB,MAAM,CAAC,OAAO,CACZ,gFAAgF,CAAC,IAAI;YACnF,qGAAqG;YACrG,oGAAoG;YACpG,iDAAiD,CACpD,CAAC;QACF,OAAO;KACR;IACD,MAAM,CAAC,QAAQ,EAAE,CAAC;AACpB,CAAC;AAtCD,8CAsCC"}
Generated
+2 -1
View File
@@ -31,6 +31,7 @@ const analyze_1 = require("./analyze");
const autobuild_1 = require("./autobuild"); const autobuild_1 = require("./autobuild");
const codeql_1 = require("./codeql"); const codeql_1 = require("./codeql");
const config_utils_1 = require("./config-utils"); const config_utils_1 = require("./config-utils");
const feature_flags_1 = require("./feature-flags");
const init_1 = require("./init"); const init_1 = require("./init");
const languages_1 = require("./languages"); const languages_1 = require("./languages");
const logging_1 = require("./logging"); const logging_1 = require("./logging");
@@ -163,7 +164,7 @@ program
} }
await (0, util_1.enrichEnvironment)(util_1.Mode.runner, codeql); await (0, util_1.enrichEnvironment)(util_1.Mode.runner, codeql);
const workspacePath = checkoutPath; const workspacePath = checkoutPath;
const config = await (0, init_1.initConfig)(cmd.languages, cmd.queries, cmd.packs, cmd.configFile, undefined, false, (0, repository_1.parseRepositoryNwo)(cmd.repository), tempDir, toolsDir, codeql, workspacePath, gitHubVersion, apiDetails, logger); const config = await (0, init_1.initConfig)(cmd.languages, cmd.queries, cmd.packs, cmd.configFile, undefined, false, "", "", (0, repository_1.parseRepositoryNwo)(cmd.repository), tempDir, toolsDir, codeql, workspacePath, gitHubVersion, apiDetails, (0, feature_flags_1.createFeatureFlags)([]), logger);
const sourceRoot = checkoutPath; const sourceRoot = checkoutPath;
const tracerConfig = await (0, init_1.runInit)(codeql, config, sourceRoot, parseTraceProcessName(), parseTraceProcessLevel()); const tracerConfig = await (0, init_1.runInit)(codeql, config, sourceRoot, parseTraceProcessName(), parseTraceProcessLevel());
if (tracerConfig === undefined) { if (tracerConfig === undefined) {
+1 -1
View File
File diff suppressed because one or more lines are too long
+48 -1
View File
@@ -19,9 +19,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result; return result;
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.setupActionsVars = exports.setupTests = void 0; exports.mockFeatureFlagApiEndpoint = exports.getRecordingLogger = exports.setupActionsVars = exports.setupTests = void 0;
const github = __importStar(require("@actions/github"));
const sinon = __importStar(require("sinon")); const sinon = __importStar(require("sinon"));
const apiClient = __importStar(require("./api-client"));
const CodeQL = __importStar(require("./codeql")); const CodeQL = __importStar(require("./codeql"));
const util_1 = require("./util");
function wrapOutput(context) { function wrapOutput(context) {
// Function signature taken from Socket.write. // Function signature taken from Socket.write.
// Note there are two overloads: // Note there are two overloads:
@@ -89,4 +92,48 @@ function setupActionsVars(tempDir, toolsDir) {
process.env["RUNNER_TOOL_CACHE"] = toolsDir; process.env["RUNNER_TOOL_CACHE"] = toolsDir;
} }
exports.setupActionsVars = setupActionsVars; exports.setupActionsVars = setupActionsVars;
function getRecordingLogger(messages) {
return {
debug: (message) => {
messages.push({ type: "debug", message });
console.debug(message);
},
info: (message) => {
messages.push({ type: "info", message });
console.info(message);
},
warning: (message) => {
messages.push({ type: "warning", message });
console.warn(message);
},
error: (message) => {
messages.push({ type: "error", message });
console.error(message);
},
isDebug: () => true,
startGroup: () => undefined,
endGroup: () => undefined,
};
}
exports.getRecordingLogger = getRecordingLogger;
/** Mock the HTTP request to the feature flags enablement API endpoint. */
function mockFeatureFlagApiEndpoint(responseStatusCode, response) {
// Passing an auth token is required, so we just use a dummy value
const client = github.getOctokit("123");
const requestSpy = sinon.stub(client, "request");
const optInSpy = requestSpy.withArgs("GET /repos/:owner/:repo/code-scanning/codeql-action/features");
if (responseStatusCode < 300) {
optInSpy.resolves({
status: responseStatusCode,
data: response,
headers: {},
url: "GET /repos/:owner/:repo/code-scanning/codeql-action/features",
});
}
else {
optInSpy.throws(new util_1.HTTPError("some error message", responseStatusCode));
}
sinon.stub(apiClient, "getApiClient").value(() => client);
}
exports.mockFeatureFlagApiEndpoint = mockFeatureFlagApiEndpoint;
//# sourceMappingURL=testing-utils.js.map //# sourceMappingURL=testing-utils.js.map
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"testing-utils.js","sourceRoot":"","sources":["../src/testing-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AACA,6CAA+B;AAE/B,iDAAmC;AASnC,SAAS,UAAU,CAAC,OAAoB;IACtC,8CAA8C;IAC9C,gCAAgC;IACh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AAK,CAAC,CAAC;IAExC,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAEjD,MAAM,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAClC,8DAA8D,CAC/D,CAAC;IACF,IAAI,kBAAkB,GAAG,GAAG,EAAE;QAC5B,QAAQ,CAAC,QAAQ,CAAC;YAChB,MAAM,EAAE,kBAAkB;YAC1B,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,EAAE;YACX,GAAG,EAAE,8DAA8D;SACpE,CAAC,CAAC;KACJ;SAAM;QACL,QAAQ,CAAC,MAAM,CAAC,IAAI,gBAAS,CAAC,oBAAoB,EAAE,kBAAkB,CAAC,CAAC,CAAC;KAC1E;IAED,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC;AAC5D,CAAC;AAxBD,gEAwBC"}
-8
View File
@@ -44,10 +44,6 @@ async function toolrunnerErrorCatcher(commandLine, args, matchers, options) {
if (((_a = options === null || options === void 0 ? void 0 : options.listeners) === null || _a === void 0 ? void 0 : _a.stdout) !== undefined) { if (((_a = options === null || options === void 0 ? void 0 : options.listeners) === null || _a === void 0 ? void 0 : _a.stdout) !== undefined) {
options.listeners.stdout(data); options.listeners.stdout(data);
} }
else {
// if no stdout listener was originally defined then we match default behavior of Toolrunner
process.stdout.write(data);
}
}, },
stderr: (data) => { stderr: (data) => {
var _a; var _a;
@@ -55,10 +51,6 @@ async function toolrunnerErrorCatcher(commandLine, args, matchers, options) {
if (((_a = options === null || options === void 0 ? void 0 : options.listeners) === null || _a === void 0 ? void 0 : _a.stderr) !== undefined) { if (((_a = options === null || options === void 0 ? void 0 : options.listeners) === null || _a === void 0 ? void 0 : _a.stderr) !== undefined) {
options.listeners.stderr(data); options.listeners.stderr(data);
} }
else {
// if no stderr listener was originally defined then we match default behavior of Toolrunner
process.stderr.write(data);
}
}, },
}; };
// we capture the original return code or error so that if no match is found we can duplicate the behavior // we capture the original return code or error so that if no match is found we can duplicate the behavior
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"toolrunner-error-catcher.js","sourceRoot":"","sources":["../src/toolrunner-error-catcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AACA,yEAA2D;AAC3D,kEAAoD;AAIpD;;;;;;;;;;GAUG;AACI,KAAK,UAAU,sBAAsB,CAC1C,WAAmB,EACnB,IAAe,EACf,QAAyB,EACzB,OAAwB;;IAExB,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,MAAM,GAAG,EAAE,CAAC;IAEhB,MAAM,SAAS,GAAG;QAChB,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE;;YACvB,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC1B,IAAI,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,0CAAE,MAAM,MAAK,SAAS,EAAE;gBAC5C,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;aAChC;iBAAM;gBACL,4FAA4F;gBAC5F,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;aAC5B;QACH,CAAC;QACD,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE;;YACvB,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC1B,IAAI,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,0CAAE,MAAM,MAAK,SAAS,EAAE;gBAC5C,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;aAChC;iBAAM;gBACL,4FAA4F;gBAC5F,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;aAC5B;QACH,CAAC;KACF,CAAC;IAEF,0GAA0G;IAC1G,IAAI,WAA2B,CAAC;IAChC,IAAI;QACF,WAAW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AAC;IAE1C,IAAI,QAAQ,EAAE;QACZ,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;YAC9B,IACE,OAAO,CAAC,QAAQ,KAAK,WAAW;iBAChC,MAAA,OAAO,CAAC,WAAW,0CAAE,IAAI,CAAC,MAAM,CAAC,CAAA;iBACjC,MAAA,OAAO,CAAC,WAAW,0CAAE,IAAI,CAAC,MAAM,CAAC,CAAA,EACjC;gBACA,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;aAClC;SACF;KACF;IAED,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;QACnC,qFAAqF;QACrF,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,gBAAgB,EAAE;YAC7B,OAAO,WAAW,CAAC;SACpB;aAAM;YACL,MAAM,IAAI,KAAK,CACb,gBAAgB,WAAW,2BAA2B,WAAW,EAAE,CACpE,CAAC;SACH;KACF;SAAM;QACL,MAAM,WAAW,CAAC;KACnB;AACH,CAAC;AAnED,wDAmEC"}
+2
View File
@@ -45,6 +45,8 @@ function getTestConfig(tmpDir) {
dbLocation: path.resolve(tmpDir, "codeql_databases"), dbLocation: path.resolve(tmpDir, "codeql_databases"),
packs: {}, packs: {},
debugMode: false, debugMode: false,
debugArtifactName: util.DEFAULT_DEBUG_ARTIFACT_NAME,
debugDatabaseName: util.DEFAULT_DEBUG_DATABASE_NAME,
}; };
} }
// A very minimal setup // A very minimal setup
File diff suppressed because one or more lines are too long
Generated
+16 -6
View File
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.isGoodVersion = exports.delay = exports.bundleDb = exports.codeQlVersionAbove = exports.isHTTPError = exports.HTTPError = exports.getRequiredEnvParam = exports.isActions = exports.getMode = exports.enrichEnvironment = exports.initializeEnvironment = exports.Mode = exports.assertNever = exports.getGitHubAuth = exports.apiVersionInRange = exports.DisallowedAPIVersionReason = exports.checkGitHubVersionInRange = exports.getGitHubVersion = exports.GitHubVariant = exports.parseGitHubUrl = exports.getCodeQLDatabasePath = exports.getThreadsFlag = exports.getThreadsFlagValue = exports.getAddSnippetsFlag = exports.getMemoryFlag = exports.getMemoryFlagValue = exports.withTmpDir = exports.getToolNames = exports.getExtraOptionsEnvParam = exports.DEBUG_ARTIFACT_NAME = exports.GITHUB_DOTCOM_URL = void 0; exports.checkNotWindows11 = exports.isGoodVersion = exports.delay = exports.bundleDb = exports.codeQlVersionAbove = exports.isHTTPError = exports.HTTPError = exports.getRequiredEnvParam = exports.isActions = exports.getMode = exports.enrichEnvironment = exports.initializeEnvironment = exports.Mode = exports.assertNever = exports.getGitHubAuth = exports.apiVersionInRange = exports.DisallowedAPIVersionReason = exports.checkGitHubVersionInRange = exports.getGitHubVersion = exports.GitHubVariant = exports.parseGitHubUrl = exports.getCodeQLDatabasePath = exports.getThreadsFlag = exports.getThreadsFlagValue = exports.getAddSnippetsFlag = exports.getMemoryFlag = exports.getMemoryFlagValue = exports.withTmpDir = exports.getToolNames = exports.getExtraOptionsEnvParam = exports.DEFAULT_DEBUG_DATABASE_NAME = exports.DEFAULT_DEBUG_ARTIFACT_NAME = exports.GITHUB_DOTCOM_URL = void 0;
const fs = __importStar(require("fs")); const fs = __importStar(require("fs"));
const os = __importStar(require("os")); const os = __importStar(require("os"));
const path = __importStar(require("path")); const path = __importStar(require("path"));
@@ -42,9 +42,13 @@ const BROKEN_VERSIONS = ["0.0.0-20211207"];
*/ */
exports.GITHUB_DOTCOM_URL = "https://github.com"; exports.GITHUB_DOTCOM_URL = "https://github.com";
/** /**
* Name of the debugging artifact. * Default name of the debugging artifact.
*/ */
exports.DEBUG_ARTIFACT_NAME = "debug-artifacts"; exports.DEFAULT_DEBUG_ARTIFACT_NAME = "debug-artifacts";
/**
* Default name of the database in the debugging artifact.
*/
exports.DEFAULT_DEBUG_DATABASE_NAME = "db";
/** /**
* Get the extra options for the codeql commands. * Get the extra options for the codeql commands.
*/ */
@@ -492,9 +496,9 @@ async function codeQlVersionAbove(codeql, requiredVersion) {
} }
exports.codeQlVersionAbove = codeQlVersionAbove; exports.codeQlVersionAbove = codeQlVersionAbove;
// Create a bundle for the given DB, if it doesn't already exist // Create a bundle for the given DB, if it doesn't already exist
async function bundleDb(config, language, codeql) { async function bundleDb(config, language, codeql, dbName) {
const databasePath = getCodeQLDatabasePath(config, language); const databasePath = getCodeQLDatabasePath(config, language);
const databaseBundlePath = path.resolve(config.dbLocation, `${databasePath}.zip`); const databaseBundlePath = path.resolve(config.dbLocation, `${dbName}.zip`);
// For a tiny bit of added safety, delete the file if it exists. // For a tiny bit of added safety, delete the file if it exists.
// The file is probably from an earlier call to this function, either // The file is probably from an earlier call to this function, either
// as part of this action step or a previous one, but it could also be // as part of this action step or a previous one, but it could also be
@@ -503,7 +507,7 @@ async function bundleDb(config, language, codeql) {
if (fs.existsSync(databaseBundlePath)) { if (fs.existsSync(databaseBundlePath)) {
await (0, del_1.default)(databaseBundlePath, { force: true }); await (0, del_1.default)(databaseBundlePath, { force: true });
} }
await codeql.databaseBundle(databasePath, databaseBundlePath); await codeql.databaseBundle(databasePath, databaseBundlePath, dbName);
return databaseBundlePath; return databaseBundlePath;
} }
exports.bundleDb = bundleDb; exports.bundleDb = bundleDb;
@@ -515,4 +519,10 @@ function isGoodVersion(versionSpec) {
return !BROKEN_VERSIONS.includes(versionSpec); return !BROKEN_VERSIONS.includes(versionSpec);
} }
exports.isGoodVersion = isGoodVersion; exports.isGoodVersion = isGoodVersion;
function checkNotWindows11() {
if (os.platform() === "win32" && semver.gte(os.release(), "10.0.20348")) {
throw new Error("Tracing builds with CodeQL is currently not supported on Windows 11 and Windows Server 2022. Please modify your Actions workflow to use an earlier version of Windows for this job, for example by setting `runs-on: windows-2019`.");
}
}
exports.checkNotWindows11 = checkNotWindows11;
//# sourceMappingURL=util.js.map //# sourceMappingURL=util.js.map
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "codeql", "name": "codeql",
"version": "1.0.26", "version": "1.0.28",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "codeql", "name": "codeql",
"version": "1.0.26", "version": "1.0.28",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "codeql", "name": "codeql",
"version": "1.0.26", "version": "1.0.28",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/artifact": "^0.5.2", "@actions/artifact": "^0.5.2",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "codeql", "name": "codeql",
"version": "1.0.26", "version": "1.0.28",
"private": true, "private": true,
"description": "CodeQL action", "description": "CodeQL action",
"scripts": { "scripts": {
+4 -4
View File
@@ -2,12 +2,12 @@ name: "Debug artifact upload"
description: "Checks that debugging artifacts are correctly uploaded" description: "Checks that debugging artifacts are correctly uploaded"
os: ["ubuntu-latest", "macos-latest"] os: ["ubuntu-latest", "macos-latest"]
steps: steps:
- name: Initialize dotnet
run: dotnet restore
- uses: ./../action/init - uses: ./../action/init
with: with:
tools: ${{ steps.prepare-test.outputs.tools-url }} tools: ${{ steps.prepare-test.outputs.tools-url }}
debug: true debug: true
debug-artifact-name: "my-debug-artifacts"
debug-database-name: "my-db"
- name: Build code - name: Build code
shell: bash shell: bash
run: ./build.sh run: ./build.sh
@@ -15,7 +15,7 @@ steps:
id: analysis id: analysis
- uses: actions/download-artifact@v2 - uses: actions/download-artifact@v2
with: with:
name: debug-artifacts-${{ matrix.os }}-${{ matrix.version }} name: my-debug-artifacts-${{ matrix.os }}-${{ matrix.version }}
- shell: bash - shell: bash
run: | run: |
LANGUAGES="cpp csharp go java javascript python" LANGUAGES="cpp csharp go java javascript python"
@@ -25,7 +25,7 @@ steps:
echo "Missing a SARIF file for $language" echo "Missing a SARIF file for $language"
exit 1 exit 1
fi fi
if [[ ! -f "$language.zip" ]] ; then if [[ ! -f "my-db-$language.zip" ]] ; then
echo "Missing a database bundle for $language" echo "Missing a database bundle for $language"
exit 1 exit 1
fi fi
-2
View File
@@ -1,8 +1,6 @@
name: "Go: Custom queries" name: "Go: Custom queries"
description: "Checks that Go works in conjunction with a config file specifying custom queries" description: "Checks that Go works in conjunction with a config file specifying custom queries"
steps: steps:
- name: Initialize dotnet
run: dotnet restore
- uses: actions/setup-go@v2 - uses: actions/setup-go@v2
with: with:
go-version: "^1.13.1" go-version: "^1.13.1"
@@ -2,8 +2,6 @@ name: "Multi-language repository"
description: "An end-to-end integration test of a multi-language repository using automatic language detection" description: "An end-to-end integration test of a multi-language repository using automatic language detection"
os: ["ubuntu-latest", "macos-latest"] os: ["ubuntu-latest", "macos-latest"]
steps: steps:
- name: Initialize dotnet
run: dotnet restore
- uses: ./../action/init - uses: ./../action/init
with: with:
db-location: "${{ runner.temp }}/customDbLocation" db-location: "${{ runner.temp }}/customDbLocation"
@@ -3,8 +3,6 @@ description: "Checks that specifying packages using a combination of a config fi
versions: ["nightly-20210831"] # This CLI version is known to work with package used in this test versions: ["nightly-20210831"] # This CLI version is known to work with package used in this test
os: ["ubuntu-latest", "macos-latest"] os: ["ubuntu-latest", "macos-latest"]
steps: steps:
- name: Initialize dotnet
run: dotnet restore
- uses: ./../action/init - uses: ./../action/init
with: with:
config-file: ".github/codeql/codeql-config-packaging3.yml" config-file: ".github/codeql/codeql-config-packaging3.yml"
-2
View File
@@ -3,8 +3,6 @@ description: "Checks that specifying packages using only a config file works"
versions: ["nightly-20210831"] # This CLI version is known to work with package used in this test versions: ["nightly-20210831"] # This CLI version is known to work with package used in this test
os: ["ubuntu-latest", "macos-latest"] os: ["ubuntu-latest", "macos-latest"]
steps: steps:
- name: Initialize dotnet
run: dotnet restore
- uses: ./../action/init - uses: ./../action/init
with: with:
config-file: ".github/codeql/codeql-config-packaging.yml" config-file: ".github/codeql/codeql-config-packaging.yml"
-2
View File
@@ -3,8 +3,6 @@ description: "Checks that specifying packages using the input to the Action work
versions: ["nightly-20210831"] # This CLI version is known to work with package used in this test versions: ["nightly-20210831"] # This CLI version is known to work with package used in this test
os: ["ubuntu-latest", "macos-latest"] os: ["ubuntu-latest", "macos-latest"]
steps: steps:
- name: Initialize dotnet
run: dotnet restore
- uses: ./../action/init - uses: ./../action/init
with: with:
config-file: ".github/codeql/codeql-config-packaging2.yml" config-file: ".github/codeql/codeql-config-packaging2.yml"
-2
View File
@@ -1,8 +1,6 @@
name: "Remote config file" name: "Remote config file"
description: "Checks that specifying packages using only a config file works" description: "Checks that specifying packages using only a config file works"
steps: steps:
- name: Initialize dotnet
run: dotnet restore
- uses: ./../action/init - uses: ./../action/init
with: with:
tools: ${{ steps.prepare-test.outputs.tools-url }} tools: ${{ steps.prepare-test.outputs.tools-url }}
-2
View File
@@ -3,8 +3,6 @@ description: "Tests a split-up workflow in which we first build a database and l
versions: ["nightly-20210831"] # This CLI version is known to work with package used in this test versions: ["nightly-20210831"] # This CLI version is known to work with package used in this test
os: ["ubuntu-latest", "macos-latest"] os: ["ubuntu-latest", "macos-latest"]
steps: steps:
- name: Initialize dotnet
run: dotnet restore
- uses: ./../action/init - uses: ./../action/init
with: with:
config-file: ".github/codeql/codeql-config-packaging3.yml" config-file: ".github/codeql/codeql-config-packaging3.yml"
-2
View File
@@ -3,8 +3,6 @@ description: "Tests using a CodeQL bundle from a local file rather than a URL"
versions: ["nightly-latest"] versions: ["nightly-latest"]
os: ["ubuntu-latest"] os: ["ubuntu-latest"]
steps: steps:
- name: Initialize dotnet
run: dotnet restore
- name: Fetch a CodeQL bundle - name: Fetch a CodeQL bundle
shell: bash shell: bash
env: env:
-2
View File
@@ -2,8 +2,6 @@ name: "Test unsetting environment variables"
description: "An end-to-end integration test that unsets some environment variables" description: "An end-to-end integration test that unsets some environment variables"
os: ["ubuntu-latest"] os: ["ubuntu-latest"]
steps: steps:
- name: Initialize dotnet
run: dotnet restore
- uses: ./../action/init - uses: ./../action/init
with: with:
db-location: "${{ runner.temp }}/customDbLocation" db-location: "${{ runner.temp }}/customDbLocation"
+2 -2
View File
@@ -5,8 +5,8 @@ py -3 -m pip install --user --upgrade pip setuptools wheel
# virtualenv is a bit nicer for setting up virtual environment, since it will provide up-to-date versions of # virtualenv is a bit nicer for setting up virtual environment, since it will provide up-to-date versions of
# pip/setuptools/wheel which basic `python3 -m venv venv` won't # pip/setuptools/wheel which basic `python3 -m venv venv` won't
py -2 -m pip install --user virtualenv py -2 -m pip install --user 'virtualenv<20.11'
py -3 -m pip install --user virtualenv py -3 -m pip install --user 'virtualenv<20.11'
# poetry 1.0.10 has error (https://github.com/python-poetry/poetry/issues/2711) # poetry 1.0.10 has error (https://github.com/python-poetry/poetry/issues/2711)
py -3 -m pip install --user poetry!=1.0.10 py -3 -m pip install --user poetry!=1.0.10
+2 -2
View File
@@ -15,7 +15,7 @@ python3 -m pip install --user --upgrade pip setuptools wheel
# virtualenv is a bit nicer for setting up virtual environment, since it will provide up-to-date versions of # virtualenv is a bit nicer for setting up virtual environment, since it will provide up-to-date versions of
# pip/setuptools/wheel which basic `python3 -m venv venv` won't # pip/setuptools/wheel which basic `python3 -m venv venv` won't
python3 -m pip install --user virtualenv python3 -m pip install --user 'virtualenv<20.11'
# We install poetry with pip instead of the recommended way, since the recommended way # We install poetry with pip instead of the recommended way, since the recommended way
# caused some problem since `poetry run` gives output like: # caused some problem since `poetry run` gives output like:
@@ -35,5 +35,5 @@ if command -v python2 &> /dev/null; then
python2 -m pip install --user --upgrade pip setuptools wheel python2 -m pip install --user --upgrade pip setuptools wheel
python2 -m pip install --user virtualenv python2 -m pip install --user 'virtualenv<20.11'
fi fi
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "codeql-runner", "name": "codeql-runner",
"version": "1.0.26", "version": "1.0.28",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "codeql-runner", "name": "codeql-runner",
"version": "1.0.26", "version": "1.0.28",
"private": true, "private": true,
"description": "CodeQL runner", "description": "CodeQL runner",
"scripts": { "scripts": {
+6
View File
@@ -23,6 +23,8 @@ test("emptyPaths", async (t) => {
dbLocation: path.resolve(tmpDir, "codeql_databases"), dbLocation: path.resolve(tmpDir, "codeql_databases"),
packs: {}, packs: {},
debugMode: false, debugMode: false,
debugArtifactName: util.DEFAULT_DEBUG_ARTIFACT_NAME,
debugDatabaseName: util.DEFAULT_DEBUG_DATABASE_NAME,
}; };
analysisPaths.includeAndExcludeAnalysisPaths(config); analysisPaths.includeAndExcludeAnalysisPaths(config);
t.is(process.env["LGTM_INDEX_INCLUDE"], undefined); t.is(process.env["LGTM_INDEX_INCLUDE"], undefined);
@@ -46,6 +48,8 @@ test("nonEmptyPaths", async (t) => {
dbLocation: path.resolve(tmpDir, "codeql_databases"), dbLocation: path.resolve(tmpDir, "codeql_databases"),
packs: {}, packs: {},
debugMode: false, debugMode: false,
debugArtifactName: util.DEFAULT_DEBUG_ARTIFACT_NAME,
debugDatabaseName: util.DEFAULT_DEBUG_DATABASE_NAME,
}; };
analysisPaths.includeAndExcludeAnalysisPaths(config); analysisPaths.includeAndExcludeAnalysisPaths(config);
t.is(process.env["LGTM_INDEX_INCLUDE"], "path1\npath2"); t.is(process.env["LGTM_INDEX_INCLUDE"], "path1\npath2");
@@ -73,6 +77,8 @@ test("exclude temp dir", async (t) => {
dbLocation: path.resolve(tempDir, "codeql_databases"), dbLocation: path.resolve(tempDir, "codeql_databases"),
packs: {}, packs: {},
debugMode: false, debugMode: false,
debugArtifactName: util.DEFAULT_DEBUG_ARTIFACT_NAME,
debugDatabaseName: util.DEFAULT_DEBUG_DATABASE_NAME,
}; };
analysisPaths.includeAndExcludeAnalysisPaths(config); analysisPaths.includeAndExcludeAnalysisPaths(config);
t.is(process.env["LGTM_INDEX_INCLUDE"], undefined); t.is(process.env["LGTM_INDEX_INCLUDE"], undefined);
+7 -1
View File
@@ -4,7 +4,11 @@ import * as sinon from "sinon";
import * as actionsUtil from "./actions-util"; import * as actionsUtil from "./actions-util";
import * as analyze from "./analyze"; import * as analyze from "./analyze";
import * as configUtils from "./config-utils"; import * as configUtils from "./config-utils";
import { setupTests, setupActionsVars } from "./testing-utils"; import {
setupTests,
setupActionsVars,
mockFeatureFlagApiEndpoint,
} from "./testing-utils";
import * as util from "./util"; import * as util from "./util";
setupTests(test); setupTests(test);
@@ -25,6 +29,7 @@ test("analyze action with RAM & threads from environment variables", async (t) =
.resolves({} as actionsUtil.StatusReportBase); .resolves({} as actionsUtil.StatusReportBase);
sinon.stub(actionsUtil, "sendStatusReport").resolves(true); sinon.stub(actionsUtil, "sendStatusReport").resolves(true);
sinon.stub(configUtils, "getConfig").resolves({ sinon.stub(configUtils, "getConfig").resolves({
gitHubVersion: { type: util.GitHubVariant.DOTCOM },
languages: [], languages: [],
} as unknown as configUtils.Config); } as unknown as configUtils.Config);
const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput"); const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput");
@@ -33,6 +38,7 @@ test("analyze action with RAM & threads from environment variables", async (t) =
const optionalInputStub = sinon.stub(actionsUtil, "getOptionalInput"); const optionalInputStub = sinon.stub(actionsUtil, "getOptionalInput");
optionalInputStub.withArgs("cleanup-level").returns("none"); optionalInputStub.withArgs("cleanup-level").returns("none");
setupActionsVars(tmpDir, tmpDir); setupActionsVars(tmpDir, tmpDir);
mockFeatureFlagApiEndpoint(200, {});
// When there are no action inputs for RAM and threads, the action uses // When there are no action inputs for RAM and threads, the action uses
// environment variables (passed down from the init action) to set RAM and // environment variables (passed down from the init action) to set RAM and
+7 -1
View File
@@ -4,7 +4,11 @@ import * as sinon from "sinon";
import * as actionsUtil from "./actions-util"; import * as actionsUtil from "./actions-util";
import * as analyze from "./analyze"; import * as analyze from "./analyze";
import * as configUtils from "./config-utils"; import * as configUtils from "./config-utils";
import { setupTests, setupActionsVars } from "./testing-utils"; import {
setupTests,
setupActionsVars,
mockFeatureFlagApiEndpoint,
} from "./testing-utils";
import * as util from "./util"; import * as util from "./util";
setupTests(test); setupTests(test);
@@ -25,6 +29,7 @@ test("analyze action with RAM & threads from action inputs", async (t) => {
.resolves({} as actionsUtil.StatusReportBase); .resolves({} as actionsUtil.StatusReportBase);
sinon.stub(actionsUtil, "sendStatusReport").resolves(true); sinon.stub(actionsUtil, "sendStatusReport").resolves(true);
sinon.stub(configUtils, "getConfig").resolves({ sinon.stub(configUtils, "getConfig").resolves({
gitHubVersion: { type: util.GitHubVariant.DOTCOM },
languages: [], languages: [],
} as unknown as configUtils.Config); } as unknown as configUtils.Config);
const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput"); const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput");
@@ -33,6 +38,7 @@ test("analyze action with RAM & threads from action inputs", async (t) => {
const optionalInputStub = sinon.stub(actionsUtil, "getOptionalInput"); const optionalInputStub = sinon.stub(actionsUtil, "getOptionalInput");
optionalInputStub.withArgs("cleanup-level").returns("none"); optionalInputStub.withArgs("cleanup-level").returns("none");
setupActionsVars(tmpDir, tmpDir); setupActionsVars(tmpDir, tmpDir);
mockFeatureFlagApiEndpoint(200, {});
process.env["CODEQL_THREADS"] = "1"; process.env["CODEQL_THREADS"] = "1";
process.env["CODEQL_RAM"] = "4992"; process.env["CODEQL_RAM"] = "4992";
+65 -17
View File
@@ -15,12 +15,13 @@ import {
import { CODEQL_VERSION_NEW_TRACING, getCodeQL } from "./codeql"; import { CODEQL_VERSION_NEW_TRACING, getCodeQL } from "./codeql";
import { Config, getConfig } from "./config-utils"; import { Config, getConfig } from "./config-utils";
import { uploadDatabases } from "./database-upload"; import { uploadDatabases } from "./database-upload";
import { GitHubFeatureFlags } from "./feature-flags";
import { getActionsLogger } from "./logging"; import { getActionsLogger } from "./logging";
import { parseRepositoryNwo } from "./repository"; import { parseRepositoryNwo } from "./repository";
import * as upload_lib from "./upload-lib"; import * as upload_lib from "./upload-lib";
import { UploadResult } from "./upload-lib"; import { UploadResult } from "./upload-lib";
import * as util from "./util"; import * as util from "./util";
import { bundleDb, codeQlVersionAbove, DEBUG_ARTIFACT_NAME } from "./util"; import { bundleDb, codeQlVersionAbove } from "./util";
// eslint-disable-next-line import/no-commonjs // eslint-disable-next-line import/no-commonjs
const pkg = require("../package.json"); const pkg = require("../package.json");
@@ -99,6 +100,23 @@ async function run() {
const memory = util.getMemoryFlag( const memory = util.getMemoryFlag(
actionsUtil.getOptionalInput("ram") || process.env["CODEQL_RAM"] actionsUtil.getOptionalInput("ram") || process.env["CODEQL_RAM"]
); );
const repositoryNwo = parseRepositoryNwo(
util.getRequiredEnvParam("GITHUB_REPOSITORY")
);
const featureFlags = new GitHubFeatureFlags(
config.gitHubVersion,
apiDetails,
repositoryNwo,
logger
);
// We currently perform an API request in both the `init` and `analyze` Actions to determine
// what feature flags are enabled. At the time of writing, this redundant API call is acceptable
// to us, but if we wanted to avoid it, we could do so by serializing the feature flags as part
// of the config file.
void featureFlags.preloadFeatureFlags();
await runFinalize(outputDir, threads, memory, config, logger); await runFinalize(outputDir, threads, memory, config, logger);
if (actionsUtil.getRequiredInput("skip-queries") !== "true") { if (actionsUtil.getRequiredInput("skip-queries") !== "true") {
runStats = await runQueries( runStats = await runQueries(
@@ -117,7 +135,8 @@ async function run() {
config.languages.map((lang) => config.languages.map((lang) =>
path.resolve(outputDir, `${lang}.sarif`) path.resolve(outputDir, `${lang}.sarif`)
), ),
outputDir outputDir,
config.debugArtifactName
); );
} }
} }
@@ -138,12 +157,17 @@ async function run() {
// Multilanguage tracing: there are additional logs in the root of the cluster // Multilanguage tracing: there are additional logs in the root of the cluster
toUpload.push(...listFolder(path.resolve(config.dbLocation, "log"))); toUpload.push(...listFolder(path.resolve(config.dbLocation, "log")));
} }
await uploadDebugArtifacts(toUpload, config.dbLocation); await uploadDebugArtifacts(
toUpload,
config.dbLocation,
config.debugArtifactName
);
if (!(await codeQlVersionAbove(codeql, CODEQL_VERSION_NEW_TRACING))) { if (!(await codeQlVersionAbove(codeql, CODEQL_VERSION_NEW_TRACING))) {
// Before multi-language tracing, we wrote a compound-build-tracer.log in the temp dir // Before multi-language tracing, we wrote a compound-build-tracer.log in the temp dir
await uploadDebugArtifacts( await uploadDebugArtifacts(
[path.resolve(config.tempDir, "compound-build-tracer.log")], [path.resolve(config.tempDir, "compound-build-tracer.log")],
config.tempDir config.tempDir,
config.debugArtifactName
); );
} }
} }
@@ -173,10 +197,14 @@ async function run() {
logger.info("Not uploading results"); logger.info("Not uploading results");
} }
const repositoryNwo = parseRepositoryNwo( // Possibly upload the database bundles for remote queries
util.getRequiredEnvParam("GITHUB_REPOSITORY") await uploadDatabases(
repositoryNwo,
config,
featureFlags,
apiDetails,
logger
); );
await uploadDatabases(repositoryNwo, config, apiDetails, logger); // Possibly upload the database bundles for remote queries
if ( if (
uploadResult !== undefined && uploadResult !== undefined &&
@@ -189,14 +217,6 @@ async function run() {
getActionsLogger() getActionsLogger()
); );
} }
if (config.debugMode) {
// Upload the database bundles as an Actions artifact for debugging
const toUpload: string[] = [];
for (const language of config.languages)
toUpload.push(await bundleDb(config, language, codeql));
await uploadDebugArtifacts(toUpload, config.dbLocation);
}
} catch (origError) { } catch (origError) {
const error = const error =
origError instanceof Error ? origError : new Error(String(origError)); origError instanceof Error ? origError : new Error(String(origError));
@@ -212,6 +232,30 @@ async function run() {
return; return;
} finally { } finally {
if (config !== undefined && config.debugMode) {
try {
// Upload the database bundles as an Actions artifact for debugging
const toUpload: string[] = [];
for (const language of config.languages) {
toUpload.push(
await bundleDb(
config,
language,
await getCodeQL(config.codeQLCmd),
`${config.debugDatabaseName}-${language}`
)
);
}
await uploadDebugArtifacts(
toUpload,
config.dbLocation,
config.debugArtifactName
);
} catch (error) {
console.log(`Failed to upload database debug bundles: ${error}`);
}
}
if (core.isDebug() && config !== undefined) { if (core.isDebug() && config !== undefined) {
core.info("Debug mode is on. Printing CodeQL debug logs..."); core.info("Debug mode is on. Printing CodeQL debug logs...");
for (const language of config.languages) { for (const language of config.languages) {
@@ -251,7 +295,11 @@ async function run() {
} }
} }
async function uploadDebugArtifacts(toUpload: string[], rootDir: string) { async function uploadDebugArtifacts(
toUpload: string[],
rootDir: string,
artifactName: string
) {
let suffix = ""; let suffix = "";
const matrix = actionsUtil.getRequiredInput("matrix"); const matrix = actionsUtil.getRequiredInput("matrix");
if (matrix !== undefined && matrix !== "null") { if (matrix !== undefined && matrix !== "null") {
@@ -259,7 +307,7 @@ async function uploadDebugArtifacts(toUpload: string[], rootDir: string) {
suffix += `-${entry[1]}`; suffix += `-${entry[1]}`;
} }
await artifact.create().uploadArtifact( await artifact.create().uploadArtifact(
actionsUtil.sanitizeArifactName(`${DEBUG_ARTIFACT_NAME}${suffix}`), actionsUtil.sanitizeArifactName(`${artifactName}${suffix}`),
toUpload.map((file) => path.normalize(file)), toUpload.map((file) => path.normalize(file)),
path.normalize(rootDir) path.normalize(rootDir)
); );
+2
View File
@@ -120,6 +120,8 @@ test("status report fields and search path setting", async (t) => {
dbLocation: path.resolve(tmpDir, "codeql_databases"), dbLocation: path.resolve(tmpDir, "codeql_databases"),
packs, packs,
debugMode: false, debugMode: false,
debugArtifactName: util.DEFAULT_DEBUG_ARTIFACT_NAME,
debugDatabaseName: util.DEFAULT_DEBUG_DATABASE_NAME,
}; };
fs.mkdirSync(util.getCodeQLDatabasePath(config, language), { fs.mkdirSync(util.getCodeQLDatabasePath(config, language), {
recursive: true, recursive: true,
+1 -1
View File
@@ -1 +1 @@
{"maximumVersion": "3.3", "minimumVersion": "3.0"} {"maximumVersion": "3.4", "minimumVersion": "3.0"}
+9 -2
View File
@@ -127,7 +127,11 @@ export interface CodeQL {
/** /**
* Run 'codeql database bundle'. * Run 'codeql database bundle'.
*/ */
databaseBundle(databasePath: string, outputFilePath: string): Promise<void>; databaseBundle(
databasePath: string,
outputFilePath: string,
dbName: string
): Promise<void>;
/** /**
* Run 'codeql database run-queries'. * Run 'codeql database run-queries'.
*/ */
@@ -215,6 +219,7 @@ const CODEQL_VERSION_GROUP_RULES = "2.5.5";
const CODEQL_VERSION_SARIF_GROUP = "2.5.3"; const CODEQL_VERSION_SARIF_GROUP = "2.5.3";
export const CODEQL_VERSION_COUNTS_LINES = "2.6.2"; export const CODEQL_VERSION_COUNTS_LINES = "2.6.2";
const CODEQL_VERSION_CUSTOM_QUERY_HELP = "2.7.1"; const CODEQL_VERSION_CUSTOM_QUERY_HELP = "2.7.1";
export const CODEQL_VERSION_ML_POWERED_QUERIES = "2.7.5";
/** /**
* This variable controls using the new style of tracing from the CodeQL * This variable controls using the new style of tracing from the CodeQL
@@ -956,13 +961,15 @@ async function getCodeQLForCmd(
}, },
async databaseBundle( async databaseBundle(
databasePath: string, databasePath: string,
outputFilePath: string outputFilePath: string,
databaseName: string
): Promise<void> { ): Promise<void> {
const args = [ const args = [
"database", "database",
"bundle", "bundle",
databasePath, databasePath,
`--output=${outputFilePath}`, `--output=${outputFilePath}`,
`--name=${databaseName}`,
]; ];
await new toolrunner.ToolRunner(cmd, args).exec(); await new toolrunner.ToolRunner(cmd, args).exec();
}, },
+154 -2
View File
@@ -9,6 +9,7 @@ import * as sinon from "sinon";
import * as api from "./api-client"; import * as api from "./api-client";
import { getCachedCodeQL, setCodeQL } from "./codeql"; import { getCachedCodeQL, setCodeQL } from "./codeql";
import * as configUtils from "./config-utils"; import * as configUtils from "./config-utils";
import { createFeatureFlags, FeatureFlag } from "./feature-flags";
import { Language } from "./languages"; import { Language } from "./languages";
import { getRunnerLogger } from "./logging"; import { getRunnerLogger } from "./logging";
import { setupTests } from "./testing-utils"; import { setupTests } from "./testing-utils";
@@ -86,6 +87,8 @@ test("load empty config", async (t) => {
undefined, undefined,
undefined, undefined,
false, false,
"",
"",
{ owner: "github", repo: "example " }, { owner: "github", repo: "example " },
tmpDir, tmpDir,
tmpDir, tmpDir,
@@ -93,6 +96,7 @@ test("load empty config", async (t) => {
tmpDir, tmpDir,
gitHubVersion, gitHubVersion,
sampleApiDetails, sampleApiDetails,
createFeatureFlags([]),
logger logger
); );
@@ -104,6 +108,8 @@ test("load empty config", async (t) => {
undefined, undefined,
undefined, undefined,
false, false,
"",
"",
{ owner: "github", repo: "example " }, { owner: "github", repo: "example " },
tmpDir, tmpDir,
tmpDir, tmpDir,
@@ -111,6 +117,7 @@ test("load empty config", async (t) => {
tmpDir, tmpDir,
gitHubVersion, gitHubVersion,
sampleApiDetails, sampleApiDetails,
createFeatureFlags([]),
logger logger
) )
); );
@@ -147,6 +154,8 @@ test("loading config saves config", async (t) => {
undefined, undefined,
undefined, undefined,
false, false,
"",
"",
{ owner: "github", repo: "example " }, { owner: "github", repo: "example " },
tmpDir, tmpDir,
tmpDir, tmpDir,
@@ -154,6 +163,7 @@ test("loading config saves config", async (t) => {
tmpDir, tmpDir,
gitHubVersion, gitHubVersion,
sampleApiDetails, sampleApiDetails,
createFeatureFlags([]),
logger logger
); );
@@ -176,6 +186,8 @@ test("load input outside of workspace", async (t) => {
"../input", "../input",
undefined, undefined,
false, false,
"",
"",
{ owner: "github", repo: "example " }, { owner: "github", repo: "example " },
tmpDir, tmpDir,
tmpDir, tmpDir,
@@ -183,6 +195,7 @@ test("load input outside of workspace", async (t) => {
tmpDir, tmpDir,
gitHubVersion, gitHubVersion,
sampleApiDetails, sampleApiDetails,
createFeatureFlags([]),
getRunnerLogger(true) getRunnerLogger(true)
); );
throw new Error("initConfig did not throw error"); throw new Error("initConfig did not throw error");
@@ -212,6 +225,8 @@ test("load non-local input with invalid repo syntax", async (t) => {
configFile, configFile,
undefined, undefined,
false, false,
"",
"",
{ owner: "github", repo: "example " }, { owner: "github", repo: "example " },
tmpDir, tmpDir,
tmpDir, tmpDir,
@@ -219,6 +234,7 @@ test("load non-local input with invalid repo syntax", async (t) => {
tmpDir, tmpDir,
gitHubVersion, gitHubVersion,
sampleApiDetails, sampleApiDetails,
createFeatureFlags([]),
getRunnerLogger(true) getRunnerLogger(true)
); );
throw new Error("initConfig did not throw error"); throw new Error("initConfig did not throw error");
@@ -249,6 +265,8 @@ test("load non-existent input", async (t) => {
configFile, configFile,
undefined, undefined,
false, false,
"",
"",
{ owner: "github", repo: "example " }, { owner: "github", repo: "example " },
tmpDir, tmpDir,
tmpDir, tmpDir,
@@ -256,6 +274,7 @@ test("load non-existent input", async (t) => {
tmpDir, tmpDir,
gitHubVersion, gitHubVersion,
sampleApiDetails, sampleApiDetails,
createFeatureFlags([]),
getRunnerLogger(true) getRunnerLogger(true)
); );
throw new Error("initConfig did not throw error"); throw new Error("initConfig did not throw error");
@@ -333,6 +352,8 @@ test("load non-empty input", async (t) => {
dbLocation: path.resolve(tmpDir, "codeql_databases"), dbLocation: path.resolve(tmpDir, "codeql_databases"),
packs: {} as configUtils.Packs, packs: {} as configUtils.Packs,
debugMode: false, debugMode: false,
debugArtifactName: "my-artifact",
debugDatabaseName: "my-db",
}; };
const languages = "javascript"; const languages = "javascript";
@@ -345,6 +366,8 @@ test("load non-empty input", async (t) => {
configFilePath, configFilePath,
undefined, undefined,
false, false,
"my-artifact",
"my-db",
{ owner: "github", repo: "example " }, { owner: "github", repo: "example " },
tmpDir, tmpDir,
tmpDir, tmpDir,
@@ -352,6 +375,7 @@ test("load non-empty input", async (t) => {
tmpDir, tmpDir,
gitHubVersion, gitHubVersion,
sampleApiDetails, sampleApiDetails,
createFeatureFlags([]),
getRunnerLogger(true) getRunnerLogger(true)
); );
@@ -409,6 +433,8 @@ test("Default queries are used", async (t) => {
configFilePath, configFilePath,
undefined, undefined,
false, false,
"",
"",
{ owner: "github", repo: "example " }, { owner: "github", repo: "example " },
tmpDir, tmpDir,
tmpDir, tmpDir,
@@ -416,6 +442,7 @@ test("Default queries are used", async (t) => {
tmpDir, tmpDir,
gitHubVersion, gitHubVersion,
sampleApiDetails, sampleApiDetails,
createFeatureFlags([]),
getRunnerLogger(true) getRunnerLogger(true)
); );
@@ -481,6 +508,8 @@ test("Queries can be specified in config file", async (t) => {
configFilePath, configFilePath,
undefined, undefined,
false, false,
"",
"",
{ owner: "github", repo: "example " }, { owner: "github", repo: "example " },
tmpDir, tmpDir,
tmpDir, tmpDir,
@@ -488,6 +517,7 @@ test("Queries can be specified in config file", async (t) => {
tmpDir, tmpDir,
gitHubVersion, gitHubVersion,
sampleApiDetails, sampleApiDetails,
createFeatureFlags([]),
getRunnerLogger(true) getRunnerLogger(true)
); );
@@ -547,6 +577,8 @@ test("Queries from config file can be overridden in workflow file", async (t) =>
configFilePath, configFilePath,
undefined, undefined,
false, false,
"",
"",
{ owner: "github", repo: "example " }, { owner: "github", repo: "example " },
tmpDir, tmpDir,
tmpDir, tmpDir,
@@ -554,6 +586,7 @@ test("Queries from config file can be overridden in workflow file", async (t) =>
tmpDir, tmpDir,
gitHubVersion, gitHubVersion,
sampleApiDetails, sampleApiDetails,
createFeatureFlags([]),
getRunnerLogger(true) getRunnerLogger(true)
); );
@@ -611,6 +644,8 @@ test("Queries in workflow file can be used in tandem with the 'disable default q
configFilePath, configFilePath,
undefined, undefined,
false, false,
"",
"",
{ owner: "github", repo: "example " }, { owner: "github", repo: "example " },
tmpDir, tmpDir,
tmpDir, tmpDir,
@@ -618,6 +653,7 @@ test("Queries in workflow file can be used in tandem with the 'disable default q
tmpDir, tmpDir,
gitHubVersion, gitHubVersion,
sampleApiDetails, sampleApiDetails,
createFeatureFlags([]),
getRunnerLogger(true) getRunnerLogger(true)
); );
@@ -668,6 +704,8 @@ test("Multiple queries can be specified in workflow file, no config file require
undefined, undefined,
undefined, undefined,
false, false,
"",
"",
{ owner: "github", repo: "example " }, { owner: "github", repo: "example " },
tmpDir, tmpDir,
tmpDir, tmpDir,
@@ -675,6 +713,7 @@ test("Multiple queries can be specified in workflow file, no config file require
tmpDir, tmpDir,
gitHubVersion, gitHubVersion,
sampleApiDetails, sampleApiDetails,
createFeatureFlags([]),
getRunnerLogger(true) getRunnerLogger(true)
); );
@@ -746,6 +785,8 @@ test("Queries in workflow file can be added to the set of queries without overri
configFilePath, configFilePath,
undefined, undefined,
false, false,
"",
"",
{ owner: "github", repo: "example " }, { owner: "github", repo: "example " },
tmpDir, tmpDir,
tmpDir, tmpDir,
@@ -753,6 +794,7 @@ test("Queries in workflow file can be added to the set of queries without overri
tmpDir, tmpDir,
gitHubVersion, gitHubVersion,
sampleApiDetails, sampleApiDetails,
createFeatureFlags([]),
getRunnerLogger(true) getRunnerLogger(true)
); );
@@ -814,6 +856,8 @@ test("Invalid queries in workflow file handled correctly", async (t) => {
undefined, undefined,
undefined, undefined,
false, false,
"",
"",
{ owner: "github", repo: "example " }, { owner: "github", repo: "example " },
tmpDir, tmpDir,
tmpDir, tmpDir,
@@ -821,6 +865,7 @@ test("Invalid queries in workflow file handled correctly", async (t) => {
tmpDir, tmpDir,
gitHubVersion, gitHubVersion,
sampleApiDetails, sampleApiDetails,
createFeatureFlags([]),
getRunnerLogger(true) getRunnerLogger(true)
); );
t.fail("initConfig did not throw error"); t.fail("initConfig did not throw error");
@@ -879,6 +924,8 @@ test("API client used when reading remote config", async (t) => {
configFile, configFile,
undefined, undefined,
false, false,
"",
"",
{ owner: "github", repo: "example " }, { owner: "github", repo: "example " },
tmpDir, tmpDir,
tmpDir, tmpDir,
@@ -886,6 +933,7 @@ test("API client used when reading remote config", async (t) => {
tmpDir, tmpDir,
gitHubVersion, gitHubVersion,
sampleApiDetails, sampleApiDetails,
createFeatureFlags([]),
getRunnerLogger(true) getRunnerLogger(true)
); );
t.assert(spyGetContents.called); t.assert(spyGetContents.called);
@@ -906,6 +954,8 @@ test("Remote config handles the case where a directory is provided", async (t) =
repoReference, repoReference,
undefined, undefined,
false, false,
"",
"",
{ owner: "github", repo: "example " }, { owner: "github", repo: "example " },
tmpDir, tmpDir,
tmpDir, tmpDir,
@@ -913,6 +963,7 @@ test("Remote config handles the case where a directory is provided", async (t) =
tmpDir, tmpDir,
gitHubVersion, gitHubVersion,
sampleApiDetails, sampleApiDetails,
createFeatureFlags([]),
getRunnerLogger(true) getRunnerLogger(true)
); );
throw new Error("initConfig did not throw error"); throw new Error("initConfig did not throw error");
@@ -941,6 +992,8 @@ test("Invalid format of remote config handled correctly", async (t) => {
repoReference, repoReference,
undefined, undefined,
false, false,
"",
"",
{ owner: "github", repo: "example " }, { owner: "github", repo: "example " },
tmpDir, tmpDir,
tmpDir, tmpDir,
@@ -948,6 +1001,7 @@ test("Invalid format of remote config handled correctly", async (t) => {
tmpDir, tmpDir,
gitHubVersion, gitHubVersion,
sampleApiDetails, sampleApiDetails,
createFeatureFlags([]),
getRunnerLogger(true) getRunnerLogger(true)
); );
throw new Error("initConfig did not throw error"); throw new Error("initConfig did not throw error");
@@ -977,6 +1031,8 @@ test("No detected languages", async (t) => {
undefined, undefined,
undefined, undefined,
false, false,
"",
"",
{ owner: "github", repo: "example " }, { owner: "github", repo: "example " },
tmpDir, tmpDir,
tmpDir, tmpDir,
@@ -984,6 +1040,7 @@ test("No detected languages", async (t) => {
tmpDir, tmpDir,
gitHubVersion, gitHubVersion,
sampleApiDetails, sampleApiDetails,
createFeatureFlags([]),
getRunnerLogger(true) getRunnerLogger(true)
); );
throw new Error("initConfig did not throw error"); throw new Error("initConfig did not throw error");
@@ -1005,6 +1062,8 @@ test("Unknown languages", async (t) => {
undefined, undefined,
undefined, undefined,
false, false,
"",
"",
{ owner: "github", repo: "example " }, { owner: "github", repo: "example " },
tmpDir, tmpDir,
tmpDir, tmpDir,
@@ -1012,6 +1071,7 @@ test("Unknown languages", async (t) => {
tmpDir, tmpDir,
gitHubVersion, gitHubVersion,
sampleApiDetails, sampleApiDetails,
createFeatureFlags([]),
getRunnerLogger(true) getRunnerLogger(true)
); );
throw new Error("initConfig did not throw error"); throw new Error("initConfig did not throw error");
@@ -1055,6 +1115,8 @@ test("Config specifies packages", async (t) => {
configFile, configFile,
undefined, undefined,
false, false,
"",
"",
{ owner: "github", repo: "example " }, { owner: "github", repo: "example " },
tmpDir, tmpDir,
tmpDir, tmpDir,
@@ -1062,6 +1124,7 @@ test("Config specifies packages", async (t) => {
tmpDir, tmpDir,
gitHubVersion, gitHubVersion,
sampleApiDetails, sampleApiDetails,
createFeatureFlags([]),
getRunnerLogger(true) getRunnerLogger(true)
); );
t.deepEqual(packs as unknown, { t.deepEqual(packs as unknown, {
@@ -1114,6 +1177,8 @@ test("Config specifies packages for multiple languages", async (t) => {
configFile, configFile,
undefined, undefined,
false, false,
"",
"",
{ owner: "github", repo: "example" }, { owner: "github", repo: "example" },
tmpDir, tmpDir,
tmpDir, tmpDir,
@@ -1121,6 +1186,7 @@ test("Config specifies packages for multiple languages", async (t) => {
tmpDir, tmpDir,
gitHubVersion, gitHubVersion,
sampleApiDetails, sampleApiDetails,
createFeatureFlags([]),
getRunnerLogger(true) getRunnerLogger(true)
); );
t.deepEqual(packs as unknown, { t.deepEqual(packs as unknown, {
@@ -1189,6 +1255,8 @@ function doInvalidInputTest(
configFile, configFile,
undefined, undefined,
false, false,
"",
"",
{ owner: "github", repo: "example " }, { owner: "github", repo: "example " },
tmpDir, tmpDir,
tmpDir, tmpDir,
@@ -1196,6 +1264,7 @@ function doInvalidInputTest(
tmpDir, tmpDir,
gitHubVersion, gitHubVersion,
sampleApiDetails, sampleApiDetails,
createFeatureFlags([]),
getRunnerLogger(true) getRunnerLogger(true)
); );
throw new Error("initConfig did not throw error"); throw new Error("initConfig did not throw error");
@@ -1631,5 +1700,88 @@ test(
/"xxx" is not a valid pack/ /"xxx" is not a valid pack/
); );
// errors async function mlPoweredQueriesMacro(
// input w invalid pack name t: ExecutionContext,
codeQLVersion: string,
isMlPoweredQueriesFlagEnabled: boolean,
queriesInput: string | undefined,
shouldRunMlPoweredQueries: boolean
) {
return await util.withTmpDir(async (tmpDir) => {
const codeQL = setCodeQL({
async getVersion() {
return codeQLVersion;
},
async resolveQueries() {
return {
byLanguage: {
javascript: { "fake-query.ql": {} },
},
noDeclaredLanguage: {},
multipleDeclaredLanguages: {},
};
},
});
const { packs } = await configUtils.initConfig(
"javascript",
queriesInput,
undefined,
undefined,
undefined,
false,
"",
"",
{ owner: "github", repo: "example " },
tmpDir,
tmpDir,
codeQL,
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatureFlags(
isMlPoweredQueriesFlagEnabled
? [FeatureFlag.MlPoweredQueriesEnabled]
: []
),
getRunnerLogger(true)
);
if (shouldRunMlPoweredQueries) {
t.deepEqual(packs as unknown, {
[Language.javascript]: [
{
packName: "codeql/javascript-experimental-atm-queries",
version: "~0.0.2",
},
],
});
} else {
t.deepEqual(packs as unknown, {});
}
});
}
mlPoweredQueriesMacro.title = (
_providedTitle: string,
codeQLVersion: string,
isMlPoweredQueriesFlagEnabled: boolean,
queriesInput: string | undefined,
shouldRunMlPoweredQueries: boolean
) => {
const queriesInputDescription = queriesInput
? `'queries: ${queriesInput}'`
: "default config";
return `ML-powered queries ${
shouldRunMlPoweredQueries ? "are" : "aren't"
} loaded for ${queriesInputDescription} using CLI v${codeQLVersion} when feature flag is ${
isMlPoweredQueriesFlagEnabled ? "enabled" : "disabled"
}`;
};
// macro, isMlPoweredQueriesFlagEnabled, queriesInput, shouldRunMlPoweredQueries
test(mlPoweredQueriesMacro, "2.7.4", true, "security-extended", false);
test(mlPoweredQueriesMacro, "2.7.5", false, "security-extended", false);
test(mlPoweredQueriesMacro, "2.7.5", true, undefined, false);
test(mlPoweredQueriesMacro, "2.7.5", true, "security-extended", true);
test(mlPoweredQueriesMacro, "2.7.5", true, "security-and-quality", true);
+79 -14
View File
@@ -5,12 +5,17 @@ import * as yaml from "js-yaml";
import * as semver from "semver"; import * as semver from "semver";
import * as api from "./api-client"; import * as api from "./api-client";
import { CodeQL, ResolveQueriesOutput } from "./codeql"; import {
CodeQL,
CODEQL_VERSION_ML_POWERED_QUERIES,
ResolveQueriesOutput,
} from "./codeql";
import * as externalQueries from "./external-queries"; import * as externalQueries from "./external-queries";
import { FeatureFlag, FeatureFlags } from "./feature-flags";
import { Language, parseLanguage } from "./languages"; import { Language, parseLanguage } from "./languages";
import { Logger } from "./logging"; import { Logger } from "./logging";
import { RepositoryNwo } from "./repository"; import { RepositoryNwo } from "./repository";
import { GitHubVersion } from "./util"; import { codeQlVersionAbove, GitHubVersion } from "./util";
// Property names from the user-supplied config file. // Property names from the user-supplied config file.
const NAME_PROPERTY = "name"; const NAME_PROPERTY = "name";
@@ -130,6 +135,14 @@ export interface Config {
* output for debugging purposes when possible. * output for debugging purposes when possible.
*/ */
debugMode: boolean; debugMode: boolean;
/**
* Specifies the name of the debugging artifact if we are in debug mode.
*/
debugArtifactName: string;
/**
* Specifies the name of the database in the debugging artifact.
*/
debugDatabaseName: string;
} }
export type Packs = Partial<Record<Language, PackWithVersion[]>>; export type Packs = Partial<Record<Language, PackWithVersion[]>>;
@@ -262,7 +275,9 @@ async function addBuiltinSuiteQueries(
languages: string[], languages: string[],
codeQL: CodeQL, codeQL: CodeQL,
resultMap: Queries, resultMap: Queries,
packs: Packs,
suiteName: string, suiteName: string,
featureFlags: FeatureFlags,
configFile?: string configFile?: string
) { ) {
const found = builtinSuites.find((suite) => suite === suiteName); const found = builtinSuites.find((suite) => suite === suiteName);
@@ -270,6 +285,24 @@ async function addBuiltinSuiteQueries(
throw new Error(getQueryUsesInvalid(configFile, suiteName)); throw new Error(getQueryUsesInvalid(configFile, suiteName));
} }
// If we're running the JavaScript security-extended analysis (or a superset of it) and the repo
// is opted into the ML-powered queries beta, then add the ML-powered query pack so that we run
// the ML-powered queries.
if (
languages.includes("javascript") &&
(found === "security-extended" || found === "security-and-quality") &&
(await featureFlags.getValue(FeatureFlag.MlPoweredQueriesEnabled)) &&
(await codeQlVersionAbove(codeQL, CODEQL_VERSION_ML_POWERED_QUERIES))
) {
if (!packs.javascript) {
packs.javascript = [];
}
packs.javascript.push({
packName: "codeql/javascript-experimental-atm-queries",
version: "~0.0.2",
});
}
const suites = languages.map((l) => `${l}-${suiteName}.qls`); const suites = languages.map((l) => `${l}-${suiteName}.qls`);
await runResolveQueries(codeQL, resultMap, suites, undefined); await runResolveQueries(codeQL, resultMap, suites, undefined);
} }
@@ -378,10 +411,12 @@ async function parseQueryUses(
languages: string[], languages: string[],
codeQL: CodeQL, codeQL: CodeQL,
resultMap: Queries, resultMap: Queries,
packs: Packs,
queryUses: string, queryUses: string,
tempDir: string, tempDir: string,
workspacePath: string, workspacePath: string,
apiDetails: api.GitHubApiExternalRepoDetails, apiDetails: api.GitHubApiExternalRepoDetails,
featureFlags: FeatureFlags,
logger: Logger, logger: Logger,
configFile?: string configFile?: string
) { ) {
@@ -408,7 +443,9 @@ async function parseQueryUses(
languages, languages,
codeQL, codeQL,
resultMap, resultMap,
packs,
queryUses, queryUses,
featureFlags,
configFile configFile
); );
return; return;
@@ -770,14 +807,16 @@ async function getLanguages(
return parsedLanguages; return parsedLanguages;
} }
async function addQueriesFromWorkflow( async function addQueriesAndPacksFromWorkflow(
codeQL: CodeQL, codeQL: CodeQL,
queriesInput: string, queriesInput: string,
languages: string[], languages: string[],
resultMap: Queries, resultMap: Queries,
packs: Packs,
tempDir: string, tempDir: string,
workspacePath: string, workspacePath: string,
apiDetails: api.GitHubApiExternalRepoDetails, apiDetails: api.GitHubApiExternalRepoDetails,
featureFlags: FeatureFlags,
logger: Logger logger: Logger
) { ) {
queriesInput = queriesInput.trim(); queriesInput = queriesInput.trim();
@@ -789,10 +828,12 @@ async function addQueriesFromWorkflow(
languages, languages,
codeQL, codeQL,
resultMap, resultMap,
packs,
query, query,
tempDir, tempDir,
workspacePath, workspacePath,
apiDetails, apiDetails,
featureFlags,
logger logger
); );
} }
@@ -819,6 +860,8 @@ export async function getDefaultConfig(
packsInput: string | undefined, packsInput: string | undefined,
dbLocation: string | undefined, dbLocation: string | undefined,
debugMode: boolean, debugMode: boolean,
debugArtifactName: string,
debugDatabaseName: string,
repository: RepositoryNwo, repository: RepositoryNwo,
tempDir: string, tempDir: string,
toolCacheDir: string, toolCacheDir: string,
@@ -826,6 +869,7 @@ export async function getDefaultConfig(
workspacePath: string, workspacePath: string,
gitHubVersion: GitHubVersion, gitHubVersion: GitHubVersion,
apiDetails: api.GitHubApiCombinedDetails, apiDetails: api.GitHubApiCombinedDetails,
featureFlags: FeatureFlags,
logger: Logger logger: Logger
): Promise<Config> { ): Promise<Config> {
const languages = await getLanguages( const languages = await getLanguages(
@@ -843,21 +887,22 @@ export async function getDefaultConfig(
}; };
} }
await addDefaultQueries(codeQL, languages, queries); await addDefaultQueries(codeQL, languages, queries);
const packs = parsePacksFromInput(packsInput, languages) ?? {};
if (queriesInput) { if (queriesInput) {
await addQueriesFromWorkflow( await addQueriesAndPacksFromWorkflow(
codeQL, codeQL,
queriesInput, queriesInput,
languages, languages,
queries, queries,
packs,
tempDir, tempDir,
workspacePath, workspacePath,
apiDetails, apiDetails,
featureFlags,
logger logger
); );
} }
const packs = parsePacksFromInput(packsInput, languages) ?? {};
return { return {
languages, languages,
queries, queries,
@@ -871,6 +916,8 @@ export async function getDefaultConfig(
gitHubVersion, gitHubVersion,
dbLocation: dbLocationOrDefault(dbLocation, tempDir), dbLocation: dbLocationOrDefault(dbLocation, tempDir),
debugMode, debugMode,
debugArtifactName,
debugDatabaseName,
}; };
} }
@@ -884,6 +931,8 @@ async function loadConfig(
configFile: string, configFile: string,
dbLocation: string | undefined, dbLocation: string | undefined,
debugMode: boolean, debugMode: boolean,
debugArtifactName: string,
debugDatabaseName: string,
repository: RepositoryNwo, repository: RepositoryNwo,
tempDir: string, tempDir: string,
toolCacheDir: string, toolCacheDir: string,
@@ -891,6 +940,7 @@ async function loadConfig(
workspacePath: string, workspacePath: string,
gitHubVersion: GitHubVersion, gitHubVersion: GitHubVersion,
apiDetails: api.GitHubApiCombinedDetails, apiDetails: api.GitHubApiCombinedDetails,
featureFlags: FeatureFlags,
logger: Logger logger: Logger
): Promise<Config> { ): Promise<Config> {
let parsedYAML: UserConfig; let parsedYAML: UserConfig;
@@ -943,19 +993,28 @@ async function loadConfig(
await addDefaultQueries(codeQL, languages, queries); await addDefaultQueries(codeQL, languages, queries);
} }
const packs = parsePacks(
parsedYAML[PACKS_PROPERTY] ?? {},
packsInput,
languages,
configFile
);
// If queries were provided using `with` in the action configuration, // If queries were provided using `with` in the action configuration,
// they should take precedence over the queries in the config file // they should take precedence over the queries in the config file
// unless they're prefixed with "+", in which case they supplement those // unless they're prefixed with "+", in which case they supplement those
// in the config file. // in the config file.
if (queriesInput) { if (queriesInput) {
await addQueriesFromWorkflow( await addQueriesAndPacksFromWorkflow(
codeQL, codeQL,
queriesInput, queriesInput,
languages, languages,
queries, queries,
packs,
tempDir, tempDir,
workspacePath, workspacePath,
apiDetails, apiDetails,
featureFlags,
logger logger
); );
} }
@@ -978,10 +1037,12 @@ async function loadConfig(
languages, languages,
codeQL, codeQL,
queries, queries,
packs,
query[QUERIES_USES_PROPERTY], query[QUERIES_USES_PROPERTY],
tempDir, tempDir,
workspacePath, workspacePath,
apiDetails, apiDetails,
featureFlags,
logger, logger,
configFile configFile
); );
@@ -1021,13 +1082,6 @@ async function loadConfig(
} }
} }
const packs = parsePacks(
parsedYAML[PACKS_PROPERTY] ?? {},
packsInput,
languages,
configFile
);
return { return {
languages, languages,
queries, queries,
@@ -1041,6 +1095,8 @@ async function loadConfig(
gitHubVersion, gitHubVersion,
dbLocation: dbLocationOrDefault(dbLocation, tempDir), dbLocation: dbLocationOrDefault(dbLocation, tempDir),
debugMode, debugMode,
debugArtifactName,
debugDatabaseName,
}; };
} }
@@ -1211,6 +1267,8 @@ export async function initConfig(
configFile: string | undefined, configFile: string | undefined,
dbLocation: string | undefined, dbLocation: string | undefined,
debugMode: boolean, debugMode: boolean,
debugArtifactName: string,
debugDatabaseName: string,
repository: RepositoryNwo, repository: RepositoryNwo,
tempDir: string, tempDir: string,
toolCacheDir: string, toolCacheDir: string,
@@ -1218,6 +1276,7 @@ export async function initConfig(
workspacePath: string, workspacePath: string,
gitHubVersion: GitHubVersion, gitHubVersion: GitHubVersion,
apiDetails: api.GitHubApiCombinedDetails, apiDetails: api.GitHubApiCombinedDetails,
featureFlags: FeatureFlags,
logger: Logger logger: Logger
): Promise<Config> { ): Promise<Config> {
let config: Config; let config: Config;
@@ -1231,6 +1290,8 @@ export async function initConfig(
packsInput, packsInput,
dbLocation, dbLocation,
debugMode, debugMode,
debugArtifactName,
debugDatabaseName,
repository, repository,
tempDir, tempDir,
toolCacheDir, toolCacheDir,
@@ -1238,6 +1299,7 @@ export async function initConfig(
workspacePath, workspacePath,
gitHubVersion, gitHubVersion,
apiDetails, apiDetails,
featureFlags,
logger logger
); );
} else { } else {
@@ -1248,6 +1310,8 @@ export async function initConfig(
configFile, configFile,
dbLocation, dbLocation,
debugMode, debugMode,
debugArtifactName,
debugDatabaseName,
repository, repository,
tempDir, tempDir,
toolCacheDir, toolCacheDir,
@@ -1255,6 +1319,7 @@ export async function initConfig(
workspacePath, workspacePath,
gitHubVersion, gitHubVersion,
apiDetails, apiDetails,
featureFlags,
logger logger
); );
} }
+45 -103
View File
@@ -10,11 +10,18 @@ import * as apiClient from "./api-client";
import { setCodeQL } from "./codeql"; import { setCodeQL } from "./codeql";
import { Config } from "./config-utils"; import { Config } from "./config-utils";
import { uploadDatabases } from "./database-upload"; import { uploadDatabases } from "./database-upload";
import { createFeatureFlags, FeatureFlag, FeatureFlags } from "./feature-flags";
import { Language } from "./languages"; import { Language } from "./languages";
import { Logger } from "./logging";
import { RepositoryNwo } from "./repository"; import { RepositoryNwo } from "./repository";
import { setupActionsVars, setupTests } from "./testing-utils";
import { import {
getRecordingLogger,
LoggedMessage,
setupActionsVars,
setupTests,
} from "./testing-utils";
import {
DEFAULT_DEBUG_ARTIFACT_NAME,
DEFAULT_DEBUG_DATABASE_NAME,
GitHubVariant, GitHubVariant,
HTTPError, HTTPError,
initializeEnvironment, initializeEnvironment,
@@ -28,6 +35,11 @@ test.beforeEach(() => {
initializeEnvironment(Mode.actions, "1.2.3"); initializeEnvironment(Mode.actions, "1.2.3");
}); });
const uploadToUploadsDomainFlags = createFeatureFlags([
FeatureFlag.DatabaseUploadsEnabled,
FeatureFlag.UploadsDomainEnabled,
]);
const testRepoName: RepositoryNwo = { owner: "github", repo: "example" }; const testRepoName: RepositoryNwo = { owner: "github", repo: "example" };
const testApiDetails: GitHubApiDetails = { const testApiDetails: GitHubApiDetails = {
auth: "1234", auth: "1234",
@@ -48,76 +60,30 @@ function getTestConfig(tmpDir: string): Config {
dbLocation: tmpDir, dbLocation: tmpDir,
packs: {}, packs: {},
debugMode: false, debugMode: false,
debugArtifactName: DEFAULT_DEBUG_ARTIFACT_NAME,
debugDatabaseName: DEFAULT_DEBUG_DATABASE_NAME,
}; };
} }
interface LoggedMessage { async function mockHttpRequests(
type: "debug" | "info" | "warning" | "error"; featureFlags: FeatureFlags,
message: string | Error; databaseUploadStatusCode: number
}
function getRecordingLogger(messages: LoggedMessage[]): Logger {
return {
debug: (message: string) => {
messages.push({ type: "debug", message });
console.debug(message);
},
info: (message: string) => {
messages.push({ type: "info", message });
console.info(message);
},
warning: (message: string | Error) => {
messages.push({ type: "warning", message });
console.warn(message);
},
error: (message: string | Error) => {
messages.push({ type: "error", message });
console.error(message);
},
isDebug: () => true,
startGroup: () => undefined,
endGroup: () => undefined,
};
}
function mockHttpRequests(
optInStatusCode: number,
useUploadDomain?: boolean,
databaseUploadStatusCode?: number
) { ) {
// Passing an auth token is required, so we just use a dummy value // Passing an auth token is required, so we just use a dummy value
const client = github.getOctokit("123"); const client = github.getOctokit("123");
const requestSpy = sinon.stub(client, "request"); const requestSpy = sinon.stub(client, "request");
const optInSpy = requestSpy.withArgs( const url = (await featureFlags.getValue(FeatureFlag.UploadsDomainEnabled))
"GET /repos/:owner/:repo/code-scanning/codeql/databases" ? "POST https://uploads.github.com/repos/:owner/:repo/code-scanning/codeql/databases/:language?name=:name"
); : "PUT /repos/:owner/:repo/code-scanning/codeql/databases/:language";
if (optInStatusCode < 300) { const databaseUploadSpy = requestSpy.withArgs(url);
optInSpy.resolves({ if (databaseUploadStatusCode < 300) {
status: optInStatusCode, databaseUploadSpy.resolves(undefined);
data: {
useUploadDomain,
},
headers: {},
url: "GET /repos/:owner/:repo/code-scanning/codeql/databases",
});
} else { } else {
optInSpy.throws(new HTTPError("some error message", optInStatusCode)); databaseUploadSpy.throws(
} new HTTPError("some error message", databaseUploadStatusCode)
);
if (databaseUploadStatusCode !== undefined) {
const url = useUploadDomain
? "POST https://uploads.github.com/repos/:owner/:repo/code-scanning/codeql/databases/:language?name=:name"
: "PUT /repos/:owner/:repo/code-scanning/codeql/databases/:language";
const databaseUploadSpy = requestSpy.withArgs(url);
if (databaseUploadStatusCode < 300) {
databaseUploadSpy.resolves(undefined);
} else {
databaseUploadSpy.throws(
new HTTPError("some error message", databaseUploadStatusCode)
);
}
} }
sinon.stub(apiClient, "getApiClient").value(() => client); sinon.stub(apiClient, "getApiClient").value(() => client);
@@ -136,6 +102,7 @@ test("Abort database upload if 'upload-database' input set to false", async (t)
await uploadDatabases( await uploadDatabases(
testRepoName, testRepoName,
getTestConfig(tmpDir), getTestConfig(tmpDir),
uploadToUploadsDomainFlags,
testApiDetails, testApiDetails,
getRecordingLogger(loggedMessages) getRecordingLogger(loggedMessages)
); );
@@ -165,6 +132,7 @@ test("Abort database upload if running against GHES", async (t) => {
await uploadDatabases( await uploadDatabases(
testRepoName, testRepoName,
config, config,
createFeatureFlags([]),
testApiDetails, testApiDetails,
getRecordingLogger(loggedMessages) getRecordingLogger(loggedMessages)
); );
@@ -194,6 +162,7 @@ test("Abort database upload if running against GHAE", async (t) => {
await uploadDatabases( await uploadDatabases(
testRepoName, testRepoName,
config, config,
createFeatureFlags([]),
testApiDetails, testApiDetails,
getRecordingLogger(loggedMessages) getRecordingLogger(loggedMessages)
); );
@@ -220,6 +189,7 @@ test("Abort database upload if not analyzing default branch", async (t) => {
await uploadDatabases( await uploadDatabases(
testRepoName, testRepoName,
getTestConfig(tmpDir), getTestConfig(tmpDir),
uploadToUploadsDomainFlags,
testApiDetails, testApiDetails,
getRecordingLogger(loggedMessages) getRecordingLogger(loggedMessages)
); );
@@ -233,7 +203,7 @@ test("Abort database upload if not analyzing default branch", async (t) => {
}); });
}); });
test("Abort database upload if opt-in request returns 404", async (t) => { test("Abort database upload if feature flag is disabled", async (t) => {
await withTmpDir(async (tmpDir) => { await withTmpDir(async (tmpDir) => {
setupActionsVars(tmpDir, tmpDir); setupActionsVars(tmpDir, tmpDir);
sinon sinon
@@ -242,8 +212,6 @@ test("Abort database upload if opt-in request returns 404", async (t) => {
.returns("true"); .returns("true");
sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true); sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true);
mockHttpRequests(404);
setCodeQL({ setCodeQL({
async databaseBundle() { async databaseBundle() {
return; return;
@@ -254,6 +222,7 @@ test("Abort database upload if opt-in request returns 404", async (t) => {
await uploadDatabases( await uploadDatabases(
testRepoName, testRepoName,
getTestConfig(tmpDir), getTestConfig(tmpDir),
createFeatureFlags([FeatureFlag.UploadsDomainEnabled]),
testApiDetails, testApiDetails,
getRecordingLogger(loggedMessages) getRecordingLogger(loggedMessages)
); );
@@ -268,41 +237,6 @@ test("Abort database upload if opt-in request returns 404", async (t) => {
}); });
}); });
test("Abort database upload if opt-in request fails with something other than 404", async (t) => {
await withTmpDir(async (tmpDir) => {
setupActionsVars(tmpDir, tmpDir);
sinon
.stub(actionsUtil, "getRequiredInput")
.withArgs("upload-database")
.returns("true");
sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true);
mockHttpRequests(500);
setCodeQL({
async databaseBundle() {
return;
},
});
const loggedMessages = [] as LoggedMessage[];
await uploadDatabases(
testRepoName,
getTestConfig(tmpDir),
testApiDetails,
getRecordingLogger(loggedMessages)
);
t.assert(
loggedMessages.find(
(v) =>
v.type === "info" &&
v.message ===
"Skipping database upload due to unknown error: Error: some error message"
) !== undefined
);
});
});
test("Don't crash if uploading a database fails", async (t) => { test("Don't crash if uploading a database fails", async (t) => {
await withTmpDir(async (tmpDir) => { await withTmpDir(async (tmpDir) => {
setupActionsVars(tmpDir, tmpDir); setupActionsVars(tmpDir, tmpDir);
@@ -312,7 +246,11 @@ test("Don't crash if uploading a database fails", async (t) => {
.returns("true"); .returns("true");
sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true); sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true);
mockHttpRequests(200, false, 500); const featureFlags = createFeatureFlags([
FeatureFlag.DatabaseUploadsEnabled,
]);
await mockHttpRequests(featureFlags, 500);
setCodeQL({ setCodeQL({
async databaseBundle(_: string, outputFilePath: string) { async databaseBundle(_: string, outputFilePath: string) {
@@ -324,9 +262,11 @@ test("Don't crash if uploading a database fails", async (t) => {
await uploadDatabases( await uploadDatabases(
testRepoName, testRepoName,
getTestConfig(tmpDir), getTestConfig(tmpDir),
featureFlags,
testApiDetails, testApiDetails,
getRecordingLogger(loggedMessages) getRecordingLogger(loggedMessages)
); );
t.assert( t.assert(
loggedMessages.find( loggedMessages.find(
(v) => (v) =>
@@ -347,7 +287,7 @@ test("Successfully uploading a database to api.github.com", async (t) => {
.returns("true"); .returns("true");
sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true); sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true);
mockHttpRequests(200, false, 201); await mockHttpRequests(uploadToUploadsDomainFlags, 201);
setCodeQL({ setCodeQL({
async databaseBundle(_: string, outputFilePath: string) { async databaseBundle(_: string, outputFilePath: string) {
@@ -359,6 +299,7 @@ test("Successfully uploading a database to api.github.com", async (t) => {
await uploadDatabases( await uploadDatabases(
testRepoName, testRepoName,
getTestConfig(tmpDir), getTestConfig(tmpDir),
uploadToUploadsDomainFlags,
testApiDetails, testApiDetails,
getRecordingLogger(loggedMessages) getRecordingLogger(loggedMessages)
); );
@@ -381,7 +322,7 @@ test("Successfully uploading a database to uploads.github.com", async (t) => {
.returns("true"); .returns("true");
sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true); sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true);
mockHttpRequests(200, true, 201); await mockHttpRequests(uploadToUploadsDomainFlags, 201);
setCodeQL({ setCodeQL({
async databaseBundle(_: string, outputFilePath: string) { async databaseBundle(_: string, outputFilePath: string) {
@@ -393,6 +334,7 @@ test("Successfully uploading a database to uploads.github.com", async (t) => {
await uploadDatabases( await uploadDatabases(
testRepoName, testRepoName,
getTestConfig(tmpDir), getTestConfig(tmpDir),
uploadToUploadsDomainFlags,
testApiDetails, testApiDetails,
getRecordingLogger(loggedMessages) getRecordingLogger(loggedMessages)
); );
+13 -20
View File
@@ -4,6 +4,7 @@ import * as actionsUtil from "./actions-util";
import { getApiClient, GitHubApiDetails } from "./api-client"; import { getApiClient, GitHubApiDetails } from "./api-client";
import { getCodeQL } from "./codeql"; import { getCodeQL } from "./codeql";
import { Config } from "./config-utils"; import { Config } from "./config-utils";
import { FeatureFlag, FeatureFlags } from "./feature-flags";
import { Logger } from "./logging"; import { Logger } from "./logging";
import { RepositoryNwo } from "./repository"; import { RepositoryNwo } from "./repository";
import * as util from "./util"; import * as util from "./util";
@@ -12,6 +13,7 @@ import { bundleDb } from "./util";
export async function uploadDatabases( export async function uploadDatabases(
repositoryNwo: RepositoryNwo, repositoryNwo: RepositoryNwo,
config: Config, config: Config,
featureFlags: FeatureFlags,
apiDetails: GitHubApiDetails, apiDetails: GitHubApiDetails,
logger: Logger logger: Logger
): Promise<void> { ): Promise<void> {
@@ -32,36 +34,27 @@ export async function uploadDatabases(
return; return;
} }
const client = getApiClient(apiDetails); if (!(await featureFlags.getValue(FeatureFlag.DatabaseUploadsEnabled))) {
let useUploadDomain: boolean; logger.debug(
try { "Repository is not opted in to database uploads. Skipping upload."
const response = await client.request(
"GET /repos/:owner/:repo/code-scanning/codeql/databases",
{
owner: repositoryNwo.owner,
repo: repositoryNwo.repo,
}
); );
useUploadDomain = response.data["uploads_domain_enabled"];
} catch (e) {
if (util.isHTTPError(e) && e.status === 404) {
logger.debug(
"Repository is not opted in to database uploads. Skipping upload."
);
} else {
console.log(e);
logger.info(`Skipping database upload due to unknown error: ${e}`);
}
return; return;
} }
const client = getApiClient(apiDetails);
const codeql = await getCodeQL(config.codeQLCmd); const codeql = await getCodeQL(config.codeQLCmd);
const useUploadDomain = await featureFlags.getValue(
FeatureFlag.UploadsDomainEnabled
);
for (const language of config.languages) { for (const language of config.languages) {
// Upload the database bundle. // Upload the database bundle.
// Although we are uploading arbitrary file contents to the API, it's worth // Although we are uploading arbitrary file contents to the API, it's worth
// noting that it's the API's job to validate that the contents is acceptable. // noting that it's the API's job to validate that the contents is acceptable.
// This API method is available to anyone with write access to the repo. // This API method is available to anyone with write access to the repo.
const payload = fs.readFileSync(await bundleDb(config, language, codeql)); const payload = fs.readFileSync(
await bundleDb(config, language, codeql, language)
);
try { try {
if (useUploadDomain) { if (useUploadDomain) {
await client.request( await client.request(
+165
View File
@@ -0,0 +1,165 @@
import test from "ava";
import { GitHubApiDetails } from "./api-client";
import { FeatureFlag, GitHubFeatureFlags } from "./feature-flags";
import { getRunnerLogger } from "./logging";
import { parseRepositoryNwo } from "./repository";
import {
getRecordingLogger,
LoggedMessage,
mockFeatureFlagApiEndpoint,
setupActionsVars,
setupTests,
} from "./testing-utils";
import * as util from "./util";
import { GitHubVariant, initializeEnvironment, Mode, withTmpDir } from "./util";
setupTests(test);
test.beforeEach(() => {
initializeEnvironment(Mode.actions, "1.2.3");
});
const testApiDetails: GitHubApiDetails = {
auth: "1234",
url: "https://github.com",
};
const testRepositoryNwo = parseRepositoryNwo("github/example");
const ALL_FEATURE_FLAGS_DISABLED_VARIANTS: Array<{
description: string;
gitHubVersion: util.GitHubVersion;
}> = [
{
description: "GHES",
gitHubVersion: { type: GitHubVariant.GHES, version: "3.0.0" },
},
{ description: "GHAE", gitHubVersion: { type: GitHubVariant.GHAE } },
];
for (const variant of ALL_FEATURE_FLAGS_DISABLED_VARIANTS) {
test(`All feature flags are disabled if running against ${variant.description}`, async (t) => {
await withTmpDir(async (tmpDir) => {
setupActionsVars(tmpDir, tmpDir);
const loggedMessages = [];
const featureFlags = new GitHubFeatureFlags(
variant.gitHubVersion,
testApiDetails,
testRepositoryNwo,
getRecordingLogger(loggedMessages)
);
for (const flag of Object.values(FeatureFlag)) {
t.assert((await featureFlags.getValue(flag)) === false);
}
t.assert(
loggedMessages.find(
(v: LoggedMessage) =>
v.type === "debug" &&
v.message ===
"Not running against github.com. Disabling all feature flags."
) !== undefined
);
});
});
}
test("Feature flags are disabled if they're not returned in API response", async (t) => {
await withTmpDir(async (tmpDir) => {
setupActionsVars(tmpDir, tmpDir);
const loggedMessages = [];
const featureFlags = new GitHubFeatureFlags(
{ type: GitHubVariant.DOTCOM },
testApiDetails,
testRepositoryNwo,
getRecordingLogger(loggedMessages)
);
mockFeatureFlagApiEndpoint(200, {});
for (const flag of Object.values(FeatureFlag)) {
t.assert((await featureFlags.getValue(flag)) === false);
}
for (const featureFlag of [
"database_uploads_enabled",
"ml_powered_queries_enabled",
"uploads_domain_enabled",
]) {
t.assert(
loggedMessages.find(
(v: LoggedMessage) =>
v.type === "debug" &&
v.message ===
`Feature flag '${featureFlag}' undefined in API response, considering it disabled.`
) !== undefined
);
}
});
});
test("Feature flags exception is propagated if the API request errors", async (t) => {
await withTmpDir(async (tmpDir) => {
setupActionsVars(tmpDir, tmpDir);
const featureFlags = new GitHubFeatureFlags(
{ type: GitHubVariant.DOTCOM },
testApiDetails,
testRepositoryNwo,
getRunnerLogger(true)
);
mockFeatureFlagApiEndpoint(500, {});
await t.throwsAsync(async () => featureFlags.preloadFeatureFlags(), {
message:
"Encountered an error while trying to load feature flags: Error: some error message",
});
});
});
const FEATURE_FLAGS = [
"database_uploads_enabled",
"ml_powered_queries_enabled",
"uploads_domain_enabled",
];
for (const featureFlag of FEATURE_FLAGS) {
test(`Feature flag '${featureFlag}' is enabled if enabled in the API response`, async (t) => {
await withTmpDir(async (tmpDir) => {
setupActionsVars(tmpDir, tmpDir);
const featureFlags = new GitHubFeatureFlags(
{ type: GitHubVariant.DOTCOM },
testApiDetails,
testRepositoryNwo,
getRunnerLogger(true)
);
const expectedFeatureFlags = {};
for (const f of FEATURE_FLAGS) {
expectedFeatureFlags[f] = false;
}
expectedFeatureFlags[featureFlag] = true;
mockFeatureFlagApiEndpoint(200, expectedFeatureFlags);
const actualFeatureFlags = {
database_uploads_enabled: await featureFlags.getValue(
FeatureFlag.DatabaseUploadsEnabled
),
ml_powered_queries_enabled: await featureFlags.getValue(
FeatureFlag.MlPoweredQueriesEnabled
),
uploads_domain_enabled: await featureFlags.getValue(
FeatureFlag.UploadsDomainEnabled
),
};
t.deepEqual(actualFeatureFlags, expectedFeatureFlags);
});
});
}
+96
View File
@@ -0,0 +1,96 @@
import { getApiClient, GitHubApiDetails } from "./api-client";
import { Logger } from "./logging";
import { RepositoryNwo } from "./repository";
import * as util from "./util";
export interface FeatureFlags {
getValue(flag: FeatureFlag): Promise<boolean>;
}
export enum FeatureFlag {
DatabaseUploadsEnabled = "database_uploads_enabled",
MlPoweredQueriesEnabled = "ml_powered_queries_enabled",
UploadsDomainEnabled = "uploads_domain_enabled",
}
/**
* A response from the GitHub API that contains feature flag enablement information for the CodeQL
* Action.
*
* It maps feature flags to whether they are enabled or not.
*/
type FeatureFlagsApiResponse = Partial<Record<FeatureFlag, boolean>>;
export class GitHubFeatureFlags implements FeatureFlags {
private cachedApiResponse: FeatureFlagsApiResponse | undefined;
constructor(
private gitHubVersion: util.GitHubVersion,
private apiDetails: GitHubApiDetails,
private repositoryNwo: RepositoryNwo,
private logger: Logger
) {}
async getValue(flag: FeatureFlag): Promise<boolean> {
const response = (await this.getApiResponse())[flag];
if (response === undefined) {
this.logger.debug(
`Feature flag '${flag}' undefined in API response, considering it disabled.`
);
return false;
}
return response;
}
async preloadFeatureFlags(): Promise<void> {
await this.getApiResponse();
}
private async getApiResponse(): Promise<FeatureFlagsApiResponse> {
const loadApiResponse = async () => {
// Do nothing when not running against github.com
if (this.gitHubVersion.type !== util.GitHubVariant.DOTCOM) {
this.logger.debug(
"Not running against github.com. Disabling all feature flags."
);
return {};
}
const client = getApiClient(this.apiDetails);
try {
const response = await client.request(
"GET /repos/:owner/:repo/code-scanning/codeql-action/features",
{
owner: this.repositoryNwo.owner,
repo: this.repositoryNwo.repo,
}
);
return response.data;
} catch (e) {
// Some feature flags, such as `ml_powered_queries_enabled` affect the produced alerts.
// Considering these feature flags disabled in the event of a transient error could
// therefore lead to alert churn. As a result, we crash if we cannot determine the value of
// the feature flags.
throw new Error(
`Encountered an error while trying to load feature flags: ${e}`
);
}
};
const apiResponse = this.cachedApiResponse || (await loadApiResponse());
this.cachedApiResponse = apiResponse;
return apiResponse;
}
}
/**
* Create a feature flags instance with the specified set of enabled flags.
*
* This should be only used within tests.
*/
export function createFeatureFlags(enabledFlags: FeatureFlag[]): FeatureFlags {
return {
getValue: async (flag) => {
return enabledFlags.includes(flag);
},
};
}
+26 -2
View File
@@ -14,6 +14,7 @@ import {
} from "./actions-util"; } from "./actions-util";
import { CodeQL, CODEQL_VERSION_NEW_TRACING } from "./codeql"; import { CodeQL, CODEQL_VERSION_NEW_TRACING } from "./codeql";
import * as configUtils from "./config-utils"; import * as configUtils from "./config-utils";
import { GitHubFeatureFlags } from "./feature-flags";
import { import {
initCodeQL, initCodeQL,
initConfig, initConfig,
@@ -21,7 +22,7 @@ import {
installPythonDeps, installPythonDeps,
runInit, runInit,
} from "./init"; } from "./init";
import { Language } from "./languages"; import { isTracedLanguage, Language } from "./languages";
import { getActionsLogger } from "./logging"; import { getActionsLogger } from "./logging";
import { parseRepositoryNwo } from "./repository"; import { parseRepositoryNwo } from "./repository";
import { import {
@@ -34,6 +35,9 @@ import {
enrichEnvironment, enrichEnvironment,
getMemoryFlagValue, getMemoryFlagValue,
getThreadsFlagValue, getThreadsFlagValue,
DEFAULT_DEBUG_ARTIFACT_NAME,
DEFAULT_DEBUG_DATABASE_NAME,
checkNotWindows11,
} from "./util"; } from "./util";
// eslint-disable-next-line import/no-commonjs // eslint-disable-next-line import/no-commonjs
@@ -129,6 +133,18 @@ async function run() {
const gitHubVersion = await getGitHubVersion(apiDetails); const gitHubVersion = await getGitHubVersion(apiDetails);
checkGitHubVersionInRange(gitHubVersion, logger, Mode.actions); checkGitHubVersionInRange(gitHubVersion, logger, Mode.actions);
const repositoryNwo = parseRepositoryNwo(
getRequiredEnvParam("GITHUB_REPOSITORY")
);
const featureFlags = new GitHubFeatureFlags(
gitHubVersion,
apiDetails,
repositoryNwo,
logger
);
void featureFlags.preloadFeatureFlags();
try { try {
const workflowErrors = await validateWorkflow(); const workflowErrors = await validateWorkflow();
@@ -164,16 +180,24 @@ async function run() {
getOptionalInput("config-file"), getOptionalInput("config-file"),
getOptionalInput("db-location"), getOptionalInput("db-location"),
getOptionalInput("debug") === "true", getOptionalInput("debug") === "true",
parseRepositoryNwo(getRequiredEnvParam("GITHUB_REPOSITORY")), getOptionalInput("debug-artifact-name") || DEFAULT_DEBUG_ARTIFACT_NAME,
getOptionalInput("debug-database-name") || DEFAULT_DEBUG_DATABASE_NAME,
repositoryNwo,
getTemporaryDirectory(), getTemporaryDirectory(),
getRequiredEnvParam("RUNNER_TOOL_CACHE"), getRequiredEnvParam("RUNNER_TOOL_CACHE"),
codeql, codeql,
getRequiredEnvParam("GITHUB_WORKSPACE"), getRequiredEnvParam("GITHUB_WORKSPACE"),
gitHubVersion, gitHubVersion,
apiDetails, apiDetails,
featureFlags,
logger logger
); );
if (config.languages.some(isTracedLanguage)) {
// We currently do not support tracing on Windows 11 and Windows Server 2022
checkNotWindows11();
}
if ( if (
config.languages.includes(Language.python) && config.languages.includes(Language.python) &&
getRequiredInput("setup-python-dependencies") === "true" getRequiredInput("setup-python-dependencies") === "true"
+7
View File
@@ -8,6 +8,7 @@ import * as analysisPaths from "./analysis-paths";
import { GitHubApiCombinedDetails, GitHubApiDetails } from "./api-client"; import { GitHubApiCombinedDetails, GitHubApiDetails } from "./api-client";
import { CodeQL, CODEQL_VERSION_NEW_TRACING, setupCodeQL } from "./codeql"; import { CodeQL, CODEQL_VERSION_NEW_TRACING, setupCodeQL } from "./codeql";
import * as configUtils from "./config-utils"; import * as configUtils from "./config-utils";
import { FeatureFlags } from "./feature-flags";
import { Logger } from "./logging"; import { Logger } from "./logging";
import { RepositoryNwo } from "./repository"; import { RepositoryNwo } from "./repository";
import { TracerConfig, getCombinedTracerConfig } from "./tracer-config"; import { TracerConfig, getCombinedTracerConfig } from "./tracer-config";
@@ -44,6 +45,8 @@ export async function initConfig(
configFile: string | undefined, configFile: string | undefined,
dbLocation: string | undefined, dbLocation: string | undefined,
debugMode: boolean, debugMode: boolean,
debugArtifactName: string,
debugDatabaseName: string,
repository: RepositoryNwo, repository: RepositoryNwo,
tempDir: string, tempDir: string,
toolCacheDir: string, toolCacheDir: string,
@@ -51,6 +54,7 @@ export async function initConfig(
workspacePath: string, workspacePath: string,
gitHubVersion: util.GitHubVersion, gitHubVersion: util.GitHubVersion,
apiDetails: GitHubApiCombinedDetails, apiDetails: GitHubApiCombinedDetails,
featureFlags: FeatureFlags,
logger: Logger logger: Logger
): Promise<configUtils.Config> { ): Promise<configUtils.Config> {
logger.startGroup("Load language configuration"); logger.startGroup("Load language configuration");
@@ -61,6 +65,8 @@ export async function initConfig(
configFile, configFile,
dbLocation, dbLocation,
debugMode, debugMode,
debugArtifactName,
debugDatabaseName,
repository, repository,
tempDir, tempDir,
toolCacheDir, toolCacheDir,
@@ -68,6 +74,7 @@ export async function initConfig(
workspacePath, workspacePath,
gitHubVersion, gitHubVersion,
apiDetails, apiDetails,
featureFlags,
logger logger
); );
analysisPaths.printPathFiltersWarning(config, logger); analysisPaths.printPathFiltersWarning(config, logger);
+4
View File
@@ -9,6 +9,7 @@ import { runFinalize, runQueries } from "./analyze";
import { determineAutobuildLanguage, runAutobuild } from "./autobuild"; import { determineAutobuildLanguage, runAutobuild } from "./autobuild";
import { CodeQL, CODEQL_VERSION_NEW_TRACING, getCodeQL } from "./codeql"; import { CodeQL, CODEQL_VERSION_NEW_TRACING, getCodeQL } from "./codeql";
import { Config, getConfig } from "./config-utils"; import { Config, getConfig } from "./config-utils";
import { createFeatureFlags } from "./feature-flags";
import { initCodeQL, initConfig, injectWindowsTracer, runInit } from "./init"; import { initCodeQL, initConfig, injectWindowsTracer, runInit } from "./init";
import { Language, parseLanguage } from "./languages"; import { Language, parseLanguage } from "./languages";
import { getRunnerLogger } from "./logging"; import { getRunnerLogger } from "./logging";
@@ -251,6 +252,8 @@ program
cmd.configFile, cmd.configFile,
undefined, undefined,
false, false,
"",
"",
parseRepositoryNwo(cmd.repository), parseRepositoryNwo(cmd.repository),
tempDir, tempDir,
toolsDir, toolsDir,
@@ -258,6 +261,7 @@ program
workspacePath, workspacePath,
gitHubVersion, gitHubVersion,
apiDetails, apiDetails,
createFeatureFlags([]),
logger logger
); );
+60
View File
@@ -1,7 +1,11 @@
import * as github from "@actions/github";
import { TestInterface } from "ava"; import { TestInterface } from "ava";
import * as sinon from "sinon"; import * as sinon from "sinon";
import * as apiClient from "./api-client";
import * as CodeQL from "./codeql"; import * as CodeQL from "./codeql";
import { Logger } from "./logging";
import { HTTPError } from "./util";
type TestContext = { type TestContext = {
stdoutWrite: any; stdoutWrite: any;
@@ -89,3 +93,59 @@ export function setupActionsVars(tempDir: string, toolsDir: string) {
process.env["RUNNER_TEMP"] = tempDir; process.env["RUNNER_TEMP"] = tempDir;
process.env["RUNNER_TOOL_CACHE"] = toolsDir; process.env["RUNNER_TOOL_CACHE"] = toolsDir;
} }
export interface LoggedMessage {
type: "debug" | "info" | "warning" | "error";
message: string | Error;
}
export function getRecordingLogger(messages: LoggedMessage[]): Logger {
return {
debug: (message: string) => {
messages.push({ type: "debug", message });
console.debug(message);
},
info: (message: string) => {
messages.push({ type: "info", message });
console.info(message);
},
warning: (message: string | Error) => {
messages.push({ type: "warning", message });
console.warn(message);
},
error: (message: string | Error) => {
messages.push({ type: "error", message });
console.error(message);
},
isDebug: () => true,
startGroup: () => undefined,
endGroup: () => undefined,
};
}
/** Mock the HTTP request to the feature flags enablement API endpoint. */
export function mockFeatureFlagApiEndpoint(
responseStatusCode: number,
response: { [flagName: string]: boolean }
) {
// Passing an auth token is required, so we just use a dummy value
const client = github.getOctokit("123");
const requestSpy = sinon.stub(client, "request");
const optInSpy = requestSpy.withArgs(
"GET /repos/:owner/:repo/code-scanning/codeql-action/features"
);
if (responseStatusCode < 300) {
optInSpy.resolves({
status: responseStatusCode,
data: response,
headers: {},
url: "GET /repos/:owner/:repo/code-scanning/codeql-action/features",
});
} else {
optInSpy.throws(new HTTPError("some error message", responseStatusCode));
}
sinon.stub(apiClient, "getApiClient").value(() => client);
}
-6
View File
@@ -29,18 +29,12 @@ export async function toolrunnerErrorCatcher(
stdout += data.toString(); stdout += data.toString();
if (options?.listeners?.stdout !== undefined) { if (options?.listeners?.stdout !== undefined) {
options.listeners.stdout(data); options.listeners.stdout(data);
} else {
// if no stdout listener was originally defined then we match default behavior of Toolrunner
process.stdout.write(data);
} }
}, },
stderr: (data: Buffer) => { stderr: (data: Buffer) => {
stderr += data.toString(); stderr += data.toString();
if (options?.listeners?.stderr !== undefined) { if (options?.listeners?.stderr !== undefined) {
options.listeners.stderr(data); options.listeners.stderr(data);
} else {
// if no stderr listener was originally defined then we match default behavior of Toolrunner
process.stderr.write(data);
} }
}, },
}; };
+2
View File
@@ -30,6 +30,8 @@ function getTestConfig(tmpDir: string): configUtils.Config {
dbLocation: path.resolve(tmpDir, "codeql_databases"), dbLocation: path.resolve(tmpDir, "codeql_databases"),
packs: {}, packs: {},
debugMode: false, debugMode: false,
debugArtifactName: util.DEFAULT_DEBUG_ARTIFACT_NAME,
debugDatabaseName: util.DEFAULT_DEBUG_DATABASE_NAME,
}; };
} }
+19 -8
View File
@@ -26,9 +26,14 @@ const BROKEN_VERSIONS = ["0.0.0-20211207"];
export const GITHUB_DOTCOM_URL = "https://github.com"; export const GITHUB_DOTCOM_URL = "https://github.com";
/** /**
* Name of the debugging artifact. * Default name of the debugging artifact.
*/ */
export const DEBUG_ARTIFACT_NAME = "debug-artifacts"; export const DEFAULT_DEBUG_ARTIFACT_NAME = "debug-artifacts";
/**
* Default name of the database in the debugging artifact.
*/
export const DEFAULT_DEBUG_DATABASE_NAME = "db";
/** /**
* Get the extra options for the codeql commands. * Get the extra options for the codeql commands.
@@ -559,13 +564,11 @@ export async function codeQlVersionAbove(
export async function bundleDb( export async function bundleDb(
config: Config, config: Config,
language: Language, language: Language,
codeql: CodeQL codeql: CodeQL,
dbName: string
) { ) {
const databasePath = getCodeQLDatabasePath(config, language); const databasePath = getCodeQLDatabasePath(config, language);
const databaseBundlePath = path.resolve( const databaseBundlePath = path.resolve(config.dbLocation, `${dbName}.zip`);
config.dbLocation,
`${databasePath}.zip`
);
// For a tiny bit of added safety, delete the file if it exists. // For a tiny bit of added safety, delete the file if it exists.
// The file is probably from an earlier call to this function, either // The file is probably from an earlier call to this function, either
// as part of this action step or a previous one, but it could also be // as part of this action step or a previous one, but it could also be
@@ -574,7 +577,7 @@ export async function bundleDb(
if (fs.existsSync(databaseBundlePath)) { if (fs.existsSync(databaseBundlePath)) {
await del(databaseBundlePath, { force: true }); await del(databaseBundlePath, { force: true });
} }
await codeql.databaseBundle(databasePath, databaseBundlePath); await codeql.databaseBundle(databasePath, databaseBundlePath, dbName);
return databaseBundlePath; return databaseBundlePath;
} }
@@ -585,3 +588,11 @@ export async function delay(milliseconds: number) {
export function isGoodVersion(versionSpec: string) { export function isGoodVersion(versionSpec: string) {
return !BROKEN_VERSIONS.includes(versionSpec); return !BROKEN_VERSIONS.includes(versionSpec);
} }
export function checkNotWindows11() {
if (os.platform() === "win32" && semver.gte(os.release(), "10.0.20348")) {
throw new Error(
"Tracing builds with CodeQL is currently not supported on Windows 11 and Windows Server 2022. Please modify your Actions workflow to use an earlier version of Windows for this job, for example by setting `runs-on: windows-2019`."
);
}
}
+1 -1
View File
@@ -23,7 +23,7 @@ inputs:
wait-for-processing: wait-for-processing:
description: If true, the Action will wait for the uploaded SARIF to be processed before completing. description: If true, the Action will wait for the uploaded SARIF to be processed before completing.
required: true required: true
default: "false" default: "true"
runs: runs:
using: 'node12' using: 'node12'
main: '../lib/upload-sarif-action.js' main: '../lib/upload-sarif-action.js'