Compare commits

...

35 Commits

Author SHA1 Message Date
Edoardo Pirovano
89d78ba457 Merge pull request #729 from github/update-v1.0.13-4455bf8c
Merge main into v1
2021-09-06 12:49:34 +01:00
github-actions[bot]
e72d9f4a72 1.0.13 2021-09-06 09:02:00 +00:00
Andrew Eisenberg
4455bf8cd9 Merge pull request #723 from github/adityasharad/readme-indent
README: Minor formatting edits
2021-09-02 10:49:46 -07:00
Andrew Eisenberg
12300ac88e Merge branch 'main' into adityasharad/readme-indent 2021-09-01 21:03:17 -07:00
Aditya Sharad
11db623ba8 Merge pull request #724 from aeisenberg/aeisenberg/changelog
Update changelog
2021-09-01 16:35:44 -07:00
Andrew Eisenberg
3f515d3140 Update changelog 2021-09-01 15:58:18 -07:00
Aditya Sharad
a57642e1a0 README: Minor formatting edits 2021-09-01 15:56:15 -07:00
Andrew Eisenberg
62ef9f5eb2 Merge pull request #713 from github/aeisenberg/pr-check-names
Add names to all pr-checks
2021-09-01 15:47:24 -07:00
Andrew Eisenberg
e22a6cd3c9 Merge branch 'main' into aeisenberg/pr-check-names 2021-09-01 15:34:36 -07:00
Andrew Eisenberg
f9b0b9cb7b Merge pull request #715 from edoardopirovano/remove-old-loc
Remove old baseline LoC injection
2021-09-01 10:20:01 -07:00
Andrew Eisenberg
5fc16ebcf6 Merge branch 'main' into remove-old-loc 2021-09-01 09:49:28 -07:00
Andrew Eisenberg
7e2215bc92 Merge pull request #722 from github/esbena-patch-2
Fix typo in docstring
2021-09-01 08:47:47 -07:00
Andrew Eisenberg
3a016ebea8 Merge branch 'main' into remove-old-loc 2021-09-01 07:27:50 -07:00
Andrew Eisenberg
2ba7208ff2 Merge branch 'main' into aeisenberg/pr-check-names 2021-09-01 07:27:25 -07:00
Andrew Eisenberg
72399ae69a Merge branch 'main' into esbena-patch-2 2021-09-01 07:26:43 -07:00
Andrew Eisenberg
c0a58782b6 Merge pull request #721 from github/aeisenberg/update-pack-version
Update integration test pack versions
2021-08-31 21:47:11 -07:00
Andrew Eisenberg
d1ff4d6297 Try the nightly build for packaging integration tests 2021-08-31 19:21:37 -07:00
Andrew Eisenberg
80a6b3a41e Merge branch 'main' into remove-old-loc 2021-08-31 14:58:37 -07:00
Esben Sparre Andreasen
1c27c52804 Fix typo in docstring 2021-08-31 09:27:30 +02:00
Andrew Eisenberg
e833d6e84c Update integration test pack versions 2021-08-26 15:59:11 -07:00
Andrew Eisenberg
8a0c541e24 Merge branch 'main' into aeisenberg/pr-check-names 2021-08-26 10:05:30 -07:00
Andrew Eisenberg
e2d592dc8f Merge pull request #714 from github/aeisenberg/update-linguist
Upgrade linguist dependency
2021-08-26 10:04:42 -07:00
Edoardo Pirovano
2e71e02553 Remove old baseline LoC injection 2021-08-26 13:46:22 +01:00
Andrew Eisenberg
b29bf7b05a Upgrade linguist dependency
This version changes how it counts python heredoc. All heredoc is
counted as code.
2021-08-25 11:15:45 -07:00
Andrew Eisenberg
1785bbb7d8 Add names to all pr-checks 2021-08-25 10:38:25 -07:00
Edoardo Pirovano
a44b61d961 Merge pull request #707 from edoardopirovano/cli-version
Improve handling of CLI versions
2021-08-25 15:52:37 +01:00
Henry Mercer
a062fc9bf5 Merge branch 'main' into cli-version 2021-08-25 15:33:18 +01:00
Aditya Sharad
50de2e4d1e Merge pull request #712 from github/hmakholm/pr/2.6.0
Update CodeQL bundle to 20210824 / 2.6.0
2021-08-24 15:32:25 -07:00
Edoardo Pirovano
132e08a05f Bump version of testing pack 2021-08-24 23:18:22 +01:00
Henning Makholm
720884501a Update CodeQL bundle to 20210824 / 2.6.0 2021-08-24 23:06:42 +02:00
Edoardo Pirovano
fd45eac830 Address PR comments from @henrymercer 2021-08-18 16:39:00 +01:00
Edoardo Pirovano
e70ec1d70e Test against oldest supported version 2021-08-18 11:48:12 +01:00
Edoardo Pirovano
70d2efc353 Enforce a minimum version of CodeQL CLI 2021-08-18 11:48:12 +01:00
Edoardo Pirovano
fb77829455 Version flag usage of certain CLI flags 2021-08-18 09:44:49 +01:00
Edoardo Pirovano
4ba53e33d7 Cache result of codeql version 2021-08-18 09:26:33 +01:00
67 changed files with 648 additions and 606 deletions

View File

@@ -1,4 +1,4 @@
name: "PR checks"
name: PR checks
env:
GO111MODULE: auto
@@ -14,6 +14,7 @@ on:
jobs:
lint-js:
name: Lint
runs-on: ubuntu-latest
steps:
@@ -26,10 +27,11 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Check generated JavaScript
- name: Check generated JS
run: .github/workflows/script/check-js.sh
check-node-modules:
name: Check modules up to date
runs-on: macos-latest
steps:
@@ -38,6 +40,7 @@ jobs:
run: .github/workflows/script/check-node-modules.sh
npm-test:
name: Unit Test
needs: [check-js, check-node-modules]
strategy:
matrix:
@@ -50,6 +53,7 @@ jobs:
run: npm run-script test
multi-language-repo_test-autodetect-languages:
name: Autodetect language (multi)
needs: [check-js, check-node-modules]
runs-on: ubuntu-latest
@@ -107,6 +111,7 @@ jobs:
# Packaging test that runs against a javascript database
# Specifying packs in the config file.
test-packaging-javascript-config:
name: Packaging Config JS
needs: [check-js, check-node-modules]
runs-on: ubuntu-latest
@@ -123,6 +128,8 @@ jobs:
with:
config-file: ".github/codeql/codeql-config-packaging.yml"
languages: javascript
# This version is known to worl with 0.1.0
tools: https://github.com/dsp-testing/codeql-cli-nightlies/releases/download/codeql-bundle-20210831-manual/codeql-bundle.tar.gz
- name: Build code
shell: bash
run: ./build.sh
@@ -148,6 +155,7 @@ jobs:
# Packaging test that runs against a javascript database
# Specifying packs as an input.
test-packaging-javascript-inputs:
name: Packaging Inputs JS
needs: [check-js, check-node-modules]
runs-on: ubuntu-latest
@@ -164,7 +172,9 @@ jobs:
with:
config-file: ".github/codeql/codeql-config-packaging2.yml"
languages: javascript
packs: dsp-testing/codeql-pack1@0.0.4, dsp-testing/codeql-pack2
packs: dsp-testing/codeql-pack1@0.1.0, dsp-testing/codeql-pack2
# This version is known to worl with 0.1.0
tools: https://github.com/dsp-testing/codeql-cli-nightlies/releases/download/codeql-bundle-20210831-manual/codeql-bundle.tar.gz
- name: Build code
shell: bash
@@ -191,6 +201,7 @@ jobs:
# Packaging test that runs against a javascript database
# Specifying packs in the config file and inputs.
test-packaging-javascript-config-and-inputs:
name: Packaging Inputs and Config JS
needs: [check-js, check-node-modules]
runs-on: ubuntu-latest
@@ -206,8 +217,10 @@ jobs:
- uses: ./../action/init
with:
config-file: ".github/codeql/codeql-config-packaging3.yml"
packs: +dsp-testing/codeql-pack1@0.0.4
packs: +dsp-testing/codeql-pack1@0.1.0
languages: javascript
# This version is known to worl with 0.1.0
tools: https://github.com/dsp-testing/codeql-cli-nightlies/releases/download/codeql-bundle-20210831-manual/codeql-bundle.tar.gz
- name: Build code
shell: bash
@@ -233,6 +246,7 @@ jobs:
# Tests a split workflow where database construction and query execution happen in different steps
test-split-workflow:
name: Split workflow
needs: [check-js, check-node-modules]
runs-on: ubuntu-latest
@@ -248,9 +262,10 @@ jobs:
- uses: ./../action/init
with:
config-file: ".github/codeql/codeql-config-packaging3.yml"
packs: +dsp-testing/codeql-pack1@0.0.4
packs: +dsp-testing/codeql-pack1@0.1.0
languages: javascript
tools: latest
# This version is known to worl with 0.1.0
tools: https://github.com/dsp-testing/codeql-cli-nightlies/releases/download/codeql-bundle-20210831-manual/codeql-bundle.tar.gz
- name: Build code
shell: bash
run: ./build.sh
@@ -287,12 +302,16 @@ jobs:
# Identify the CodeQL tool versions to integration test against.
check-codeql-versions:
name: Check CodeQL Versions
needs: [check-js, check-node-modules]
runs-on: ubuntu-latest
outputs:
versions: ${{ steps.compare.outputs.versions }}
nightly-url: ${{ steps.get-url.outputs.nightly-url }}
env:
# URL of the oldest release that we support, if this is being bumped then the constant
# CODEQL_MINIMUM_VERSION in the file codeql.ts should also be bumped to match this.
OLDEST_URL: https://github.com/github/codeql-action/releases/download/codeql-bundle-20201028/codeql-bundle.tar.gz
steps:
- uses: actions/checkout@v2
- name: Move codeql-action
@@ -336,31 +355,44 @@ jobs:
with:
tools: ${{ steps.get-url.outputs.nightly-url }}
languages: javascript
- name: Remove empty database
# allows us to run init a fourth time
run: |
rm -rf "$RUNNER_TEMP/codeql_databases"
- name: Init with a CodeQL bundle from the oldest supported release
id: init-oldest
uses: ./../action/init
with:
tools: ${{ env.OLDEST_URL }}
languages: javascript
- name: Compare CodeQL bundle versions
id: compare
env:
CODEQL_DEFAULT: ${{ steps.init-default.outputs.codeql-path }}
CODEQL_LATEST: ${{ steps.init-latest.outputs.codeql-path }}
CODEQL_NIGHTLY: ${{ steps.init-nightly.outputs.codeql-path }}
CODEQL_OLDEST: ${{ steps.init-oldest.outputs.codeql-path }}
NIGHTLY_URL: ${{ steps.get-url.outputs.nightly-url }}
run: |
CODEQL_VERSION_DEFAULT="$("$CODEQL_DEFAULT" version --format terse)"
CODEQL_VERSION_LATEST="$("$CODEQL_LATEST" version --format terse)"
CODEQL_VERSION_NIGHTLY="$("$CODEQL_NIGHTLY" version --format terse)"
CODEQL_VERSION_OLDEST="$("$CODEQL_OLDEST" version --format terse)"
echo "Default CodeQL bundle version is $CODEQL_VERSION_DEFAULT"
echo "Latest CodeQL bundle version is $CODEQL_VERSION_LATEST"
echo "Nightly CodeQL bundle version is $CODEQL_VERSION_NIGHTLY"
echo "Oldest supported CodeQL bundle version is $CODEQL_VERSION_OLDEST"
# If we're running on a pull request, run each integration test with all three bundles, even
# If we're running on a pull request, run each integration test with all four bundles, even
# if `tools: latest` would be the same as `tools: null`. This allows us to make the
# integration test job for each of the three bundles a required status check.
# integration test job for each of the four bundles a required status check.
#
# If we're running on push, then we can skip running with `tools: latest` when it would be
# the same as running with `tools: null`.
if [[ "$GITHUB_EVENT_NAME" != "pull_request" && "$CODEQL_VERSION_DEFAULT" == "$CODEQL_VERSION_LATEST" ]]; then
VERSIONS_JSON="[null, \"$NIGHTLY_URL\"]"
VERSIONS_JSON="[null, \"$NIGHTLY_URL\", \"$OLDEST_URL\"]"
else
VERSIONS_JSON="[null, \"$NIGHTLY_URL\", \"latest\"]"
VERSIONS_JSON="[null, \"$NIGHTLY_URL\", \"$OLDEST_URL\", \"latest\"]"
fi
# Output a JSON-encoded list with the distinct versions to test against.
@@ -368,6 +400,7 @@ jobs:
echo "::set-output name=versions::${VERSIONS_JSON}"
multi-language-repo_test-custom-queries-and-remote-config:
name: Remote Config Custom Queries multi-language repo
needs: [check-js, check-node-modules, check-codeql-versions]
strategy:
fail-fast: false
@@ -399,6 +432,7 @@ jobs:
# Currently is not possible to analyze Go in conjunction with other languages in macos
multi-language-repo_test-go-custom-queries:
name: Go custom queries multi-language repo
needs: [check-js, check-node-modules, check-codeql-versions]
strategy:
fail-fast: false
@@ -433,6 +467,7 @@ jobs:
TEST_MODE: true
go-custom-tracing:
name: Go custom tracing
needs: [check-js, check-node-modules, check-codeql-versions]
strategy:
fail-fast: false
@@ -468,6 +503,7 @@ jobs:
TEST_MODE: true
go-custom-tracing-autobuild:
name: Go autobuild custom tracing
needs: [check-js, check-node-modules, check-codeql-versions]
strategy:
fail-fast: false
@@ -505,6 +541,7 @@ jobs:
# Ruby is in beta, so test it separately for now.
multi-language-repo_test-ruby:
name: Ruby multi-language
needs: [check-js, check-node-modules, check-codeql-versions]
strategy:
fail-fast: false
@@ -545,6 +582,7 @@ jobs:
fi
multi-language-repo_rubocop:
name: Rubocop multi-language
needs: [check-js, check-node-modules]
runs-on: ubuntu-latest
@@ -578,6 +616,7 @@ jobs:
TEST_MODE: true
test-proxy:
name: Proxy
needs: [check-js, check-node-modules, check-codeql-versions]
strategy:
fail-fast: false
@@ -612,6 +651,7 @@ jobs:
TEST_MODE: true
runner-analyze-javascript-ubuntu:
name: Runner ubuntu JS analyze
needs: [check-js, check-node-modules]
runs-on: ubuntu-latest
@@ -639,6 +679,7 @@ jobs:
TEST_MODE: true
runner-analyze-javascript-windows:
name: Runner windows JS analyze
needs: [check-js, check-node-modules]
runs-on: windows-latest
@@ -662,6 +703,7 @@ jobs:
TEST_MODE: true
runner-analyze-javascript-macos:
name: Runner macos JS analyze
needs: [check-js, check-node-modules]
runs-on: macos-latest
@@ -685,6 +727,7 @@ jobs:
TEST_MODE: true
runner-analyze-csharp-ubuntu:
name: Runner ubuntu C# analyze
needs: [check-js, check-node-modules]
runs-on: ubuntu-latest
@@ -721,6 +764,7 @@ jobs:
TEST_MODE: true
runner-analyze-csharp-windows:
name: Runner windows C# analyze
needs: [check-js, check-node-modules]
runs-on: windows-latest
@@ -760,6 +804,7 @@ jobs:
TEST_MODE: true
runner-analyze-csharp-macos:
name: Runner macos C# analyze
needs: [check-js, check-node-modules]
runs-on: macos-latest
@@ -798,6 +843,7 @@ jobs:
runner-analyze-csharp-autobuild-ubuntu:
name: Runner ubuntu autobuild C# analyze
needs: [check-js, check-node-modules]
runs-on: ubuntu-latest
@@ -833,6 +879,7 @@ jobs:
TEST_MODE: true
runner-analyze-csharp-autobuild-windows:
name: Runner windows autobuild C# analyze
needs: [check-js, check-node-modules]
runs-on: windows-latest
@@ -869,6 +916,7 @@ jobs:
TEST_MODE: true
runner-analyze-csharp-autobuild-macos:
name: Runner macos autobuild C# analyze
needs: [check-js, check-node-modules]
runs-on: macos-latest
@@ -905,6 +953,7 @@ jobs:
TEST_MODE: true
runner-upload-sarif:
name: Runner upload sarif
needs: [check-js, check-node-modules]
runs-on: ubuntu-latest
@@ -926,6 +975,7 @@ jobs:
runner/dist/codeql-runner-linux upload --sarif-file src/testdata/empty-sarif.sarif --repository $GITHUB_REPOSITORY --commit $GITHUB_SHA --ref $GITHUB_REF --github-url $GITHUB_SERVER_URL --github-auth ${{ github.token }}
multi-language-repo_test-local-codeql:
name: Local codeql multi-language repo
needs: [check-js, check-node-modules, check-codeql-versions]
runs-on: ubuntu-latest
@@ -946,6 +996,7 @@ jobs:
- uses: ./../action/analyze
test-javascript-source-root:
name: JS source root
needs: [check-js, check-node-modules]
runs-on: ubuntu-latest

View File

@@ -1,8 +1,10 @@
# CodeQL Action and CodeQL Runner Changelog
## [UNRELEASED]
## 1.0.13 - 06 Sep 2021
No user facing changes.
- Update default CodeQL bundle version to 2.6.0. [#712](https://github.com/github/codeql-action/pull/712)
- Update baseline lines of code counter for python. All multi-line strings are counted as code. [#714](https://github.com/github/codeql-action/pull/714)
- Remove old baseline LoC injection [#715](https://github.com/github/codeql-action/pull/715)
## 1.0.12 - 16 Aug 2021

View File

@@ -91,8 +91,8 @@ If you prefer to integrate this within an existing CI workflow, it should end up
# Here is where you build your code
- run: |
make bootstrap
make release
make bootstrap
make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1

24
lib/analyze.js generated
View File

@@ -67,7 +67,7 @@ async function createdDBForScannedLanguages(config, logger) {
// Insert the LGTM_INDEX_X env vars at this point so they are set when
// we extract any scanned languages.
analysisPaths.includeAndExcludeAnalysisPaths(config);
const codeql = codeql_1.getCodeQL(config.codeQLCmd);
const codeql = await codeql_1.getCodeQL(config.codeQLCmd);
for (const language of config.languages) {
if (languages_1.isScannedLanguage(language) &&
!dbIsFinalized(config, language, logger)) {
@@ -93,7 +93,7 @@ function dbIsFinalized(config, language, logger) {
}
async function finalizeDatabaseCreation(config, threadsFlag, memoryFlag, logger) {
await createdDBForScannedLanguages(config, logger);
const codeql = codeql_1.getCodeQL(config.codeQLCmd);
const codeql = await codeql_1.getCodeQL(config.codeQLCmd);
for (const language of config.languages) {
if (dbIsFinalized(config, language, logger)) {
logger.info(`There is already a finalized database for ${language} at the location where the CodeQL Action places databases, so we did not create one.`);
@@ -130,7 +130,7 @@ async function runQueries(sarifFolder, memoryFlag, addSnippetsFlag, threadsFlag,
logger.info("And should not be used in production yet.");
logger.info("*************");
logger.startGroup(`Downloading custom packs for ${language}`);
const codeql = codeql_1.getCodeQL(config.codeQLCmd);
const codeql = await codeql_1.getCodeQL(config.codeQLCmd);
const results = await codeql.packDownload(packsWithVersion);
logger.info(`Downloaded packs: ${results.packs
.map((r) => `${r.name}@${r.version || "latest"}`)
@@ -183,7 +183,7 @@ async function runQueries(sarifFolder, memoryFlag, addSnippetsFlag, threadsFlag,
return statusReport;
async function runInterpretResults(language, queries, sarifFile) {
const databasePath = util.getCodeQLDatabasePath(config, language);
const codeql = codeql_1.getCodeQL(config.codeQLCmd);
const codeql = await codeql_1.getCodeQL(config.codeQLCmd);
return await codeql.databaseInterpretResults(databasePath, queries, sarifFile, addSnippetsFlag, threadsFlag, automationDetailsId);
}
async function runQueryGroup(language, type, querySuiteContents, searchPath) {
@@ -193,7 +193,7 @@ async function runQueries(sarifFolder, memoryFlag, addSnippetsFlag, threadsFlag,
const querySuitePath = `${databasePath}-queries-${type}.qls`;
fs.writeFileSync(querySuitePath, querySuiteContents);
logger.debug(`Query suite file for ${language}-${type}...\n${querySuiteContents}`);
const codeql = codeql_1.getCodeQL(config.codeQLCmd);
const codeql = await codeql_1.getCodeQL(config.codeQLCmd);
await codeql.databaseRunQueries(databasePath, searchPath, querySuitePath, memoryFlag, threadsFlag);
logger.debug(`BQRS results produced for ${language} (queries: ${type})"`);
return querySuitePath;
@@ -223,7 +223,7 @@ exports.runFinalize = runFinalize;
async function runCleanup(config, cleanupLevel, logger) {
logger.startGroup("Cleaning up databases");
for (const language of config.languages) {
const codeql = codeql_1.getCodeQL(config.codeQLCmd);
const codeql = await codeql_1.getCodeQL(config.codeQLCmd);
const databasePath = util.getCodeQLDatabasePath(config, language);
await codeql.databaseCleanup(databasePath, cleanupLevel);
}
@@ -233,24 +233,14 @@ exports.runCleanup = runCleanup;
async function injectLinesOfCode(sarifFile, language, locPromise) {
var _a;
const lineCounts = await locPromise;
const idPrefix = count_loc_1.getIdPrefix(language);
if (language in lineCounts) {
const sarif = JSON.parse(fs.readFileSync(sarifFile, "utf8"));
if (Array.isArray(sarif.runs)) {
for (const run of sarif.runs) {
// Old style: Baseline is inserted when rule ID has suffix /summary/lines-of-code
const ruleId = `${idPrefix}/summary/lines-of-code`;
run.properties = run.properties || {};
run.properties.metricResults = run.properties.metricResults || [];
const rule = run.properties.metricResults.find(
// the rule id can be in either of two places
(r) => { var _a; return r.ruleId === ruleId || ((_a = r.rule) === null || _a === void 0 ? void 0 : _a.id) === ruleId; });
// only add the baseline value if the rule already exists
if (rule) {
rule.baseline = lineCounts[language];
}
// New style: Baseline is inserted when matching rule has tag lines-of-code
for (const metric of run.properties.metricResults) {
// Baseline is inserted when matching rule has tag lines-of-code
if (metric.rule && metric.rule.toolComponent) {
const matchingRule = run.tool.extensions[metric.rule.toolComponent.index].rules[metric.rule.index];
if ((_a = matchingRule.properties.tags) === null || _a === void 0 ? void 0 : _a.includes("lines-of-code")) {

File diff suppressed because one or more lines are too long

50
lib/analyze.test.js generated
View File

@@ -30,7 +30,6 @@ const semver_1 = require("semver");
const sinon = __importStar(require("sinon"));
const analyze_1 = require("./analyze");
const codeql_1 = require("./codeql");
const count_loc_1 = require("./count-loc");
const count = __importStar(require("./count-loc"));
const languages_1 = require("./languages");
const logging_1 = require("./logging");
@@ -76,31 +75,7 @@ ava_1.default("status report fields and search path setting", async (t) => {
databaseInterpretResults: async (_db, _queriesRun, sarifFile) => {
fs.writeFileSync(sarifFile, JSON.stringify({
runs: [
// variant 1 uses ruleId
{
properties: {
metricResults: [
{
ruleId: `${count_loc_1.getIdPrefix(language)}/summary/lines-of-code`,
value: 123,
},
],
},
},
// variant 2 uses rule.id
{
properties: {
metricResults: [
{
rule: {
id: `${count_loc_1.getIdPrefix(language)}/summary/lines-of-code`,
},
value: 123,
},
],
},
},
// variant 3 references a rule with the lines-of-code tag
// references a rule with the lines-of-code tag, so baseline should be injected
{
tool: {
extensions: [
@@ -199,29 +174,12 @@ ava_1.default("status report fields and search path setting", async (t) => {
function verifyLineCounts(tmpDir) {
// eslint-disable-next-line github/array-foreach
Object.keys(languages_1.Language).forEach((lang, i) => {
verifyLineCountForFile(lang, path.join(tmpDir, `${lang}.sarif`), i + 1);
verifyLineCountForFile(path.join(tmpDir, `${lang}.sarif`), i + 1);
});
}
function verifyLineCountForFile(lang, filePath, lineCount) {
const idPrefix = count_loc_1.getIdPrefix(lang);
function verifyLineCountForFile(filePath, lineCount) {
const sarif = JSON.parse(fs.readFileSync(filePath, "utf8"));
t.deepEqual(sarif.runs[0].properties.metricResults, [
{
ruleId: `${idPrefix}/summary/lines-of-code`,
value: 123,
baseline: lineCount,
},
]);
t.deepEqual(sarif.runs[1].properties.metricResults, [
{
rule: {
id: `${idPrefix}/summary/lines-of-code`,
},
value: 123,
baseline: lineCount,
},
]);
t.deepEqual(sarif.runs[2].properties.metricResults, [
{
rule: {
index: 0,
@@ -234,7 +192,7 @@ ava_1.default("status report fields and search path setting", async (t) => {
},
]);
// when the rule doesn't exist, it should not be added
t.deepEqual(sarif.runs[3].properties.metricResults, []);
t.deepEqual(sarif.runs[1].properties.metricResults, []);
}
function verifyQuerySuites(tmpDir) {
const qlsContent = [

File diff suppressed because one or more lines are too long

2
lib/autobuild.js generated
View File

@@ -25,7 +25,7 @@ function determineAutobuildLanguage(config, logger) {
exports.determineAutobuildLanguage = determineAutobuildLanguage;
async function runAutobuild(language, config, logger) {
logger.startGroup(`Attempting to automatically build ${language} code`);
const codeQL = codeql_1.getCodeQL(config.codeQLCmd);
const codeQL = await codeql_1.getCodeQL(config.codeQLCmd);
await codeQL.runAutobuild(language);
logger.endGroup();
}

View File

@@ -1 +1 @@
{"version":3,"file":"autobuild.js","sourceRoot":"","sources":["../src/autobuild.ts"],"names":[],"mappings":";;;AAAA,qCAAqC;AAErC,2CAAyD;AAGzD,SAAgB,0BAA0B,CACxC,MAA2B,EAC3B,MAAc;IAEd,0CAA0C;IAC1C,mFAAmF;IACnF,oFAAoF;IACpF,4EAA4E;IAC5E,MAAM,kBAAkB,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,4BAAgB,CAAC,CAAC;IACrE,MAAM,QAAQ,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC;IAEvC,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,CAAC,IAAI,CACT,iEAAiE,CAClE,CAAC;QACF,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,CAAC,KAAK,CAAC,sCAAsC,QAAQ,EAAE,CAAC,CAAC;IAE/D,IAAI,kB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,CAAC,uDAAuD,CACxE,CAAC;KACH;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AA7BD,gEA6BC;AAEM,KAAK,UAAU,YAAY,CAChC,QAAkB,EAClB,MAA2B,EAC3B,MAAc;IAEd,MAAM,CAAC,UAAU,CAAC,qCAAqC,QAAQ,OAAO,CAAC,CAAC;IACxE,MAAM,MAAM,GAAG,MAAM,kBAAS,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACjD,MAAM,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IACpC,MAAM,CAAC,QAAQ,EAAE,CAAC;AACpB,CAAC;AATD,oCASC"}

52
lib/codeql.js generated
View File

@@ -51,7 +51,25 @@ exports.CommandInvocationError = CommandInvocationError;
let cachedCodeQL = undefined;
const CODEQL_BUNDLE_VERSION = defaults.bundleVersion;
const CODEQL_DEFAULT_ACTION_REPOSITORY = "github/codeql-action";
/**
* The oldest version of CodeQL that the Action will run with. This should be
* at least three minor versions behind the current version. The version flags
* below can be used to conditionally enable certain features on versions newer
* than this. Please record the reason we cannot support an older version.
*
* Reason: Changes to how the tracing environment is set up.
*/
const CODEQL_MINIMUM_VERSION = "2.3.1";
/**
* Versions of CodeQL that version-flag certain functionality in the Action.
* For convenience, please keep these in descending order. Once a version
* flag is older than the oldest supported version above, it may be removed.
*/
const CODEQL_VERSION_RAM_FINALIZE = "2.5.8";
const CODEQL_VERSION_DIAGNOSTICS = "2.5.6";
const CODEQL_VERSION_METRICS = "2.5.5";
const CODEQL_VERSION_GROUP_RULES = "2.5.5";
const CODEQL_VERSION_SARIF_GROUP = "2.5.3";
function getCodeQLBundleName() {
let platform;
if (process.platform === "win32") {
@@ -160,7 +178,7 @@ async function getCodeQLBundleDownloadURL(apiDetails, variant, logger) {
}
return `https://github.com/${CODEQL_DEFAULT_ACTION_REPOSITORY}/releases/download/${CODEQL_BUNDLE_VERSION}/${codeQLBundleName}`;
}
async function setupCodeQL(codeqlURL, apiDetails, tempDir, toolCacheDir, variant, logger) {
async function setupCodeQL(codeqlURL, apiDetails, tempDir, toolCacheDir, variant, logger, checkVersion) {
try {
// We use the special value of 'latest' to prioritize the version in the
// defaults over any pinned cached version.
@@ -228,7 +246,7 @@ async function setupCodeQL(codeqlURL, apiDetails, tempDir, toolCacheDir, variant
else if (process.platform !== "linux" && process.platform !== "darwin") {
throw new Error(`Unsupported platform: ${process.platform}`);
}
cachedCodeQL = getCodeQLForCmd(codeqlCmd);
cachedCodeQL = await getCodeQLForCmd(codeqlCmd, checkVersion);
return { codeql: cachedCodeQL, toolsVersion: codeqlURLVersion };
}
catch (e) {
@@ -260,9 +278,9 @@ exports.convertToSemVer = convertToSemVer;
/**
* Use the CodeQL executable located at the given path.
*/
function getCodeQL(cmd) {
async function getCodeQL(cmd) {
if (cachedCodeQL === undefined) {
cachedCodeQL = getCodeQLForCmd(cmd);
cachedCodeQL = await getCodeQLForCmd(cmd, true);
}
return cachedCodeQL;
}
@@ -320,13 +338,16 @@ function getCachedCodeQL() {
return cachedCodeQL;
}
exports.getCachedCodeQL = getCachedCodeQL;
function getCodeQLForCmd(cmd) {
return {
async function getCodeQLForCmd(cmd, checkVersion) {
let cachedVersion = undefined;
const codeql = {
getPath() {
return cmd;
},
async getVersion() {
return await runTool(cmd, ["version", "--format=terse"]);
if (cachedVersion === undefined)
cachedVersion = runTool(cmd, ["version", "--format=terse"]);
return await cachedVersion;
},
async printVersion() {
await runTool(cmd, ["version", "--format=json"]);
@@ -495,15 +516,19 @@ function getCodeQLForCmd(cmd) {
"interpret-results",
threadsFlag,
"--format=sarif-latest",
"--print-diagnostics-summary",
"--print-metrics-summary",
"--sarif-group-rules-by-pack",
"-v",
`--output=${sarifFile}`,
addSnippetsFlag,
...getExtraOptionsFromEnv(["database", "interpret-results"]),
];
if (automationDetailsId !== undefined) {
if (await util.codeQlVersionAbove(this, CODEQL_VERSION_DIAGNOSTICS))
codeqlArgs.push("--print-diagnostics-summary");
if (await util.codeQlVersionAbove(this, CODEQL_VERSION_METRICS))
codeqlArgs.push("--print-metrics-summary");
if (await util.codeQlVersionAbove(this, CODEQL_VERSION_GROUP_RULES))
codeqlArgs.push("--sarif-group-rules-by-pack");
if (automationDetailsId !== undefined &&
(await util.codeQlVersionAbove(this, CODEQL_VERSION_SARIF_GROUP))) {
codeqlArgs.push("--sarif-category", automationDetailsId);
}
codeqlArgs.push(databasePath, ...querySuitePaths);
@@ -565,6 +590,11 @@ function getCodeQLForCmd(cmd) {
await new toolrunner.ToolRunner(cmd, args).exec();
},
};
if (checkVersion &&
!(await util.codeQlVersionAbove(codeql, CODEQL_MINIMUM_VERSION))) {
throw new Error(`Expected a CodeQL CLI with version at least ${CODEQL_MINIMUM_VERSION} but got version ${await codeql.getVersion()}`);
}
return codeql;
}
function packWithVersionToString(pack) {
return pack.version ? `${pack.packName}@${pack.version}` : pack.packName;

File diff suppressed because one or more lines are too long

20
lib/codeql.test.js generated
View File

@@ -53,7 +53,7 @@ ava_1.default("download codeql bundle cache", async (t) => {
nock_1.default("https://example.com")
.get(`/download/codeql-bundle-${version}/codeql-bundle.tar.gz`)
.replyWithFile(200, path.join(__dirname, `/../src/testdata/codeql-bundle.tar.gz`));
await codeql.setupCodeQL(`https://example.com/download/codeql-bundle-${version}/codeql-bundle.tar.gz`, sampleApiDetails, tmpDir, tmpDir, util.GitHubVariant.DOTCOM, logging_1.getRunnerLogger(true));
await codeql.setupCodeQL(`https://example.com/download/codeql-bundle-${version}/codeql-bundle.tar.gz`, sampleApiDetails, tmpDir, tmpDir, util.GitHubVariant.DOTCOM, logging_1.getRunnerLogger(true), false);
t.assert(toolcache.find("CodeQL", `0.0.0-${version}`));
}
const cachedVersions = toolcache.findAllVersions("CodeQL");
@@ -66,12 +66,12 @@ ava_1.default("download codeql bundle cache explicitly requested with pinned dif
nock_1.default("https://example.com")
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
.replyWithFile(200, path.join(__dirname, `/../src/testdata/codeql-bundle-pinned.tar.gz`));
await codeql.setupCodeQL("https://example.com/download/codeql-bundle-20200601/codeql-bundle.tar.gz", sampleApiDetails, tmpDir, tmpDir, util.GitHubVariant.DOTCOM, logging_1.getRunnerLogger(true));
await codeql.setupCodeQL("https://example.com/download/codeql-bundle-20200601/codeql-bundle.tar.gz", sampleApiDetails, tmpDir, tmpDir, util.GitHubVariant.DOTCOM, logging_1.getRunnerLogger(true), false);
t.assert(toolcache.find("CodeQL", "0.0.0-20200601"));
nock_1.default("https://example.com")
.get(`/download/codeql-bundle-20200610/codeql-bundle.tar.gz`)
.replyWithFile(200, path.join(__dirname, `/../src/testdata/codeql-bundle.tar.gz`));
await codeql.setupCodeQL("https://example.com/download/codeql-bundle-20200610/codeql-bundle.tar.gz", sampleApiDetails, tmpDir, tmpDir, util.GitHubVariant.DOTCOM, logging_1.getRunnerLogger(true));
await codeql.setupCodeQL("https://example.com/download/codeql-bundle-20200610/codeql-bundle.tar.gz", sampleApiDetails, tmpDir, tmpDir, util.GitHubVariant.DOTCOM, logging_1.getRunnerLogger(true), false);
t.assert(toolcache.find("CodeQL", "0.0.0-20200610"));
});
});
@@ -81,9 +81,9 @@ ava_1.default("don't download codeql bundle cache with pinned different version
nock_1.default("https://example.com")
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
.replyWithFile(200, path.join(__dirname, `/../src/testdata/codeql-bundle-pinned.tar.gz`));
await codeql.setupCodeQL("https://example.com/download/codeql-bundle-20200601/codeql-bundle.tar.gz", sampleApiDetails, tmpDir, tmpDir, util.GitHubVariant.DOTCOM, logging_1.getRunnerLogger(true));
await codeql.setupCodeQL("https://example.com/download/codeql-bundle-20200601/codeql-bundle.tar.gz", sampleApiDetails, tmpDir, tmpDir, util.GitHubVariant.DOTCOM, logging_1.getRunnerLogger(true), false);
t.assert(toolcache.find("CodeQL", "0.0.0-20200601"));
await codeql.setupCodeQL(undefined, sampleApiDetails, tmpDir, tmpDir, util.GitHubVariant.DOTCOM, logging_1.getRunnerLogger(true));
await codeql.setupCodeQL(undefined, sampleApiDetails, tmpDir, tmpDir, util.GitHubVariant.DOTCOM, logging_1.getRunnerLogger(true), false);
const cachedVersions = toolcache.findAllVersions("CodeQL");
t.is(cachedVersions.length, 1);
});
@@ -94,7 +94,7 @@ ava_1.default("download codeql bundle cache with different version cached (not p
nock_1.default("https://example.com")
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
.replyWithFile(200, path.join(__dirname, `/../src/testdata/codeql-bundle.tar.gz`));
await codeql.setupCodeQL("https://example.com/download/codeql-bundle-20200601/codeql-bundle.tar.gz", sampleApiDetails, tmpDir, tmpDir, util.GitHubVariant.DOTCOM, logging_1.getRunnerLogger(true));
await codeql.setupCodeQL("https://example.com/download/codeql-bundle-20200601/codeql-bundle.tar.gz", sampleApiDetails, tmpDir, tmpDir, util.GitHubVariant.DOTCOM, logging_1.getRunnerLogger(true), false);
t.assert(toolcache.find("CodeQL", "0.0.0-20200601"));
const platform = process.platform === "win32"
? "win64"
@@ -104,7 +104,7 @@ ava_1.default("download codeql bundle cache with different version cached (not p
nock_1.default("https://github.com")
.get(`/github/codeql-action/releases/download/${defaults.bundleVersion}/codeql-bundle-${platform}.tar.gz`)
.replyWithFile(200, path.join(__dirname, `/../src/testdata/codeql-bundle.tar.gz`));
await codeql.setupCodeQL(undefined, sampleApiDetails, tmpDir, tmpDir, util.GitHubVariant.DOTCOM, logging_1.getRunnerLogger(true));
await codeql.setupCodeQL(undefined, sampleApiDetails, tmpDir, tmpDir, util.GitHubVariant.DOTCOM, logging_1.getRunnerLogger(true), false);
const cachedVersions = toolcache.findAllVersions("CodeQL");
t.is(cachedVersions.length, 2);
});
@@ -115,7 +115,7 @@ ava_1.default('download codeql bundle cache with pinned different version cached
nock_1.default("https://example.com")
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
.replyWithFile(200, path.join(__dirname, `/../src/testdata/codeql-bundle-pinned.tar.gz`));
await codeql.setupCodeQL("https://example.com/download/codeql-bundle-20200601/codeql-bundle.tar.gz", sampleApiDetails, tmpDir, tmpDir, util.GitHubVariant.DOTCOM, logging_1.getRunnerLogger(true));
await codeql.setupCodeQL("https://example.com/download/codeql-bundle-20200601/codeql-bundle.tar.gz", sampleApiDetails, tmpDir, tmpDir, util.GitHubVariant.DOTCOM, logging_1.getRunnerLogger(true), false);
t.assert(toolcache.find("CodeQL", "0.0.0-20200601"));
const platform = process.platform === "win32"
? "win64"
@@ -125,7 +125,7 @@ ava_1.default('download codeql bundle cache with pinned different version cached
nock_1.default("https://github.com")
.get(`/github/codeql-action/releases/download/${defaults.bundleVersion}/codeql-bundle-${platform}.tar.gz`)
.replyWithFile(200, path.join(__dirname, `/../src/testdata/codeql-bundle.tar.gz`));
await codeql.setupCodeQL("latest", sampleApiDetails, tmpDir, tmpDir, util.GitHubVariant.DOTCOM, logging_1.getRunnerLogger(true));
await codeql.setupCodeQL("latest", sampleApiDetails, tmpDir, tmpDir, util.GitHubVariant.DOTCOM, logging_1.getRunnerLogger(true), false);
const cachedVersions = toolcache.findAllVersions("CodeQL");
t.is(cachedVersions.length, 2);
});
@@ -153,7 +153,7 @@ ava_1.default("download codeql bundle from github ae endpoint", async (t) => {
nock_1.default("https://example.githubenterprise.com")
.get(`/github/codeql-action/releases/download/${defaults.bundleVersion}/${codeQLBundleName}`)
.replyWithFile(200, path.join(__dirname, `/../src/testdata/codeql-bundle-pinned.tar.gz`));
await codeql.setupCodeQL(undefined, sampleGHAEApiDetails, tmpDir, tmpDir, util.GitHubVariant.GHAE, logging_1.getRunnerLogger(true));
await codeql.setupCodeQL(undefined, sampleGHAEApiDetails, tmpDir, tmpDir, util.GitHubVariant.GHAE, logging_1.getRunnerLogger(true), false);
const cachedVersions = toolcache.findAllVersions("CodeQL");
t.is(cachedVersions.length, 1);
});

File diff suppressed because one or more lines are too long

24
lib/count-loc.js generated
View File

@@ -1,9 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.countLoc = exports.getIdPrefix = void 0;
exports.countLoc = void 0;
const github_linguist_1 = require("github-linguist");
const languages_1 = require("./languages");
const util_1 = require("./util");
// Map from linguist language names to language prefixes used in the action and codeql
const linguistToMetrics = {
c: languages_1.Language.cpp,
@@ -23,27 +22,6 @@ const nameToLinguist = Object.entries(linguistToMetrics).reduce((obj, [key, name
obj[name].push(key);
return obj;
}, {});
function getIdPrefix(language) {
switch (language) {
case languages_1.Language.cpp:
return "cpp";
case languages_1.Language.csharp:
return "cs";
case languages_1.Language.go:
return "go";
case languages_1.Language.java:
return "java";
case languages_1.Language.javascript:
return "js";
case languages_1.Language.python:
return "py";
case languages_1.Language.ruby:
return "rb";
default:
util_1.assertNever(language);
}
}
exports.getIdPrefix = getIdPrefix;
/**
* Count the lines of code of the specified language using the include
* and exclude glob paths.

View File

@@ -1 +1 @@
{"version":3,"file":"count-loc.js","sourceRoot":"","sources":["../src/count-loc.ts"],"names":[],"mappings":";;;AAAA,qDAAyC;AAEzC,2CAAuC;AAEvC,iCAAqC;AAKrC,sFAAsF;AACtF,MAAM,iBAAiB,GAA6B;IAClD,CAAC,EAAE,oBAAQ,CAAC,GAAG;IACf,KAAK,EAAE,oBAAQ,CAAC,GAAG;IACnB,IAAI,EAAE,oBAAQ,CAAC,MAAM;IACrB,EAAE,EAAE,oBAAQ,CAAC,EAAE;IACf,IAAI,EAAE,oBAAQ,CAAC,IAAI;IACnB,UAAU,EAAE,oBAAQ,CAAC,UAAU;IAC/B,MAAM,EAAE,oBAAQ,CAAC,MAAM;IACvB,IAAI,EAAE,oBAAQ,CAAC,IAAI;IACnB,UAAU,EAAE,oBAAQ,CAAC,UAAU;CAChC,CAAC;AAEF,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAC7D,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE;IACnB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QACd,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE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,eAAe,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QACpD,IAAI,eAAe,IAAI,WAAW,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE;YAC5D,GAAG,CAAC,eAAe,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC;SAC3D;QACD,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAA8B,CAC/B,CAAC;IAEF,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,EAAE;QAClC,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;QACrC,KAAK,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;YAC1D,MAAM,CAAC,KAAK,CAAC,KAAK,QAAQ,KAAK,KAAK,EAAE,CAAC,CAAC;SACzC;KACF;SAAM;QACL,MAAM,CAAC,IAAI,CACT,2EAA2E;YACzE,gEAAgE;YAChE,4EAA4E;YAC5E,4EAA4E;YAC5E,2EAA2E;YAC3E,6EAA6E;YAC7E,2CAA2C,CAC9C,CAAC;KACH;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AA9CD,4BA8CC"}

View File

@@ -57,7 +57,7 @@ async function uploadDatabases(repositoryNwo, config, apiDetails, logger) {
}
return;
}
const codeql = codeql_1.getCodeQL(config.codeQLCmd);
const codeql = await codeql_1.getCodeQL(config.codeQLCmd);
for (const language of config.languages) {
// Bundle the database up into a single zip file
const databasePath = util.getCodeQLDatabasePath(config, language);

View File

@@ -1 +1 @@
{"version":3,"file":"database-upload.js","sourceRoot":"","sources":["../src/database-upload.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AAEzB,4DAA8C;AAC9C,6CAA8D;AAC9D,qCAAqC;AAIrC,6CAA+B;AAExB,KAAK,UAAU,eAAe,CACnC,aAA4B,EAC5B,MAAc,EACd,U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,CAAC;YACF,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;AAtED,0CAsEC"}

View File

@@ -1,3 +1,3 @@
{
"bundleVersion": "codeql-bundle-20210809"
"bundleVersion": "codeql-bundle-20210824"
}

2
lib/init.js generated
View File

@@ -31,7 +31,7 @@ const tracer_config_1 = require("./tracer-config");
const util = __importStar(require("./util"));
async function initCodeQL(codeqlURL, apiDetails, tempDir, toolCacheDir, variant, logger) {
logger.startGroup("Setup CodeQL tools");
const { codeql, toolsVersion } = await codeql_1.setupCodeQL(codeqlURL, apiDetails, tempDir, toolCacheDir, variant, logger);
const { codeql, toolsVersion } = await codeql_1.setupCodeQL(codeqlURL, apiDetails, tempDir, toolCacheDir, variant, logger, true);
await codeql.printVersion();
logger.endGroup();
return { codeql, toolsVersion };

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,qCAA+C;AAC/C,4DAA8C;AAG9C,mDAAwE;AACxE,6CAA+B;AAExB,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,oBAAW,CAChD,SAAS,EACT,UAAU,EACV,OAAO,EACP,YAAY,EACZ,OAAO,EACP,MAAM,CACP,CAAC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AI,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"}

2
lib/runner.js generated
View File

@@ -136,7 +136,7 @@ program
util_1.checkGitHubVersionInRange(gitHubVersion, logger, util_1.Mode.runner);
let codeql;
if (cmd.codeqlPath !== undefined) {
codeql = codeql_1.getCodeQL(cmd.codeqlPath);
codeql = await codeql_1.getCodeQL(cmd.codeqlPath);
}
else {
codeql = (await init_1.initCodeQL(undefined, apiDetails, tempDir, toolsDir, gitHubVersion.type, logger)).codeql;

File diff suppressed because one or more lines are too long

2
lib/util.js generated
View File

@@ -129,7 +129,7 @@ function getAddSnippetsFlag(userInput) {
exports.getAddSnippetsFlag = getAddSnippetsFlag;
/**
* Get the codeql `--threads` value specified for the `threads` input.
* If not value was specified, all available threads will be used.
* If no value was specified, all available threads will be used.
*
* The value will be capped to the number of available CPUs.
*

6
node_modules/.package-lock.json generated vendored
View File

@@ -2960,9 +2960,9 @@
}
},
"node_modules/github-linguist": {
"version": "2.4.3",
"resolved": "https://registry.npmjs.org/github-linguist/-/github-linguist-2.4.3.tgz",
"integrity": "sha512-hKWn1QQ+9oUyOIcUhPzi6AxTcAkYHg4OOwK79Pr05SBTFmdNr7GQkMDJabSGCZwu7SDhEb5YeUwUGqrUfyo7PA==",
"version": "2.4.4",
"resolved": "https://registry.npmjs.org/github-linguist/-/github-linguist-2.4.4.tgz",
"integrity": "sha512-QSw/HfSTqA13t7eqNeGLd62ghnTsTQAUrJQKkUG100NZqqzpsKB9c7gH7lFaGU1ZWGmNSWfhG6q1Ok/xotOA/g==",
"dependencies": {
"chalk": "^2.2.0",
"commander": "^2.11.0",

1
node_modules/github-linguist/.eslintcache generated vendored Normal file
View File

@@ -0,0 +1 @@
[{"/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/cli.ts":"1","/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/directory.ts":"2","/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/file.ts":"3","/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/index.ts":"4","/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/languages.ts":"5","/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/utils.ts":"6","/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/declarations.d.ts":"7"},{"size":1802,"mtime":1629757721099,"results":"8","hashOfConfig":"9"},{"size":4764,"mtime":1629758968321,"results":"10","hashOfConfig":"9"},{"size":4177,"mtime":1629759033403,"results":"11","hashOfConfig":"9"},{"size":751,"mtime":1629758749896,"results":"12","hashOfConfig":"9"},{"size":5651,"mtime":1629759502034,"results":"13","hashOfConfig":"14"},{"size":541,"mtime":1629758671936,"results":"15","hashOfConfig":"9"},{"size":25,"mtime":1629758437358,"results":"16","hashOfConfig":"9"},{"filePath":"17","messages":"18","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1ug2nbr",{"filePath":"19","messages":"20","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"21","messages":"22","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"23","messages":"24","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"25","messages":"26","errorCount":1,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"1okz2by",{"filePath":"27","messages":"28","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"29","messages":"30","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/cli.ts",[],"/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/directory.ts",[],"/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/file.ts",[],"/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/index.ts",[],"/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/languages.ts",["31"],"/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/utils.ts",[],"/Users/andrew.eisenberg/Eclipse/git-repos/linguist/src/declarations.d.ts",[],{"ruleId":"32","severity":2,"message":"33","line":4,"column":21,"nodeType":"34","messageId":"35","endLine":4,"endColumn":44},"@typescript-eslint/no-var-requires","Require statement not part of import statement.","CallExpression","noVarReqs"]

View File

@@ -1,3 +1,38 @@
module.exports = {
extends: [require.resolve('@umijs/fabric/dist/eslint')],
root: true,
extends: [
'eslint-config-airbnb-base',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
parser: '@typescript-eslint/parser',
env: {
node: true,
es6: true,
jest: true,
},
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.ts']
}
}
},
rules: {
'import/extensions': 'off',
'no-await-in-loop': 'off',
'no-console': 'off',
'class-methods-use-this': 'off',
'no-continue': 'off',
'@typescript-eslint/naming-convention': { format: 'camelCase' },
'@typescript-eslint/explicit-member-accessibility': 0,
'@typescript-eslint/interface-name-prefix': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/explicit-module-boundary-types': 0,
'@typescript-eslint/naming-convention': 0,
'@typescript-eslint/no-unused-vars': [
'error',
{ vars: 'all', args: 'after-used', ignoreRestSiblings: true },
],
},
};

View File

@@ -1,26 +1,34 @@
name: Node CI
on: [push]
on:
- push
- workflow_dispatch
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node_version: [10.x, 12.x]
node_version: [12.x, 14.x]
os: [ubuntu-latest, windows-latest]
steps:
- run: git config --global core.autocrlf false
if: matrix.os == 'windows-latest'
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node_version }}
- run: echo ${{github.ref}}
- run: yarn
- run: yarn run lint
- run: yarn run test
- run: npm ci
- run: npm run lint
- run: npm run test
env:
CI: true
PROGRESS: none
NODE_ENV: test
NODE_OPTIONS: --max_old_space_size=4096

View File

@@ -1,5 +1,15 @@
const fabric = require('@umijs/fabric');
module.exports = {
...fabric.prettier,
singleQuote: true,
trailingComma: 'all',
printWidth: 100,
proseWrap: 'never',
endOfLine: 'lf',
overrides: [
{
files: '.prettierrc',
options: {
parser: 'json',
},
},
],
};

View File

@@ -6,26 +6,13 @@
"configurations": [
{
"name": "Launch Tests",
"program": "${workspaceFolder}/node_modules/.bin/umi-test",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"type": "pwa-node",
"args": ["--testNamePattern", "example dir info"]
},
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/dist/index.js",
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
]
"args": ["--testNamePattern", "example dir info"]
}
]
}

View File

@@ -63,7 +63,7 @@ const dir = new LocDir({
include: // string or string[] containing path patterns to include (default include all)
exclude: // string or string[] containing path patterns to exclude (default exclude none)
});
const { info } = dir.getInfo();
const { info } = dir.loadInfo();
```
## License

View File

@@ -15,7 +15,7 @@ commander_1.default
.description('count lines of code in a file')
.action(async (pathPattern) => {
try {
const info = await (new file_1.LocFile(pathPattern).getFileInfo());
const info = await new file_1.LocFile(pathPattern).getFileInfo();
// eslint-disable-next-line no-console
console.log(chalk_1.default.cyan(`
path: \t\t${pathPattern}
@@ -42,9 +42,9 @@ const formatInfo = (info, languages) => `
.join('')}`;
commander_1.default.arguments('<cmd> [env]').action(async (cmd) => {
try {
const { info, languages } = await (new directory_1.LocDir({
include: cmd
}).loadInfo());
const { info, languages } = await new directory_1.LocDir({
include: cmd,
}).loadInfo();
// eslint-disable-next-line no-console
console.log(chalk_1.default.cyan(formatInfo(info, languages)));
}

View File

@@ -1 +1 @@
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAEA,kDAA0B;AAC1B,0DAAgC;AAEhC,2CAAqC;AACrC,iCAA2C;AAC3C,mCAAqC;AAErC,mBAAO;KACJ,OAAO,CAAC,kBAAU,EAAE,EAAE,IAAI,CAAC;KAC3B,OAAO,CAAC,aAAa,CAAC;KACtB,WAAW,CAAC,+BAA+B,CAAC;KAC5C,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;IAC5B,IAAI;QACF,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,cAAO,CAAC,WAAW,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;QAC5D,sCAAsC;QACtC,OAAO,CAAC,GAAG,CACT,eAAK,CAAC,IAAI,CAAC;oBACC,WAAW;sBACT,IAAI,CAAC,SAAS;yBACX,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;wBACzB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;2BACpB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;OAC9C,CAAC,CACD,CAAC;KACH;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,KAAK,CAAC,CAA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,GAAG,EAAE,EAAE;IACX,MAAM,YAAY,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;IACpC,OAAO,OAAO,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,kBAAkB,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,YAAY,MAAM,CACtF,YAAY,CAAC,KAAK,CACnB,eAAe,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,YAAY,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;AACtF,CAAC,CAAC;KACD,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;AAEhB,mBAAO,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IACpD,IAAI;QACF,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,MAAM,IAAI,kBAAM,CAAC;YAC3C,OAAO,EAAE,GAAG;SACb,CAAC,CAAC,QAAQ,EAAE,CAAC;QACd,sCAAsC;QACtC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;KACtD;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACjB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;KACxB;AACH,CAAC,CAAC,CAAC;AAEH,mBAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}

View File

@@ -7,7 +7,6 @@ exports.LocDir = void 0;
const globby_1 = __importDefault(require("globby"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
// @ts-ignore
const slash2_1 = __importDefault(require("slash2"));
const file_1 = require("./file");
const languages_1 = require("./languages");
@@ -26,16 +25,16 @@ const defaultExclude = [
'**/*.snap',
// java
'**/target',
"**/*.class",
"**/*.o",
"**/bin",
"**/*.map",
'**/*.class',
'**/*.o',
'**/bin',
'**/*.map',
// python
"**/*.pyc",
"**/*.pyo",
'**/*.pyc',
'**/*.pyo',
// other
"**/*.dil",
"**/*.ra",
'**/*.dil',
'**/*.ra',
// images
'**/*.png',
'**/*.jpg',
@@ -97,6 +96,12 @@ const defaultExclude = [
'**/*.tbz',
'**/*.tgz',
];
function ensureArray(arr, dfault) {
if (!arr) {
return dfault ? [dfault] : [];
}
return Array.isArray(arr) ? arr : [arr];
}
/**
* Collect the info of a directory.
*/
@@ -136,12 +141,12 @@ class LocDir {
// that end in .ts because the globstar indicates 0 or more directory paths.
this.exclude = ensureArray(options.exclude)
.concat(defaultExclude)
.map(item => item.endsWith('**') ? item : `${item}/**`);
.map((item) => (item.endsWith('**') ? item : `${item}/**`));
// remove all leading './' since this messes up globstar matches in the
// excludes.
this.include = ensureArray(options.include, '**')
.map(item => item.startsWith('./') ? item.substring(2) : item)
.map(item => item.endsWith('**') ? item : `${item}/**`);
.map((item) => (item.startsWith('./') ? item.substring(2) : item))
.map((item) => (item.endsWith('**') ? item : `${item}/**`));
this.cwd = options.cwd || process.cwd();
this.analysisLanguages = options.analysisLanguages;
}
@@ -152,13 +157,14 @@ class LocDir {
const paths = await globby_1.default(this.include, {
cwd: this.cwd,
ignore: this.exclude,
nodir: true
nodir: true,
});
const files = [];
const info = { ...defaultInfo };
let languages = {};
// We _could_ use Promise.all to count the files in parallel, but that
// would lead to out of memory errors when there are many files.
// eslint-disable-next-line no-restricted-syntax
for (const pathItem of paths) {
const fullPath = slash2_1.default(path_1.default.join(this.cwd, pathItem));
if (!pathItem ||
@@ -195,16 +201,9 @@ class LocDir {
* and this language is not one of them.
*/
ignoreLanguage(pathItem) {
return this.analysisLanguages && !this.analysisLanguages.includes(this.allLanguages.getType(pathItem));
return (this.analysisLanguages &&
!this.analysisLanguages.includes(this.allLanguages.getType(pathItem)));
}
}
exports.LocDir = LocDir;
function ensureArray(arr, dfault) {
if (!arr) {
return dfault ? [dfault] : [];
}
return Array.isArray(arr)
? arr
: [arr];
}
//# sourceMappingURL=directory.js.map

View File

@@ -1 +1 @@
{"version":3,"file":"directory.js","sourceRoot":"","sources":["../src/directory.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,wDAA0B;AAC1B,gDAAwB;AACxB,aAAa;AACb,oDAA2B;AAE3B,iCAA2C;AAC3C,2CAAwC;AAExC,MAAM,WAAW,GAAa;IAC5B,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,OAAO,EAAE,CAAC;CACX,CAAC;AAmBF,MAAM,cAAc,GAAG;IACrB,aAAa;IACb,UAAU;IACV,WAAW;IACX,YAAY;IACZ,oBAAoB;IACpB,YAAY;IACZ,WAAW;IAEX,OAAO;IACP,WAAW;IACX,YAAY;IACZ,QAAQ;IACR,QAAQ;IACR,UAAU;IAEV,SAAS;IACT,UAAU;IACV,UAAU;IAEV,QAAQ;IACR,UAAU;IACV,SAAS;IAET,SAAS;IACT,UAAU;IACV,UAAU;IACV,WAAW;IACX,UAAU;IACV,UAAU;IACV,UAAU;IACV,WAAW;IACX,WAAW;IACX,UAAU;IACV,SAAS;IACT,SAAS;IACT,UAAU;IAEV,QAAQ;IACR,UAAU;IACV,UAAU;IACV,WAAW;IACX,YAAY;IACZ,UAAU;IACV,UAAU;IAEV,QAAQ;IACR,UAAU;IACV,UAAU;IACV,UAAU;IACV,WAAW;IACX,UAAU;IACV,UAAU;IACV,WAAW;IAEX,QAAQ;IACR,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,WAAW;IACX,UAAU;IACV,UAAU;IAEV,SAAS;IACT,UAAU;IACV,WAAW;IACX,WAAW;IACX,UAAU;IACV,WAAW;IACX,UAAU;IACV,WAAW;IAEX,YAAY;IACZ,UAAU;IACV,WAAW;IACX,WAAW;IAEX,WAAW;IACX,UAAU;IACV,UAAU;IACV,SAAS;IACT,UAAU;IACV,SAAS;IACT,UAAU;IACV,SAAS;IAC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,GAAG,CAAC,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC;YAC3D,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,GAAG,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC;YACrD,SAAS,GAAG;gBACV,GAAG,SAAS;gBACZ,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,QAAQ;aACnC,CAAC;YACF,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SACtB;QAED,OAAO;YACL,KAAK;YACL,IAAI;YACJ,SAAS;SACV,CAAC;IACJ,CAAC;IAED;;;OAGG;IACK,cAAc,CAAC,QAAgB;QACrC,OAAO,CACL,IAAI,CAAC,iBAAiB;YACtB,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CACtE,CAAC;IACJ,CAAC;CACF;AA7FD,wBA6FC"}

View File

@@ -27,8 +27,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocFile = void 0;
const fs = __importStar(require("fs-extra"));
const Path = __importStar(require("path"));
// @ts-ignore
const slash2_1 = __importDefault(require("slash2"));
const languages_1 = require("./languages");
const DefaultLine = {
@@ -84,15 +82,16 @@ class LocFile {
let codeLength = lines.length;
const total = codeLength;
let inMultiLineComment = false;
lines.forEach((line) => {
lines.forEach((origLine) => {
var _a, _b, _c, _d, _e, _f;
let lineType = 'code';
line = line.trim();
const line = origLine.trim();
if (inMultiLineComment) {
let noCode = true;
if (regexes.multiLineCommentClose.test(line)) {
if ((_a = regexes.multiLineCommentClose) === null || _a === void 0 ? void 0 : _a.test(line)) {
// line contains the end of a multi-line comment
inMultiLineComment = false;
if (!regexes.multiLineCommentCloseEnd.test(line)) {
if (!((_b = regexes.multiLineCommentCloseEnd) === null || _b === void 0 ? void 0 : _b.test(line))) {
// the multiline comment does not end this line.
// there is real code on it.
noCode = false;
@@ -106,21 +105,21 @@ class LocFile {
}
else if (line) {
// non-empty line
if (regexes.multiLineCommentOpen.test(line)) {
if ((_c = regexes.multiLineCommentOpen) === null || _c === void 0 ? void 0 : _c.test(line)) {
// line contains the start of a multi-line comment
// might contain some real code, but we'll let that slide
if (!regexes.multiLineCommentOpenAndClose.test(line)) {
if (!((_d = regexes.multiLineCommentOpenAndClose) === null || _d === void 0 ? void 0 : _d.test(line))) {
// comment is not also closed on this line
inMultiLineComment = true;
}
if (regexes.multiLineCommentOpenStart.test(line)) {
if ((_e = regexes.multiLineCommentOpenStart) === null || _e === void 0 ? void 0 : _e.test(line)) {
// The comment starts the line. There is no other code on this line
commentLength += 1;
codeLength -= 1;
lineType = 'comm';
}
}
else if (regexes.singleLineComment.test(line)) {
else if ((_f = regexes.singleLineComment) === null || _f === void 0 ? void 0 : _f.test(line)) {
// line contains only a single line comment
commentLength += 1;
codeLength -= 1;
@@ -155,14 +154,16 @@ class LocFile {
throw new Error(`Error: file ${this.rawPath} does not exist.`);
}
let newData = data;
const info = Object.assign({}, DefaultFileInfo);
const name = this.path.split(Path.sep).pop() || '';
const info = { ...DefaultFileInfo };
// note: do not use Path.sep here since we have already
// translated the path to a posix path using slash(...).
const name = this.path.split('/').pop() || '';
try {
const stat = await fs.stat(this.path);
if (!stat.isFile()) {
return info;
}
newData = data || await fs.readFile(this.path, 'utf-8');
newData = data || (await fs.readFile(this.path, 'utf-8'));
info.name = name;
info.size = (stat && stat.size) || 0;
info.languages = this.languages.getType(this.path);
@@ -180,7 +181,7 @@ class LocFile {
return info;
}
getFileInfoByContent(name, data) {
const info = Object.assign({}, DefaultFileInfo);
const info = { ...DefaultFileInfo };
info.name = name;
info.languages = this.languages.getType(name);
info.lines = this.filterData(data, this.languages.getRegexes(info.languages));

View File

@@ -1 +1 @@
{"version":3,"file":"file.js","sourceRoot":"","sources":["../src/file.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;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;QAC9E,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA/HD,0BA+HC"}

View File

@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// @ts-ignore
const slash2_1 = __importDefault(require("slash2"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const directory_1 = require("./directory");

View File

@@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,aAAa;AACb,oDAA2B;AAC3B,wDAA0B;AAE1B,2CAAgD;AAChD,iCAAiC;AAEjC,yCAAoD;AAA3C,mGAAA,MAAM,OAAA;AACf,+BAA2C;AAAlC,+FAAA,OAAO,OAAA;AAEhB,MAAM,GAAG,GAAG,KAAK,EACf,SAAiB,EACG,EAAE;IACtB,MAAM,IAAI,GAAG,MAAM,kBAAE,CAAC,IAAI,CAAC,gBAAK,CAAC,SAAS,CAAC,CAAC,CAAC;IAC7C,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,IAAI,cAAO,CAAC,gBAAK,CAAC,SAAS,CAAC,CAAC,CAAC;QAC9C,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC;QACzC,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;QAC9B,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,KAAK;YAChB,KAAK,EAAE,CAAC,QAAQ,CAAC;YACjB,SAAS,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE;SAC3D,CAAC;KACH;IACD,MAAM,MAAM,GAAG,IAAI,kBAAM,CAAC,EAAE,GAAG,EAAE,gBAAK,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACrD,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAC;AAC3B,CAAC,CAAC;AAEF,kBAAe,GAAG,CAAC"}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,oDAA2B;AAC3B,wDAA0B;AAE1B,2CAAgD;AAChD,iCAAiC;AAEjC,yCAAoD;AAA3C,mGAAA,MAAM,OAAA;AACf,+BAA2C;AAAlC,+FAAA,OAAO,OAAA;AAEhB,MAAM,GAAG,GAAG,KAAK,EAAE,SAAiB,EAAsB,EAAE;IAC1D,MAAM,IAAI,GAAG,MAAM,kBAAE,CAAC,IAAI,CAAC,gBAAK,CAAC,SAAS,CAAC,CAAC,CAAC;IAC7C,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE;QACjB,MAAM,OAAO,GAAG,IAAI,cAAO,CAAC,gBAAK,CAAC,SAAS,CAAC,CAAC,CAAC;QAC9C,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC;QACzC,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;QAC9B,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,KAAK;YAChB,KAAK,EAAE,CAAC,QAAQ,CAAC;YACjB,SAAS,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE;SAC3D,CAAC;KACH;IACD,MAAM,MAAM,GAAG,IAAI,kBAAM,CAAC,EAAE,GAAG,EAAE,gBAAK,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACrD,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAC;AAC3B,CAAC,CAAC;AAEF,kBAAe,GAAG,CAAC"}

View File

@@ -1,4 +1,10 @@
export interface DetectorOptions {
export interface Regexes {
singleLineComment: RegExp;
multiLineCommentOpen?: RegExp;
multiLineCommentOpenStart?: RegExp;
multiLineCommentClose?: RegExp;
multiLineCommentCloseEnd?: RegExp;
multiLineCommentOpenAndClose?: RegExp;
}
/**
* detecte program language through file extension
@@ -37,11 +43,3 @@ export declare class Languages {
*/
getType(path: string): string;
}
export interface Regexes {
singleLineComment: RegExp;
multiLineCommentOpen: RegExp;
multiLineCommentOpenStart: RegExp;
multiLineCommentClose: RegExp;
multiLineCommentCloseEnd: RegExp;
multiLineCommentOpenAndClose: RegExp;
}

View File

@@ -1,9 +1,11 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Languages = void 0;
const languages_json_1 = __importDefault(require("language-map/languages.json"));
const utils_1 = require("./utils");
// tslint:disable-next-line
const languageMap = require('language-map');
/**
* The extension map can contain multiple languages with the same extension,
* but we only want a single one. For the moment, these clashes are resolved
@@ -12,7 +14,70 @@ const languageMap = require('language-map');
* where the extension is ambiguous. The ordering of the list matters and
* languages earlier on will get a higher priority when resolving clashes.
*/
const importantLanguages = ["javascript", "typescript", "ruby", "python", "java", "c", "c++", "c#", "rust", "scala", "perl", "go"];
const importantLanguages = [
'javascript',
'typescript',
'ruby',
'python',
'java',
'c',
'c++',
'c#',
'rust',
'scala',
'perl',
'go',
];
const ALL_REGEXES = {
c: {
// matches when // are the first two characters of a line
singleLineComment: /^\/\//,
// matches when /* exists in a line
multiLineCommentOpen: /\/\*/,
// matches when /* starts a line
multiLineCommentOpenStart: /^\/\*/,
// matches when */ exists a line
multiLineCommentClose: /\*\//,
// matches when */ ends a line
multiLineCommentCloseEnd: /\*\/$/,
// matches /* ... */
multiLineCommentOpenAndClose: /\/\*.*\*\//,
},
python: {
// matches when # the first character of a line
singleLineComment: /^#/,
},
ruby: {
// matches when # the first character of a line
singleLineComment: /^#/,
// For ruby multiline comments, =begin and =end must be
// on their own lines
// matches when =begin starts a line
multiLineCommentOpen: /^=begin/,
// matches when "begin starts a line
multiLineCommentOpenStart: /^=begin/,
// matches when "end ends a line
multiLineCommentClose: /^=end/,
// matches when "end ends a line
multiLineCommentCloseEnd: /^=end$/,
// not possible in ruby
multiLineCommentOpenAndClose: /^\0$/,
},
html: {
// There is no single line comment
singleLineComment: /^\0$/,
// matches when =begin starts a line
multiLineCommentOpen: /<!--/,
// matches when "begin starts a line
multiLineCommentOpenStart: /^<!--/,
// matches when "end ends a line
multiLineCommentClose: /-->/,
// matches when "end ends a line
multiLineCommentCloseEnd: /-->$/,
// matches <!-- ... -->
multiLineCommentOpenAndClose: /<!--.*-->/,
},
};
/**
* detecte program language through file extension
*
@@ -39,8 +104,8 @@ class Languages {
writable: true,
value: () => {
const extensions = {};
Object.keys(languageMap).forEach((language) => {
const languageMode = languageMap[language];
Object.keys(languages_json_1.default).forEach((language) => {
const languageMode = languages_json_1.default[language];
const languageExtensions = (languageMode && languageMode.extensions) || [];
languageExtensions.forEach((extension) => {
const lowerCaseExtension = extension.toLowerCase();
@@ -61,7 +126,7 @@ class Languages {
}
});
});
return Object.assign({}, extensions, utils_1.ExtensionJustify);
return { ...extensions, ...utils_1.ExtensionJustify };
}
});
this.extensionMap = this.loadExtensionMap();
@@ -102,66 +167,4 @@ class Languages {
}
}
exports.Languages = Languages;
const ALL_REGEXES = {
c: {
// matches when // are the first two characters of a line
singleLineComment: /^\/\//,
// matches when /* exists in a line
multiLineCommentOpen: /\/\*/,
// matches when /* starts a line
multiLineCommentOpenStart: /^\/\*/,
// matches when */ exists a line
multiLineCommentClose: /\*\//,
// matches when */ ends a line
multiLineCommentCloseEnd: /\*\/$/,
// matches /* ... */
multiLineCommentOpenAndClose: /\/\*.*\*\//
},
python: {
// matches when # the first character of a line
singleLineComment: /^#/,
// matches when """ starts a line. This is not right, since
// a multiline string is not always a comment, but for the
// sake of simplicity, we will do that here.
multiLineCommentOpen: /"""/,
// matches when """ starts a line
multiLineCommentOpenStart: /^"""/,
// matches when """ exists in a line
multiLineCommentClose: /"""/,
// matches when """ ends a line
multiLineCommentCloseEnd: /"""$/,
// matches """ ... """
multiLineCommentOpenAndClose: /""".*"""/
},
ruby: {
// matches when # the first character of a line
singleLineComment: /^#/,
// For ruby multiline comments, =begin and =end must be
// on their own lines
// matches when =begin starts a line
multiLineCommentOpen: /^=begin/,
// matches when "begin starts a line
multiLineCommentOpenStart: /^=begin/,
// matches when "end ends a line
multiLineCommentClose: /^=end/,
// matches when "end ends a line
multiLineCommentCloseEnd: /^=end$/,
// not possible in ruby
multiLineCommentOpenAndClose: /^\0$/
},
html: {
// There is no single line comment
singleLineComment: /^\0$/,
// matches when =begin starts a line
multiLineCommentOpen: /<!--/,
// matches when "begin starts a line
multiLineCommentOpenStart: /^<!--/,
// matches when "end ends a line
multiLineCommentClose: /-->/,
// matches when "end ends a line
multiLineCommentCloseEnd: /-->$/,
// matches <!-- ... -->
multiLineCommentOpenAndClose: /<!--.*-->/
}
};
//# sourceMappingURL=languages.js.map

View File

@@ -1 +1 @@
{"version":3,"file":"languages.js","sourceRoot":"","sources":["../src/languages.ts"],"names":[],"mappings":";;;AAAA,mCAA2C;AAE3C,2BAA2B;AAC3B,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAU5C;;;;;;;GAOG;AACH,MAAM,kBAAkB,GAAG,CAAC,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AAGnI;;;;;GAKG;AACH,MAAa,SAAS;IAKpB;;OAEG;IACH;QAPA;;;;mBAEI,EAAE;WAAC;QASP;;WAEG;QACH;;;;mBAA2B,GAAG,EAAE;gBAC9B,MAAM,UAAU,GAAoB,EAAE,CAAC;gBAEvC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;oBAC5C,MAAM,YAAY,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;oBAC3C,MAAM,kBAAkB,GAAG,C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,kBAAkB,CAAC,GAAG,iBAAiB,CAAC;6BACpD;iCAAM;gCACL,MAAM,aAAa,GAAG,kBAAkB,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;gCACpE,IAAI,aAAa,KAAK,CAAC,CAAC,IAAI,aAAa,GAAG,uBAAuB;oCACjE,UAAU,CAAC,kBAAkB,CAAC,GAAG,iBAAiB,CAAC;6BACtD;yBACF;oBACH,CAAC,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;gBAEH,OAAO,EAAE,GAAG,UAAU,EAAE,GAAG,wBAAgB,EAAE,CAAC;YAChD,CAAC;WAAC;QAjCA,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC9C,CAAC;IAkCD;;;;;;OAMG;IACI,UAAU,CAAC,QAAgB;QAChC,QAAQ,QAAQ,EAAE;YAChB,KAAK,MAAM,CAAC;YACZ,KAAK,KAAK;gBACR,OAAO,WAAW,CAAC,IAAI,CAAC;YAE1B,KAAK,MAAM;gBACT,OAAO,WAAW,CAAC,IAAI,CAAC;YAE1B,KAAK,QAAQ;gBACX,OAAO,WAAW,CAAC,MAAM,CAAC;YAE5B;gBACE,2EAA2E;gBAC3E,OAAO,WAAW,CAAC,CAAC,CAAC;SACxB;IACH,CAAC;IAED;;OAEG;IACI,eAAe;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,IAAY;QACzB,MAAM,aAAa,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC;QAClD,OAAO,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;IAChD,CAAC;CACF;AAnFD,8BAmFC"}

View File

@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.ExtensionJustify = exports.getVersion = void 0;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
// @ts-ignore
const slash2_1 = __importDefault(require("slash2"));
const packagePath = slash2_1.default(path_1.default.join(__dirname, '../', 'package.json'));
/**

View File

@@ -1 +1 @@
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,aAAa;AACb,oDAA2B;AAE3B,MAAM,WAAW,GAAG,gBAAK,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC;AAEvE;;;;;GAKG;AACH,SAAgB,UAAU;IACxB,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IAErE,OAAO,CAAC,WAAW,IAAI,WAAW,CAAC,OAAO,CAAC,IAAI,kBAAkB,CAAC;AACpE,CAAC;AAJD,gCAIC;AAEY,QAAA,gBAAgB,GAAG;IAC9B,KAAK,EAAE,YAAY;IACnB,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE,YAAY;IACnB,MAAM,EAAE,YAAY;CACrB,CAAC"}
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,oDAA2B;AAE3B,MAAM,WAAW,GAAG,gBAAK,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC;AAEvE;;;;;GAKG;AACH,SAAgB,UAAU;IACxB,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IAErE,OAAO,CAAC,WAAW,IAAI,WAAW,CAAC,OAAO,CAAC,IAAI,kBAAkB,CAAC;AACpE,CAAC;AAJD,gCAIC;AAEY,QAAA,gBAAgB,GAAG;IAC9B,KAAK,EAAE,YAAY;IACnB,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE,YAAY;IACnB,MAAM,EAAE,YAAY;CACrB,CAAC"}

14
node_modules/github-linguist/jest.config.ts generated vendored Normal file
View File

@@ -0,0 +1,14 @@
/*
* For a detailed explanation regarding each configuration property and type check, visit:
* https://jestjs.io/docs/configuration
*/
export default {
// Automatically clear mock calls and instances between every test
clearMocks: true,
// Indicates whether each individual test should be reported during the run
verbose: undefined,
preset: 'ts-jest',
};

View File

@@ -1,12 +1,11 @@
{
"name": "github-linguist",
"version": "2.4.3",
"version": "2.4.4",
"description": "A tool to count lines of code in a repository powered by github-linguist langauge mappings.",
"keywords": [
"loc",
"cloc",
"linguist",
"umijs",
"lines of code"
],
"homepage": "https://github.com/aeisenberg/linguist#readme",
@@ -33,10 +32,10 @@
},
"scripts": {
"build": "tsc -d",
"lint": "eslint --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src",
"lint": "eslint --cache --ext .ts ./src",
"prettier": "prettier -c --write \"**/*\"",
"prepublishOnly": "npm run build",
"test": "umi-test"
"test": "jest"
},
"dependencies": {
"chalk": "^2.2.0",
@@ -52,15 +51,22 @@
"@types/commander": "^2.11.0",
"@types/fs-extra": "^4.0.2",
"@types/globby": "^6.1.0",
"@types/jest": "^25.1.5",
"@types/jest": "^27.0.1",
"@types/mocha": "^2.2.43",
"@types/node": "^8.0.45",
"@umijs/fabric": "^2.0.7",
"@typescript-eslint/eslint-plugin": "^4.29.3",
"@typescript-eslint/parser": "^4.29.3",
"chai": "^4.1.2",
"coveralls": "^3.0.0",
"eslint": "^6.8.0",
"prettier": "^2.0.2",
"typescript": "^3.8.3",
"umi-test": "^1.9.6"
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.24.1",
"eslint-plugin-prettier": "^3.4.1",
"jest": "^27.0.6",
"prettier": "^2.3.2",
"ts-jest": "^27.0.5",
"ts-node": "^10.2.1",
"typescript": "^3.9.10"
}
}

View File

@@ -13,7 +13,7 @@ program
.description('count lines of code in a file')
.action(async (pathPattern) => {
try {
const info = await (new LocFile(pathPattern).getFileInfo());
const info = await new LocFile(pathPattern).getFileInfo();
// eslint-disable-next-line no-console
console.log(
chalk.cyan(`
@@ -52,9 +52,9 @@ const formatInfo = (
program.arguments('<cmd> [env]').action(async (cmd) => {
try {
const { info, languages } = await (new LocDir({
include: cmd
}).loadInfo());
const { info, languages } = await new LocDir({
include: cmd,
}).loadInfo();
// eslint-disable-next-line no-console
console.log(chalk.cyan(formatInfo(info, languages)));
} catch (e) {

2
node_modules/github-linguist/src/declarations.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
declare module 'slash2';
declare module 'language-map/languages.json';

View File

@@ -1,7 +1,6 @@
import globby from 'globby';
import fs from 'fs-extra';
import path from 'path';
// @ts-ignore
import slash from 'slash2';
import { LineInfo, LocFile } from './file';
@@ -41,18 +40,18 @@ const defaultExclude = [
// java
'**/target',
"**/*.class",
"**/*.o",
"**/bin",
"**/*.map",
'**/*.class',
'**/*.o',
'**/bin',
'**/*.map',
// python
"**/*.pyc",
"**/*.pyo",
'**/*.pyc',
'**/*.pyo',
// other
"**/*.dil",
"**/*.ra",
'**/*.dil',
'**/*.ra',
// images
'**/*.png',
@@ -122,29 +121,39 @@ const defaultExclude = [
'**/*.tgz',
];
function ensureArray(arr?: string[] | string, dfault?: string) {
if (!arr) {
return dfault ? [dfault] : [];
}
return Array.isArray(arr) ? arr : [arr];
}
/**
* Collect the info of a directory.
*/
export class LocDir {
private cwd: string;
private include: string[];
private exclude: string[];
private analysisLanguages?: string[];
private allLanguages = new Languages();
constructor(options: LocDirOptions) {
// ensure all excludes are globstar. Note that '**/*.ts/**' matches files
// that end in .ts because the globstar indicates 0 or more directory paths.
this.exclude = ensureArray(options.exclude)
.concat(defaultExclude)
.map(item => item.endsWith('**') ? item : `${item}/**`);
.map((item) => (item.endsWith('**') ? item : `${item}/**`));
// remove all leading './' since this messes up globstar matches in the
// excludes.
this.include = ensureArray(options.include, '**')
.map(item => item.startsWith('./') ? item.substring(2) : item)
.map(item => item.endsWith('**') ? item : `${item}/**`);
.map((item) => (item.startsWith('./') ? item.substring(2) : item))
.map((item) => (item.endsWith('**') ? item : `${item}/**`));
this.cwd = options.cwd || process.cwd();
this.analysisLanguages = options.analysisLanguages;
}
@@ -156,7 +165,7 @@ export class LocDir {
const paths = await globby(this.include, {
cwd: this.cwd,
ignore: this.exclude,
nodir: true
nodir: true,
});
const files: string[] = [];
const info: LineInfo = { ...defaultInfo };
@@ -168,6 +177,7 @@ export class LocDir {
// We _could_ use Promise.all to count the files in parallel, but that
// would lead to out of memory errors when there are many files.
// eslint-disable-next-line no-restricted-syntax
for (const pathItem of paths) {
const fullPath = slash(path.join(this.cwd, pathItem));
if (
@@ -178,6 +188,7 @@ export class LocDir {
) {
continue;
}
const file = new LocFile(fullPath);
const fileLineInfo = await file.getFileInfo();
const { lines } = fileLineInfo;
@@ -208,15 +219,9 @@ export class LocDir {
* and this language is not one of them.
*/
private ignoreLanguage(pathItem: string): boolean {
return this.analysisLanguages && !this.analysisLanguages.includes(this.allLanguages.getType(pathItem));
return (
this.analysisLanguages &&
!this.analysisLanguages.includes(this.allLanguages.getType(pathItem))
);
}
}
function ensureArray(arr?: string[] | string, dfault?: string) {
if (!arr) {
return dfault ? [dfault] : [];
}
return Array.isArray(arr)
? arr
: [arr];
}

View File

@@ -3,8 +3,6 @@
*/
import * as fs from 'fs-extra';
import * as Path from 'path';
// @ts-ignore
import slash from 'slash2';
import { Languages, Regexes } from './languages';
@@ -40,6 +38,7 @@ const DefaultFileInfo: FileInfo = {
*/
export class LocFile {
public path: string;
private rawPath: string;
private languages = new Languages();
@@ -59,18 +58,16 @@ export class LocFile {
const total = codeLength;
let inMultiLineComment = false;
lines.forEach((line) => {
lines.forEach((origLine) => {
let lineType = 'code';
line = line.trim();
const line = origLine.trim();
if (inMultiLineComment) {
let noCode = true;
if (regexes.multiLineCommentClose.test(line)) {
if (regexes.multiLineCommentClose?.test(line)) {
// line contains the end of a multi-line comment
inMultiLineComment = false;
if (!regexes.multiLineCommentCloseEnd.test(line)) {
if (!regexes.multiLineCommentCloseEnd?.test(line)) {
// the multiline comment does not end this line.
// there is real code on it.
noCode = false;
@@ -82,33 +79,29 @@ export class LocFile {
commentLength += 1;
codeLength -= 1;
}
} else if (line) {
// non-empty line
if (regexes.multiLineCommentOpen.test(line)) {
if (regexes.multiLineCommentOpen?.test(line)) {
// line contains the start of a multi-line comment
// might contain some real code, but we'll let that slide
if (!regexes.multiLineCommentOpenAndClose.test(line)) {
if (!regexes.multiLineCommentOpenAndClose?.test(line)) {
// comment is not also closed on this line
inMultiLineComment = true;
}
if (regexes.multiLineCommentOpenStart.test(line)) {
if (regexes.multiLineCommentOpenStart?.test(line)) {
// The comment starts the line. There is no other code on this line
commentLength += 1;
codeLength -= 1;
lineType = 'comm';
}
} else if (regexes.singleLineComment.test(line)) {
} else if (regexes.singleLineComment?.test(line)) {
// line contains only a single line comment
commentLength += 1;
codeLength -= 1;
lineType = 'comm';
}
} else {
// empty line
codeLength -= 1;
@@ -116,7 +109,7 @@ export class LocFile {
}
if (this.debug) {
console.log(lineType, line)
console.log(lineType, line);
}
});
@@ -137,14 +130,16 @@ export class LocFile {
}
let newData = data;
const info: FileInfo = Object.assign({}, DefaultFileInfo);
const name = this.path.split(Path.sep).pop() || '';
const info: FileInfo = { ...DefaultFileInfo };
// note: do not use Path.sep here since we have already
// translated the path to a posix path using slash(...).
const name = this.path.split('/').pop() || '';
try {
const stat = await fs.stat(this.path);
if (!stat.isFile()) {
return info;
}
newData = data || await fs.readFile(this.path, 'utf-8');
newData = data || (await fs.readFile(this.path, 'utf-8'));
info.name = name;
info.size = (stat && stat.size) || 0;
info.languages = this.languages.getType(this.path);
@@ -162,7 +157,7 @@ export class LocFile {
}
public getFileInfoByContent(name: string, data: string): FileInfo {
const info: FileInfo = Object.assign({}, DefaultFileInfo);
const info: FileInfo = { ...DefaultFileInfo };
info.name = name;
info.languages = this.languages.getType(name);
info.lines = this.filterData(data, this.languages.getRegexes(info.languages));

View File

@@ -1,4 +1,3 @@
// @ts-ignore
import slash from 'slash2';
import fs from 'fs-extra';
@@ -8,9 +7,7 @@ import { LocFile } from './file';
export { LocDir, LocDirOptions } from './directory';
export { LocFile, LineInfo } from './file';
const loc = async (
fileOrDir: string,
): Promise<LocResult> => {
const loc = async (fileOrDir: string): Promise<LocResult> => {
const stat = await fs.stat(slash(fileOrDir));
if (stat.isFile()) {
const locFile = new LocFile(slash(fileOrDir));

View File

@@ -1,16 +1,10 @@
import languageMap from 'language-map/languages.json';
import { ExtensionJustify } from './utils';
// tslint:disable-next-line
const languageMap = require('language-map');
// tslint:disable-next-line
// const lang = require('language-classifier');
interface ExtensionsTypes {
[key: string]: string;
}
export interface DetectorOptions {}
/**
* The extension map can contain multiple languages with the same extension,
* but we only want a single one. For the moment, these clashes are resolved
@@ -19,8 +13,116 @@ export interface DetectorOptions {}
* where the extension is ambiguous. The ordering of the list matters and
* languages earlier on will get a higher priority when resolving clashes.
*/
const importantLanguages = ["javascript", "typescript", "ruby", "python", "java", "c", "c++", "c#", "rust", "scala", "perl", "go"];
const importantLanguages = [
'javascript',
'typescript',
'ruby',
'python',
'java',
'c',
'c++',
'c#',
'rust',
'scala',
'perl',
'go',
];
export interface Regexes {
singleLineComment: RegExp;
multiLineCommentOpen?: RegExp;
multiLineCommentOpenStart?: RegExp;
multiLineCommentClose?: RegExp;
multiLineCommentCloseEnd?: RegExp;
multiLineCommentOpenAndClose?: RegExp;
}
const ALL_REGEXES: Record<string, Regexes> = {
c: {
// matches when // are the first two characters of a line
singleLineComment: /^\/\//,
// matches when /* exists in a line
multiLineCommentOpen: /\/\*/,
// matches when /* starts a line
multiLineCommentOpenStart: /^\/\*/,
// matches when */ exists a line
multiLineCommentClose: /\*\//,
// matches when */ ends a line
multiLineCommentCloseEnd: /\*\/$/,
// matches /* ... */
multiLineCommentOpenAndClose: /\/\*.*\*\//,
},
python: {
// matches when # the first character of a line
singleLineComment: /^#/,
// matches when """ starts a line. This is not right, since
// a multiline string is not always a comment, but for the
// sake of simplicity, we will do that here.
// multiLineCommentOpen: /"""/,
// matches when """ starts a line
// multiLineCommentOpenStart: /^"""/,
// matches when """ exists in a line
// multiLineCommentClose: /"""/,
// matches when """ ends a line
// multiLineCommentCloseEnd: /"""$/,
// matches """ ... """
// multiLineCommentOpenAndClose: /""".*"""/,
},
ruby: {
// matches when # the first character of a line
singleLineComment: /^#/,
// For ruby multiline comments, =begin and =end must be
// on their own lines
// matches when =begin starts a line
multiLineCommentOpen: /^=begin/,
// matches when "begin starts a line
multiLineCommentOpenStart: /^=begin/,
// matches when "end ends a line
multiLineCommentClose: /^=end/,
// matches when "end ends a line
multiLineCommentCloseEnd: /^=end$/,
// not possible in ruby
multiLineCommentOpenAndClose: /^\0$/,
},
html: {
// There is no single line comment
singleLineComment: /^\0$/,
// matches when =begin starts a line
multiLineCommentOpen: /<!--/,
// matches when "begin starts a line
multiLineCommentOpenStart: /^<!--/,
// matches when "end ends a line
multiLineCommentClose: /-->/,
// matches when "end ends a line
multiLineCommentCloseEnd: /-->$/,
// matches <!-- ... -->
multiLineCommentOpenAndClose: /<!--.*-->/,
},
};
/**
* detecte program language through file extension
@@ -51,11 +153,13 @@ export class Languages {
const languageExtensions = (languageMode && languageMode.extensions) || [];
languageExtensions.forEach((extension: string) => {
const lowerCaseExtension = extension.toLowerCase();
const lowerCaseLanguage = language.toLowerCase()
const lowerCaseLanguage = language.toLowerCase();
if (!extensions[lowerCaseExtension]) {
extensions[lowerCaseExtension] = lowerCaseLanguage;
} else {
const currentLanguagePriority = importantLanguages.indexOf(extensions[lowerCaseExtension]);
const currentLanguagePriority = importantLanguages.indexOf(
extensions[lowerCaseExtension],
);
if (currentLanguagePriority === -1) {
extensions[lowerCaseExtension] = lowerCaseLanguage;
} else {
@@ -67,8 +171,8 @@ export class Languages {
});
});
return Object.assign({}, extensions, ExtensionJustify);
}
return { ...extensions, ...ExtensionJustify };
};
/**
* Retrieve the regular expressions for a given language.
@@ -78,7 +182,7 @@ export class Languages {
* @param language the language to retrieve regexes for
*/
public getRegexes(language: string): Regexes {
switch(language) {
switch (language) {
case 'html':
case 'xml':
return ALL_REGEXES.html;
@@ -105,104 +209,8 @@ export class Languages {
/**
* get file type through a path
*/
public getType(path: string): string {
public getType(path: string): string {
const fileExtension = `.${path.split('.').pop()}`;
return this.extensionMap[fileExtension] || '';
}
}
export interface Regexes {
singleLineComment: RegExp;
multiLineCommentOpen: RegExp;
multiLineCommentOpenStart: RegExp;
multiLineCommentClose: RegExp;
multiLineCommentCloseEnd: RegExp;
multiLineCommentOpenAndClose: RegExp;
}
const ALL_REGEXES: Record<string, Regexes> = {
c: {
// matches when // are the first two characters of a line
singleLineComment: /^\/\//,
// matches when /* exists in a line
multiLineCommentOpen: /\/\*/,
// matches when /* starts a line
multiLineCommentOpenStart: /^\/\*/,
// matches when */ exists a line
multiLineCommentClose: /\*\//,
// matches when */ ends a line
multiLineCommentCloseEnd: /\*\/$/,
// matches /* ... */
multiLineCommentOpenAndClose: /\/\*.*\*\//
},
python: {
// matches when # the first character of a line
singleLineComment: /^#/,
// matches when """ starts a line. This is not right, since
// a multiline string is not always a comment, but for the
// sake of simplicity, we will do that here.
multiLineCommentOpen: /"""/,
// matches when """ starts a line
multiLineCommentOpenStart: /^"""/,
// matches when """ exists in a line
multiLineCommentClose: /"""/,
// matches when """ ends a line
multiLineCommentCloseEnd: /"""$/,
// matches """ ... """
multiLineCommentOpenAndClose: /""".*"""/
},
ruby: {
// matches when # the first character of a line
singleLineComment: /^#/,
// For ruby multiline comments, =begin and =end must be
// on their own lines
// matches when =begin starts a line
multiLineCommentOpen: /^=begin/,
// matches when "begin starts a line
multiLineCommentOpenStart: /^=begin/,
// matches when "end ends a line
multiLineCommentClose: /^=end/,
// matches when "end ends a line
multiLineCommentCloseEnd: /^=end$/,
// not possible in ruby
multiLineCommentOpenAndClose: /^\0$/
},
html: {
// There is no single line comment
singleLineComment: /^\0$/,
// matches when =begin starts a line
multiLineCommentOpen: /<!--/,
// matches when "begin starts a line
multiLineCommentOpenStart: /^<!--/,
// matches when "end ends a line
multiLineCommentClose: /-->/,
// matches when "end ends a line
multiLineCommentCloseEnd: /-->$/,
// matches <!-- ... -->
multiLineCommentOpenAndClose: /<!--.*-->/
}
};

View File

@@ -1,6 +1,5 @@
import fs from 'fs';
import path from 'path';
// @ts-ignore
import slash from 'slash2';
const packagePath = slash(path.join(__dirname, '../', 'package.json'));

View File

@@ -13,7 +13,8 @@
"sourceMap": true,
"paths": {
"*": ["node_modules/*", "src/types/*"]
}
},
"resolveJsonModule": true
},
"include": ["src/**/*"]
"include": ["src/**/*", "test/declarations.d.ts"]
}

18
package-lock.json generated
View File

@@ -24,7 +24,7 @@
"fast-deep-equal": "^3.1.3",
"file-url": "^3.0.0",
"fs": "0.0.1-security",
"github-linguist": "^2.4.3",
"github-linguist": "^2.4.4",
"glob": "^7.1.7",
"js-yaml": "^4.1.0",
"jsonschema": "1.2.6",
@@ -1505,6 +1505,7 @@
"dependencies": {
"anymatch": "~3.1.1",
"braces": "~3.0.2",
"fsevents": "~2.1.2",
"glob-parent": "~5.1.0",
"is-binary-path": "~2.1.0",
"is-glob": "~4.0.1",
@@ -3014,9 +3015,9 @@
}
},
"node_modules/github-linguist": {
"version": "2.4.3",
"resolved": "https://registry.npmjs.org/github-linguist/-/github-linguist-2.4.3.tgz",
"integrity": "sha512-hKWn1QQ+9oUyOIcUhPzi6AxTcAkYHg4OOwK79Pr05SBTFmdNr7GQkMDJabSGCZwu7SDhEb5YeUwUGqrUfyo7PA==",
"version": "2.4.4",
"resolved": "https://registry.npmjs.org/github-linguist/-/github-linguist-2.4.4.tgz",
"integrity": "sha512-QSw/HfSTqA13t7eqNeGLd62ghnTsTQAUrJQKkUG100NZqqzpsKB9c7gH7lFaGU1ZWGmNSWfhG6q1Ok/xotOA/g==",
"dependencies": {
"chalk": "^2.2.0",
"commander": "^2.11.0",
@@ -3706,6 +3707,9 @@
"node_modules/jsonfile": {
"version": "4.0.0",
"license": "MIT",
"dependencies": {
"graceful-fs": "^4.1.6"
},
"optionalDependencies": {
"graceful-fs": "^4.1.6"
}
@@ -8320,9 +8324,9 @@
}
},
"github-linguist": {
"version": "2.4.3",
"resolved": "https://registry.npmjs.org/github-linguist/-/github-linguist-2.4.3.tgz",
"integrity": "sha512-hKWn1QQ+9oUyOIcUhPzi6AxTcAkYHg4OOwK79Pr05SBTFmdNr7GQkMDJabSGCZwu7SDhEb5YeUwUGqrUfyo7PA==",
"version": "2.4.4",
"resolved": "https://registry.npmjs.org/github-linguist/-/github-linguist-2.4.4.tgz",
"integrity": "sha512-QSw/HfSTqA13t7eqNeGLd62ghnTsTQAUrJQKkUG100NZqqzpsKB9c7gH7lFaGU1ZWGmNSWfhG6q1Ok/xotOA/g==",
"requires": {
"chalk": "^2.2.0",
"commander": "^2.11.0",

View File

@@ -37,7 +37,7 @@
"fast-deep-equal": "^3.1.3",
"file-url": "^3.0.0",
"fs": "0.0.1-security",
"github-linguist": "^2.4.3",
"github-linguist": "^2.4.4",
"glob": "^7.1.7",
"js-yaml": "^4.1.0",
"jsonschema": "1.2.6",

View File

@@ -9,7 +9,6 @@ import * as sinon from "sinon";
import { runQueries } from "./analyze";
import { setCodeQL } from "./codeql";
import { Config } from "./config-utils";
import { getIdPrefix } from "./count-loc";
import * as count from "./count-loc";
import { Language } from "./languages";
import { getRunnerLogger } from "./logging";
@@ -68,33 +67,7 @@ test("status report fields and search path setting", async (t) => {
sarifFile,
JSON.stringify({
runs: [
// variant 1 uses ruleId
{
properties: {
metricResults: [
{
ruleId: `${getIdPrefix(
language
)}/summary/lines-of-code`,
value: 123,
},
],
},
},
// variant 2 uses rule.id
{
properties: {
metricResults: [
{
rule: {
id: `${getIdPrefix(language)}/summary/lines-of-code`,
},
value: 123,
},
],
},
},
// variant 3 references a rule with the lines-of-code tag
// references a rule with the lines-of-code tag, so baseline should be injected
{
tool: {
extensions: [
@@ -231,38 +204,13 @@ test("status report fields and search path setting", async (t) => {
function verifyLineCounts(tmpDir: string) {
// eslint-disable-next-line github/array-foreach
Object.keys(Language).forEach((lang, i) => {
verifyLineCountForFile(
lang as Language,
path.join(tmpDir, `${lang}.sarif`),
i + 1
);
verifyLineCountForFile(path.join(tmpDir, `${lang}.sarif`), i + 1);
});
}
function verifyLineCountForFile(
lang: Language,
filePath: string,
lineCount: number
) {
const idPrefix = getIdPrefix(lang);
function verifyLineCountForFile(filePath: string, lineCount: number) {
const sarif = JSON.parse(fs.readFileSync(filePath, "utf8"));
t.deepEqual(sarif.runs[0].properties.metricResults, [
{
ruleId: `${idPrefix}/summary/lines-of-code`,
value: 123,
baseline: lineCount,
},
]);
t.deepEqual(sarif.runs[1].properties.metricResults, [
{
rule: {
id: `${idPrefix}/summary/lines-of-code`,
},
value: 123,
baseline: lineCount,
},
]);
t.deepEqual(sarif.runs[2].properties.metricResults, [
{
rule: {
index: 0,
@@ -275,7 +223,7 @@ test("status report fields and search path setting", async (t) => {
},
]);
// when the rule doesn't exist, it should not be added
t.deepEqual(sarif.runs[3].properties.metricResults, []);
t.deepEqual(sarif.runs[1].properties.metricResults, []);
}
function verifyQuerySuites(tmpDir: string) {

View File

@@ -7,7 +7,7 @@ import * as yaml from "js-yaml";
import * as analysisPaths from "./analysis-paths";
import { getCodeQL } from "./codeql";
import * as configUtils from "./config-utils";
import { countLoc, getIdPrefix } from "./count-loc";
import { countLoc } from "./count-loc";
import { isScannedLanguage, Language } from "./languages";
import { Logger } from "./logging";
import * as sharedEnv from "./shared-environment";
@@ -116,7 +116,7 @@ async function createdDBForScannedLanguages(
// we extract any scanned languages.
analysisPaths.includeAndExcludeAnalysisPaths(config);
const codeql = getCodeQL(config.codeQLCmd);
const codeql = await getCodeQL(config.codeQLCmd);
for (const language of config.languages) {
if (
isScannedLanguage(language) &&
@@ -164,7 +164,7 @@ async function finalizeDatabaseCreation(
) {
await createdDBForScannedLanguages(config, logger);
const codeql = getCodeQL(config.codeQLCmd);
const codeql = await getCodeQL(config.codeQLCmd);
for (const language of config.languages) {
if (dbIsFinalized(config, language, logger)) {
logger.info(
@@ -230,7 +230,7 @@ export async function runQueries(
logger.info("*************");
logger.startGroup(`Downloading custom packs for ${language}`);
const codeql = getCodeQL(config.codeQLCmd);
const codeql = await getCodeQL(config.codeQLCmd);
const results = await codeql.packDownload(packsWithVersion);
logger.info(
`Downloaded packs: ${results.packs
@@ -320,7 +320,7 @@ export async function runQueries(
sarifFile: string
): Promise<string> {
const databasePath = util.getCodeQLDatabasePath(config, language);
const codeql = getCodeQL(config.codeQLCmd);
const codeql = await getCodeQL(config.codeQLCmd);
return await codeql.databaseInterpretResults(
databasePath,
queries,
@@ -346,7 +346,7 @@ export async function runQueries(
`Query suite file for ${language}-${type}...\n${querySuiteContents}`
);
const codeql = getCodeQL(config.codeQLCmd);
const codeql = await getCodeQL(config.codeQLCmd);
await codeql.databaseRunQueries(
databasePath,
searchPath,
@@ -402,7 +402,7 @@ export async function runCleanup(
): Promise<void> {
logger.startGroup("Cleaning up databases");
for (const language of config.languages) {
const codeql = getCodeQL(config.codeQLCmd);
const codeql = await getCodeQL(config.codeQLCmd);
const databasePath = util.getCodeQLDatabasePath(config, language);
await codeql.databaseCleanup(databasePath, cleanupLevel);
}
@@ -415,27 +415,15 @@ async function injectLinesOfCode(
locPromise: Promise<Partial<Record<Language, number>>>
) {
const lineCounts = await locPromise;
const idPrefix = getIdPrefix(language);
if (language in lineCounts) {
const sarif = JSON.parse(fs.readFileSync(sarifFile, "utf8"));
if (Array.isArray(sarif.runs)) {
for (const run of sarif.runs) {
// Old style: Baseline is inserted when rule ID has suffix /summary/lines-of-code
const ruleId = `${idPrefix}/summary/lines-of-code`;
run.properties = run.properties || {};
run.properties.metricResults = run.properties.metricResults || [];
const rule = run.properties.metricResults.find(
// the rule id can be in either of two places
(r) => r.ruleId === ruleId || r.rule?.id === ruleId
);
// only add the baseline value if the rule already exists
if (rule) {
rule.baseline = lineCounts[language];
}
// New style: Baseline is inserted when matching rule has tag lines-of-code
for (const metric of run.properties.metricResults) {
// Baseline is inserted when matching rule has tag lines-of-code
if (metric.rule && metric.rule.toolComponent) {
const matchingRule =
run.tool.extensions[metric.rule.toolComponent.index].rules[

View File

@@ -40,7 +40,7 @@ export async function runAutobuild(
logger: Logger
) {
logger.startGroup(`Attempting to automatically build ${language} code`);
const codeQL = getCodeQL(config.codeQLCmd);
const codeQL = await getCodeQL(config.codeQLCmd);
await codeQL.runAutobuild(language);
logger.endGroup();
}

View File

@@ -49,7 +49,8 @@ test("download codeql bundle cache", async (t) => {
tmpDir,
tmpDir,
util.GitHubVariant.DOTCOM,
getRunnerLogger(true)
getRunnerLogger(true),
false
);
t.assert(toolcache.find("CodeQL", `0.0.0-${version}`));
@@ -78,7 +79,8 @@ test("download codeql bundle cache explicitly requested with pinned different ve
tmpDir,
tmpDir,
util.GitHubVariant.DOTCOM,
getRunnerLogger(true)
getRunnerLogger(true),
false
);
t.assert(toolcache.find("CodeQL", "0.0.0-20200601"));
@@ -96,7 +98,8 @@ test("download codeql bundle cache explicitly requested with pinned different ve
tmpDir,
tmpDir,
util.GitHubVariant.DOTCOM,
getRunnerLogger(true)
getRunnerLogger(true),
false
);
t.assert(toolcache.find("CodeQL", "0.0.0-20200610"));
@@ -120,7 +123,8 @@ test("don't download codeql bundle cache with pinned different version cached",
tmpDir,
tmpDir,
util.GitHubVariant.DOTCOM,
getRunnerLogger(true)
getRunnerLogger(true),
false
);
t.assert(toolcache.find("CodeQL", "0.0.0-20200601"));
@@ -131,7 +135,8 @@ test("don't download codeql bundle cache with pinned different version cached",
tmpDir,
tmpDir,
util.GitHubVariant.DOTCOM,
getRunnerLogger(true)
getRunnerLogger(true),
false
);
const cachedVersions = toolcache.findAllVersions("CodeQL");
@@ -157,7 +162,8 @@ test("download codeql bundle cache with different version cached (not pinned)",
tmpDir,
tmpDir,
util.GitHubVariant.DOTCOM,
getRunnerLogger(true)
getRunnerLogger(true),
false
);
t.assert(toolcache.find("CodeQL", "0.0.0-20200601"));
@@ -183,7 +189,8 @@ test("download codeql bundle cache with different version cached (not pinned)",
tmpDir,
tmpDir,
util.GitHubVariant.DOTCOM,
getRunnerLogger(true)
getRunnerLogger(true),
false
);
const cachedVersions = toolcache.findAllVersions("CodeQL");
@@ -209,7 +216,8 @@ test('download codeql bundle cache with pinned different version cached if "late
tmpDir,
tmpDir,
util.GitHubVariant.DOTCOM,
getRunnerLogger(true)
getRunnerLogger(true),
false
);
t.assert(toolcache.find("CodeQL", "0.0.0-20200601"));
@@ -236,7 +244,8 @@ test('download codeql bundle cache with pinned different version cached if "late
tmpDir,
tmpDir,
util.GitHubVariant.DOTCOM,
getRunnerLogger(true)
getRunnerLogger(true),
false
);
const cachedVersions = toolcache.findAllVersions("CodeQL");
@@ -290,7 +299,8 @@ test("download codeql bundle from github ae endpoint", async (t) => {
tmpDir,
tmpDir,
util.GitHubVariant.GHAE,
getRunnerLogger(true)
getRunnerLogger(true),
false
);
const cachedVersions = toolcache.findAllVersions("CodeQL");

View File

@@ -178,7 +178,26 @@ let cachedCodeQL: CodeQL | undefined = undefined;
const CODEQL_BUNDLE_VERSION = defaults.bundleVersion;
const CODEQL_DEFAULT_ACTION_REPOSITORY = "github/codeql-action";
/**
* The oldest version of CodeQL that the Action will run with. This should be
* at least three minor versions behind the current version. The version flags
* below can be used to conditionally enable certain features on versions newer
* than this. Please record the reason we cannot support an older version.
*
* Reason: Changes to how the tracing environment is set up.
*/
const CODEQL_MINIMUM_VERSION = "2.3.1";
/**
* Versions of CodeQL that version-flag certain functionality in the Action.
* For convenience, please keep these in descending order. Once a version
* flag is older than the oldest supported version above, it may be removed.
*/
const CODEQL_VERSION_RAM_FINALIZE = "2.5.8";
const CODEQL_VERSION_DIAGNOSTICS = "2.5.6";
const CODEQL_VERSION_METRICS = "2.5.5";
const CODEQL_VERSION_GROUP_RULES = "2.5.5";
const CODEQL_VERSION_SARIF_GROUP = "2.5.3";
function getCodeQLBundleName(): string {
let platform: string;
@@ -319,7 +338,8 @@ export async function setupCodeQL(
tempDir: string,
toolCacheDir: string,
variant: util.GitHubVariant,
logger: Logger
logger: Logger,
checkVersion: boolean
): Promise<{ codeql: CodeQL; toolsVersion: string }> {
try {
// We use the special value of 'latest' to prioritize the version in the
@@ -430,7 +450,7 @@ export async function setupCodeQL(
throw new Error(`Unsupported platform: ${process.platform}`);
}
cachedCodeQL = getCodeQLForCmd(codeqlCmd);
cachedCodeQL = await getCodeQLForCmd(codeqlCmd, checkVersion);
return { codeql: cachedCodeQL, toolsVersion: codeqlURLVersion };
} catch (e) {
logger.error(e);
@@ -467,9 +487,9 @@ export function convertToSemVer(version: string, logger: Logger): string {
/**
* Use the CodeQL executable located at the given path.
*/
export function getCodeQL(cmd: string): CodeQL {
export async function getCodeQL(cmd: string): Promise<CodeQL> {
if (cachedCodeQL === undefined) {
cachedCodeQL = getCodeQLForCmd(cmd);
cachedCodeQL = await getCodeQLForCmd(cmd, true);
}
return cachedCodeQL;
}
@@ -542,13 +562,19 @@ export function getCachedCodeQL(): CodeQL {
return cachedCodeQL;
}
function getCodeQLForCmd(cmd: string): CodeQL {
return {
async function getCodeQLForCmd(
cmd: string,
checkVersion: boolean
): Promise<CodeQL> {
let cachedVersion: undefined | Promise<string> = undefined;
const codeql = {
getPath() {
return cmd;
},
async getVersion() {
return await runTool(cmd, ["version", "--format=terse"]);
if (cachedVersion === undefined)
cachedVersion = runTool(cmd, ["version", "--format=terse"]);
return await cachedVersion;
},
async printVersion() {
await runTool(cmd, ["version", "--format=json"]);
@@ -775,15 +801,21 @@ function getCodeQLForCmd(cmd: string): CodeQL {
"interpret-results",
threadsFlag,
"--format=sarif-latest",
"--print-diagnostics-summary",
"--print-metrics-summary",
"--sarif-group-rules-by-pack",
"-v",
`--output=${sarifFile}`,
addSnippetsFlag,
...getExtraOptionsFromEnv(["database", "interpret-results"]),
];
if (automationDetailsId !== undefined) {
if (await util.codeQlVersionAbove(this, CODEQL_VERSION_DIAGNOSTICS))
codeqlArgs.push("--print-diagnostics-summary");
if (await util.codeQlVersionAbove(this, CODEQL_VERSION_METRICS))
codeqlArgs.push("--print-metrics-summary");
if (await util.codeQlVersionAbove(this, CODEQL_VERSION_GROUP_RULES))
codeqlArgs.push("--sarif-group-rules-by-pack");
if (
automationDetailsId !== undefined &&
(await util.codeQlVersionAbove(this, CODEQL_VERSION_SARIF_GROUP))
) {
codeqlArgs.push("--sarif-category", automationDetailsId);
}
codeqlArgs.push(databasePath, ...querySuitePaths);
@@ -856,6 +888,15 @@ function getCodeQLForCmd(cmd: string): CodeQL {
await new toolrunner.ToolRunner(cmd, args).exec();
},
};
if (
checkVersion &&
!(await util.codeQlVersionAbove(codeql, CODEQL_MINIMUM_VERSION))
) {
throw new Error(
`Expected a CodeQL CLI with version at least ${CODEQL_MINIMUM_VERSION} but got version ${await codeql.getVersion()}`
);
}
return codeql;
}
function packWithVersionToString(pack: PackWithVersion): string {

View File

@@ -2,10 +2,6 @@ import { LocDir } from "github-linguist";
import { Language } from "./languages";
import { Logger } from "./logging";
import { assertNever } from "./util";
// Language IDs used by codeql when specifying its metrics.
export type IdPrefix = "cpp" | "cs" | "go" | "java" | "js" | "py" | "rb";
// Map from linguist language names to language prefixes used in the action and codeql
const linguistToMetrics: Record<string, Language> = {
@@ -31,28 +27,6 @@ const nameToLinguist = Object.entries(linguistToMetrics).reduce(
{} as Record<Language, string[]>
);
export function getIdPrefix(language: Language): IdPrefix {
switch (language) {
case Language.cpp:
return "cpp";
case Language.csharp:
return "cs";
case Language.go:
return "go";
case Language.java:
return "java";
case Language.javascript:
return "js";
case Language.python:
return "py";
case Language.ruby:
return "rb";
default:
assertNever(language);
}
}
/**
* Count the lines of code of the specified language using the include
* and exclude glob paths.

View File

@@ -52,7 +52,7 @@ export async function uploadDatabases(
return;
}
const codeql = getCodeQL(config.codeQLCmd);
const codeql = await getCodeQL(config.codeQLCmd);
for (const language of config.languages) {
// Bundle the database up into a single zip file
const databasePath = util.getCodeQLDatabasePath(config, language);

View File

@@ -1,3 +1,3 @@
{
"bundleVersion": "codeql-bundle-20210809"
"bundleVersion": "codeql-bundle-20210824"
}

View File

@@ -28,7 +28,8 @@ export async function initCodeQL(
tempDir,
toolCacheDir,
variant,
logger
logger,
true
);
await codeql.printVersion();
logger.endGroup();

View File

@@ -195,7 +195,7 @@ program
let codeql: CodeQL;
if (cmd.codeqlPath !== undefined) {
codeql = getCodeQL(cmd.codeqlPath);
codeql = await getCodeQL(cmd.codeqlPath);
} else {
codeql = (
await initCodeQL(

View File

@@ -123,7 +123,7 @@ export function getAddSnippetsFlag(
/**
* Get the codeql `--threads` value specified for the `threads` input.
* If not value was specified, all available threads will be used.
* If no value was specified, all available threads will be used.
*
* The value will be capped to the number of available CPUs.
*

View File

@@ -3,7 +3,7 @@ name: Pack testing in the CodeQL Action
disable-default-queries: true
packs:
javascript:
- dsp-testing/codeql-pack1@0.0.4
- dsp-testing/codeql-pack1@0.1.0
- dsp-testing/codeql-pack2 # latest
paths-ignore:
- tests