Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: github/codeql-action
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.26.7
Choose a base ref
...
head repository: github/codeql-action
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.26.8
Choose a head ref

Commits on Sep 11, 2024

  1. Refactor: upload all available debug artifacts in init-post

    Previously, we uploaded SARIF artifacts in the `analyze-post` step and database and log artifacts in the `init-post` step. As we migrate to the updated `artifact` dependencies, we want to switch to uploading all artifacts in one step.
    
    In order to upload all artifacts in one go and maintain the artifacts at the root of the debug directory, we first move SARIF artifacts to the database directory. This should not affect any other consumers of the SARIF file as this occurs in the `init-post` step.
    angelapwen committed Sep 11, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    crazy-max CrazyMax
    Copy the full SHA
    b296f26 View commit details
  2. Only upload upload-sarif debug artifacts at most once

    Previously, we uploaded combined SARIF artifacts in both the `analyze-post` and `upload-sarif-post` steps. This change ensures that these artifacts are uploaded at most once — in `analyze-post` if it is a first-party run and `upload-sarif-post` if it is a third-party run.
    
    This is a defensive check because as we upgrade to the new `artifact` dependencies we will not be able to upload artifacts to the same artifact directory.
    angelapwen committed Sep 11, 2024
    Copy the full SHA
    c098b25 View commit details
  3. Rebuild: add transpiled files

    angelapwen committed Sep 11, 2024
    Copy the full SHA
    4ba2440 View commit details
  4. Remove unused helper file

    angelapwen committed Sep 11, 2024
    Copy the full SHA
    82ce313 View commit details
  5. Use .push rather than .concat

    angelapwen committed Sep 11, 2024
    Copy the full SHA
    d4bfd40 View commit details

Commits on Sep 12, 2024

  1. Copy the full SHA
    cb7faf5 View commit details
  2. Rename upload-debug-artifacts to combined-sarif-artifacts

    More accurately describes what these artifacts are, rather than the step they're uploaded in.
    angelapwen committed Sep 12, 2024
    Copy the full SHA
    e771680 View commit details
  3. Copy SARIF file to database location rather than move

    angelapwen committed Sep 12, 2024
    Copy the full SHA
    bc660fc View commit details

Commits on Sep 13, 2024

  1. Fix incorrect documentation about the token input to the Actions.

    chrisgavin committed Sep 13, 2024
    Copy the full SHA
    d795ead View commit details
  2. Update changelog and version after v3.26.7

    github-actions[bot] committed Sep 13, 2024
    Copy the full SHA
    d4f57b8 View commit details
  3. Update checked-in dependencies

    github-actions[bot] committed Sep 13, 2024
    Copy the full SHA
    fa08c06 View commit details
  4. Merge pull request #2479 from github/mergeback/v3.26.7-to-main-8214744c

    Mergeback v3.26.7 refs/heads/releases/v3 into main
    dbartol authored Sep 13, 2024
    Copy the full SHA
    e1d2bc5 View commit details
  5. Use RFC-style requirements.

    Co-authored-by: Andrew Eisenberg <aeisenberg@github.com>
    chrisgavin and aeisenberg authored Sep 13, 2024
    Copy the full SHA
    51de6a8 View commit details
  6. Add a warning to not specify a token input in most cases.

    chrisgavin committed Sep 13, 2024
    Copy the full SHA
    86b04fb View commit details
  7. Merge pull request #2477 from github/fix-incorrect-token-docs

    Fix incorrect documentation about the `token` input to the Actions.
    chrisgavin authored Sep 13, 2024
    Copy the full SHA
    c101242 View commit details
  8. Use generated token on checkout

    The script `.github/update-release-branch.py` uses the `git` command
    to push changes. Therefore we need to ensure that `git` authenticates
    with a token that has the `workflows` write permision.
    
    This change restore the GitHub token used by the script to access the
    API and applies the `workflows` write permission to the token used by `git`.
    rvermeulen committed Sep 13, 2024
    Copy the full SHA
    762210d View commit details
  9. Merge pull request #2475 from github/angelapwen/refactor-debug-artifa…

    …cts-upload
    
    Refactor: prepare debug artifacts for `artifact` upgrades
    angelapwen authored Sep 13, 2024
    Copy the full SHA
    fe22310 View commit details
  10. Merge pull request #2481 from rvermeulen/rvermeulen/use-correct-token…

    …-for-auth
    
    Use generated token on checkout
    dbartol authored Sep 13, 2024
    Copy the full SHA
    5618c9f View commit details

Commits on Sep 16, 2024

  1. Copy the full SHA
    d061f2c View commit details
  2. Copy the full SHA
    bbd9c4a View commit details
  3. Add changelog note

    github-actions[bot] committed Sep 16, 2024
    Copy the full SHA
    6cc3253 View commit details
  4. Copy the full SHA
    80d7a6c View commit details
  5. Copy the full SHA
    bbd7c80 View commit details
  6. Copy the full SHA
    dd7307d View commit details
  7. Improve documentation

    henrymercer committed Sep 16, 2024
    Copy the full SHA
    213bf36 View commit details

Commits on Sep 17, 2024

  1. Turn invalid helpUri attribute into a warning

    rvermeulen committed Sep 17, 2024
    Copy the full SHA
    642bbfc View commit details
  2. Merge pull request #2486 from github/henrymercer/improve-debug-artifa…

    …ct-robustness
    
    Improve the robustness of creating and uploading debug artifacts
    henrymercer authored Sep 17, 2024
    Copy the full SHA
    782de45 View commit details
  3. Copy the full SHA
    78d398e View commit details
  4. Copy the full SHA
    d0a3cf2 View commit details
  5. Improve logging for combined SARIF debug artifact

    henrymercer committed Sep 17, 2024
    Copy the full SHA
    6e24973 View commit details
  6. Merge pull request #2488 from github/henrymercer/debug-artifacts-bett…

    …er-logging
    
    Improve logging when preparing and uploading debug artifacts
    henrymercer authored Sep 17, 2024
    Copy the full SHA
    34666c1 View commit details
  7. Merge branch 'main' into rvermeulen/uri-errors-as-warnings

    rvermeulen authored Sep 17, 2024
    Copy the full SHA
    a1a585f View commit details
  8. Rebuild JavaScript files

    rvermeulen committed Sep 17, 2024
    Copy the full SHA
    498c508 View commit details
  9. Merge pull request #2487 from rvermeulen/rvermeulen/uri-errors-as-war…

    …nings
    
    Turn URI errors into warnings
    rvermeulen authored Sep 17, 2024
    Copy the full SHA
    cb28816 View commit details

Commits on Sep 18, 2024

  1. Merge branch 'main' into update-bundle/codeql-bundle-v2.19.0

    smowton authored Sep 18, 2024
    Copy the full SHA
    e0e2d75 View commit details
  2. Merge pull request #2483 from github/update-bundle/codeql-bundle-v2.19.0

    Update default bundle to 2.19.0
    smowton authored Sep 18, 2024
    Copy the full SHA
    64431c6 View commit details

Commits on Sep 19, 2024

  1. Update changelog for v3.26.8

    github-actions[bot] committed Sep 19, 2024
    Copy the full SHA
    00b3604 View commit details
  2. Merge pull request #2490 from github/update-v3.26.8-64431c66d

    Merge main into releases/v3
    smowton authored Sep 19, 2024
    Copy the full SHA
    294a9d9 View commit details
Showing with 624 additions and 655 deletions.
  1. +6 −4 .github/workflows/update-release-branch.yml
  2. +4 −0 CHANGELOG.md
  3. +1 −1 analyze/action.yml
  4. +0 −44 lib/analyze-action-post-helper.js
  5. +0 −1 lib/analyze-action-post-helper.js.map
  6. +0 −73 lib/analyze-action-post-helper.test.js
  7. +0 −1 lib/analyze-action-post-helper.test.js.map
  8. +9 −7 lib/analyze-action-post.js
  9. +1 −1 lib/analyze-action-post.js.map
  10. +2 −1 lib/analyze-action.js
  11. +1 −1 lib/analyze-action.js.map
  12. +1 −1 lib/analyze.js
  13. +1 −1 lib/analyze.js.map
  14. +1 −1 lib/autobuild-action.js
  15. +1 −1 lib/autobuild-action.js.map
  16. +2 −2 lib/codeql.js
  17. +1 −1 lib/codeql.js.map
  18. +140 −63 lib/debug-artifacts.js
  19. +1 −1 lib/debug-artifacts.js.map
  20. +5 −5 lib/debug-artifacts.test.js
  21. +1 −1 lib/debug-artifacts.test.js.map
  22. +4 −4 lib/defaults.json
  23. +2 −0 lib/environment.js
  24. +1 −1 lib/environment.js.map
  25. +2 −3 lib/init-action-post-helper.js
  26. +1 −1 lib/init-action-post-helper.js.map
  27. +6 −10 lib/init-action-post-helper.test.js
  28. +1 −1 lib/init-action-post-helper.test.js.map
  29. +1 −1 lib/init-action-post.js
  30. +1 −1 lib/init-action-post.js.map
  31. +1 −1 lib/init-action.js
  32. +1 −1 lib/init-action.js.map
  33. +2 −2 lib/init.js
  34. +1 −1 lib/init.js.map
  35. +10 −0 lib/logging.js
  36. +1 −1 lib/logging.js.map
  37. +1 −1 lib/resolve-environment-action.js
  38. +1 −1 lib/resolve-environment-action.js.map
  39. +1 −1 lib/setup-codeql.test.js
  40. +1 −1 lib/setup-codeql.test.js.map
  41. +1 −1 lib/start-proxy-action-post.js
  42. +1 −1 lib/start-proxy-action-post.js.map
  43. +1 −1 lib/start-proxy-action.js
  44. +1 −1 lib/start-proxy-action.js.map
  45. +1 −1 lib/status-report.js
  46. +1 −1 lib/status-report.js.map
  47. +1 −1 lib/trap-caching.js
  48. +1 −1 lib/trap-caching.js.map
  49. +8 −3 lib/upload-lib.js
  50. +1 −1 lib/upload-lib.js.map
  51. +2 −2 lib/upload-lib.test.js
  52. +1 −1 lib/upload-lib.test.js.map
  53. +0 −54 lib/upload-sarif-action-post-helper.js
  54. +0 −1 lib/upload-sarif-action-post-helper.js.map
  55. +9 −3 lib/upload-sarif-action-post.js
  56. +1 −1 lib/upload-sarif-action-post.js.map
  57. +1 −1 lib/upload-sarif-action.js
  58. +1 −1 lib/upload-sarif-action.js.map
  59. +7 −1 lib/util.js
  60. +1 −1 lib/util.js.map
  61. +1 −1 node_modules/.package-lock.json
  62. +2 −2 package-lock.json
  63. +1 −1 package.json
  64. +0 −57 src/analyze-action-post-helper.test.ts
  65. +0 −30 src/analyze-action-post-helper.ts
  66. +12 −10 src/analyze-action-post.ts
  67. +2 −1 src/analyze-action.ts
  68. +1 −1 src/analyze.ts
  69. +2 −1 src/autobuild-action.ts
  70. +3 −3 src/codeql.ts
  71. +8 −5 src/debug-artifacts.test.ts
  72. +212 −90 src/debug-artifacts.ts
  73. +4 −4 src/defaults.json
  74. +3 −0 src/environment.ts
  75. +6 −12 src/init-action-post-helper.test.ts
  76. +2 −5 src/init-action-post-helper.ts
  77. +1 −2 src/init-action-post.ts
  78. +2 −1 src/init-action.ts
  79. +4 −6 src/init.ts
  80. +9 −0 src/logging.ts
  81. +4 −3 src/resolve-environment-action.ts
  82. +2 −2 src/setup-codeql.test.ts
  83. +2 −2 src/start-proxy-action-post.ts
  84. +1 −3 src/start-proxy-action.ts
  85. +4 −4 src/status-report.ts
  86. +33 −21 src/testdata/with-invalid-uri.sarif
  87. +7 −2 src/trap-caching.ts
  88. +2 −1 src/upload-lib.test.ts
  89. +15 −6 src/upload-lib.ts
  90. +0 −49 src/upload-sarif-action-post-helper.ts
  91. +12 −6 src/upload-sarif-action-post.ts
  92. +2 −1 src/upload-sarif-action.ts
  93. +7 −1 src/util.ts
  94. +1 −1 upload-sarif/action.yml
10 changes: 6 additions & 4 deletions .github/workflows/update-release-branch.yml
Original file line number Diff line number Diff line change
@@ -115,19 +115,21 @@ jobs:
SOURCE_BRANCH: ${{ needs.prepare.outputs.backport_source_branch }}
TARGET_BRANCH: ${{ matrix.target_branch }}
steps:
- uses: actions/create-github-app-token@31c86eb3b33c9b601a1f60f98dcbfd1d70f379b4
- name: Generate token
uses: actions/create-github-app-token@31c86eb3b33c9b601a1f60f98dcbfd1d70f379b4
id: app-token
with:
app-id: ${{ vars.AUTOMATION_APP_ID }}
private-key: ${{ secrets.AUTOMATION_PRIVATE_KEY }}
- uses: actions/checkout@v4

- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Need full history for calculation of diffs
token: ${{ steps.app-token.outputs.token }}
- uses: ./.github/actions/release-initialise

- name: Update older release branch
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
echo SOURCE_BRANCH=${SOURCE_BRANCH}
echo TARGET_BRANCH=${TARGET_BRANCH}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,10 @@ See the [releases page](https://github.com/github/codeql-action/releases) for th

Note that the only difference between `v2` and `v3` of the CodeQL Action is the node version they support, with `v3` running on node 20 while we continue to release `v2` to support running on node 16. For example `3.22.11` was the first `v3` release and is functionally identical to `2.22.11`. This approach ensures an easy way to track exactly which features are included in different versions, indicated by the minor and patch version numbers.

## 3.26.8 - 19 Sep 2024

- Update default CodeQL bundle version to 2.19.0. [#2483](https://github.com/github/codeql-action/pull/2483)

## 3.26.7 - 13 Sep 2024

- Update default CodeQL bundle version to 2.18.4. [#2471](https://github.com/github/codeql-action/pull/2471)
2 changes: 1 addition & 1 deletion analyze/action.yml
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ inputs:
required: true
default: "true"
token:
description: "GitHub token to use for authenticating with this instance of GitHub. The token needs the `security-events: write` permission."
description: "GitHub token to use for authenticating with this instance of GitHub. The token must be the built-in GitHub Actions token, and the workflow must have the `security-events: write` permission. Most of the time it is advisable to avoid specifying this input so that the workflow falls back to using the default value."
required: false
default: ${{ github.token }}
matrix:
44 changes: 0 additions & 44 deletions lib/analyze-action-post-helper.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/analyze-action-post-helper.js.map

This file was deleted.

73 changes: 0 additions & 73 deletions lib/analyze-action-post-helper.test.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/analyze-action-post-helper.test.js.map

This file was deleted.

16 changes: 9 additions & 7 deletions lib/analyze-action-post.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/analyze-action-post.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/analyze-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/analyze-action.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/analyze.js
2 changes: 1 addition & 1 deletion lib/analyze.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/autobuild-action.js
2 changes: 1 addition & 1 deletion lib/autobuild-action.js.map
4 changes: 2 additions & 2 deletions lib/codeql.js
2 changes: 1 addition & 1 deletion lib/codeql.js.map

Large diffs are not rendered by default.

203 changes: 140 additions & 63 deletions lib/debug-artifacts.js
2 changes: 1 addition & 1 deletion lib/debug-artifacts.js.map
10 changes: 5 additions & 5 deletions lib/debug-artifacts.test.js
2 changes: 1 addition & 1 deletion lib/debug-artifacts.test.js.map
8 changes: 4 additions & 4 deletions lib/defaults.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"bundleVersion": "codeql-bundle-v2.18.4",
"cliVersion": "2.18.4",
"priorBundleVersion": "codeql-bundle-v2.18.3",
"priorCliVersion": "2.18.3"
"bundleVersion": "codeql-bundle-v2.19.0",
"cliVersion": "2.19.0",
"priorBundleVersion": "codeql-bundle-v2.18.4",
"priorCliVersion": "2.18.4"
}
2 changes: 2 additions & 0 deletions lib/environment.js
2 changes: 1 addition & 1 deletion lib/environment.js.map
5 changes: 2 additions & 3 deletions lib/init-action-post-helper.js
2 changes: 1 addition & 1 deletion lib/init-action-post-helper.js.map
16 changes: 6 additions & 10 deletions lib/init-action-post-helper.test.js
2 changes: 1 addition & 1 deletion lib/init-action-post-helper.test.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/init-action-post.js
2 changes: 1 addition & 1 deletion lib/init-action-post.js.map
2 changes: 1 addition & 1 deletion lib/init-action.js
2 changes: 1 addition & 1 deletion lib/init-action.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/init.js
2 changes: 1 addition & 1 deletion lib/init.js.map
10 changes: 10 additions & 0 deletions lib/logging.js
2 changes: 1 addition & 1 deletion lib/logging.js.map
2 changes: 1 addition & 1 deletion lib/resolve-environment-action.js
2 changes: 1 addition & 1 deletion lib/resolve-environment-action.js.map
2 changes: 1 addition & 1 deletion lib/setup-codeql.test.js
2 changes: 1 addition & 1 deletion lib/setup-codeql.test.js.map
2 changes: 1 addition & 1 deletion lib/start-proxy-action-post.js
2 changes: 1 addition & 1 deletion lib/start-proxy-action-post.js.map
2 changes: 1 addition & 1 deletion lib/start-proxy-action.js
2 changes: 1 addition & 1 deletion lib/start-proxy-action.js.map
2 changes: 1 addition & 1 deletion lib/status-report.js
2 changes: 1 addition & 1 deletion lib/status-report.js.map
2 changes: 1 addition & 1 deletion lib/trap-caching.js
2 changes: 1 addition & 1 deletion lib/trap-caching.js.map
11 changes: 8 additions & 3 deletions lib/upload-lib.js
2 changes: 1 addition & 1 deletion lib/upload-lib.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/upload-lib.test.js
2 changes: 1 addition & 1 deletion lib/upload-lib.test.js.map

Large diffs are not rendered by default.

54 changes: 0 additions & 54 deletions lib/upload-sarif-action-post-helper.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/upload-sarif-action-post-helper.js.map

This file was deleted.

12 changes: 9 additions & 3 deletions lib/upload-sarif-action-post.js
2 changes: 1 addition & 1 deletion lib/upload-sarif-action-post.js.map
2 changes: 1 addition & 1 deletion lib/upload-sarif-action.js
2 changes: 1 addition & 1 deletion lib/upload-sarif-action.js.map
8 changes: 7 additions & 1 deletion lib/util.js
2 changes: 1 addition & 1 deletion lib/util.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion node_modules/.package-lock.json
4 changes: 2 additions & 2 deletions package-lock.json
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codeql",
"version": "3.26.7",
"version": "3.26.8",
"private": true,
"description": "CodeQL action",
"scripts": {
57 changes: 0 additions & 57 deletions src/analyze-action-post-helper.test.ts

This file was deleted.

30 changes: 0 additions & 30 deletions src/analyze-action-post-helper.ts

This file was deleted.

22 changes: 12 additions & 10 deletions src/analyze-action-post.ts
Original file line number Diff line number Diff line change
@@ -5,23 +5,25 @@
*/
import * as core from "@actions/core";

import * as analyzeActionPostHelper from "./analyze-action-post-helper";
import * as debugArtifacts from "./debug-artifacts";
import * as uploadSarifActionPostHelper from "./upload-sarif-action-post-helper";
import { wrapError } from "./util";
import { EnvVar } from "./environment";
import { getActionsLogger, withGroup } from "./logging";
import { getErrorMessage } from "./util";

async function runWrapper() {
try {
await analyzeActionPostHelper.run(debugArtifacts.uploadSarifDebugArtifact);
const logger = getActionsLogger();

// Also run the upload-sarif post action since we're potentially running
// the same steps in the analyze action.
await uploadSarifActionPostHelper.uploadArtifacts(
debugArtifacts.uploadDebugArtifacts,
);
// Upload SARIF artifacts if we determine that this is a first-party analysis run.
// For third-party runs, this artifact will be uploaded in the `upload-sarif-post` step.
if (process.env[EnvVar.INIT_ACTION_HAS_RUN] === "true") {
await withGroup("Uploading combined SARIF debug artifact", () =>
debugArtifacts.uploadCombinedSarifArtifacts(logger),
);
}
} catch (error) {
core.setFailed(
`analyze post-action step failed: ${wrapError(error).message}`,
`analyze post-action step failed: ${getErrorMessage(error)}`,
);
}
}
3 changes: 2 additions & 1 deletion src/analyze-action.ts
Original file line number Diff line number Diff line change
@@ -230,6 +230,7 @@ async function run() {

const apiDetails = getApiDetails();
const outputDir = actionsUtil.getRequiredInput("output");
core.exportVariable(EnvVar.SARIF_RESULTS_OUTPUT_DIR, outputDir);
const threads = util.getThreadsFlag(
actionsUtil.getOptionalInput("threads") || process.env["CODEQL_THREADS"],
logger,
@@ -416,7 +417,7 @@ async function runWrapper() {
try {
await runPromise;
} catch (error) {
core.setFailed(`analyze action failed: ${util.wrapError(error).message}`);
core.setFailed(`analyze action failed: ${util.getErrorMessage(error)}`);
}
await util.checkForTimeout();
}
2 changes: 1 addition & 1 deletion src/analyze.ts
Original file line number Diff line number Diff line change
@@ -314,7 +314,7 @@ export async function runQueries(
statusReport.analyze_failure_language = language;
throw new CodeQLAnalysisError(
statusReport,
`Error running analysis for ${language}: ${util.wrapError(e).message}`,
`Error running analysis for ${language}: ${util.getErrorMessage(e)}`,
util.wrapError(e),
);
}
3 changes: 2 additions & 1 deletion src/autobuild-action.ts
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ import {
checkActionVersion,
checkDiskUsage,
checkGitHubVersionInRange,
getErrorMessage,
initializeEnvironment,
wrapError,
} from "./util";
@@ -141,7 +142,7 @@ async function runWrapper() {
try {
await run();
} catch (error) {
core.setFailed(`autobuild action failed. ${wrapError(error).message}`);
core.setFailed(`autobuild action failed. ${getErrorMessage(error)}`);
}
}

6 changes: 3 additions & 3 deletions src/codeql.ts
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ import * as setupCodeql from "./setup-codeql";
import { ToolsFeature, isSupportedToolsFeature } from "./tools-features";
import { shouldEnableIndirectTracing } from "./tracer-config";
import * as util from "./util";
import { BuildMode, wrapError, cloneObject } from "./util";
import { BuildMode, cloneObject, getErrorMessage } from "./util";

type Options = Array<string | number | boolean>;

@@ -398,7 +398,7 @@ export async function setupCodeQL(
};
} catch (e) {
throw new Error(
`Unable to download and extract CodeQL CLI: ${wrapError(e).message}`,
`Unable to download and extract CodeQL CLI: ${getErrorMessage(e)}`,
);
}
}
@@ -707,7 +707,7 @@ export async function getCodeQLForCmd(
e instanceof util.ConfigurationError
? util.ConfigurationError
: Error;
throw new ErrorConstructor(`${prefix} ${util.wrapError(e).message}`);
throw new ErrorConstructor(`${prefix} ${getErrorMessage(e)}`);
} else {
throw e;
}
13 changes: 8 additions & 5 deletions src/debug-artifacts.test.ts
Original file line number Diff line number Diff line change
@@ -2,15 +2,18 @@ import test from "ava";

import * as debugArtifacts from "./debug-artifacts";

test("sanitizeArifactName", (t) => {
test("sanitizeArtifactName", (t) => {
t.deepEqual(
debugArtifacts.sanitizeArifactName("hello-world_"),
debugArtifacts.sanitizeArtifactName("hello-world_"),
"hello-world_",
);
t.deepEqual(debugArtifacts.sanitizeArifactName("hello`world`"), "helloworld");
t.deepEqual(debugArtifacts.sanitizeArifactName("hello===123"), "hello123");
t.deepEqual(
debugArtifacts.sanitizeArifactName("*m)a&n^y%i££n+v!a:l[i]d"),
debugArtifacts.sanitizeArtifactName("hello`world`"),
"helloworld",
);
t.deepEqual(debugArtifacts.sanitizeArtifactName("hello===123"), "hello123");
t.deepEqual(
debugArtifacts.sanitizeArtifactName("*m)a&n^y%i££n+v!a:l[i]d"),
"manyinvalid",
);
});
302 changes: 212 additions & 90 deletions src/debug-artifacts.ts
Original file line number Diff line number Diff line change
@@ -6,23 +6,223 @@ import * as core from "@actions/core";
import AdmZip from "adm-zip";
import del from "del";

import { getRequiredInput } from "./actions-util";
import { getRequiredInput, getTemporaryDirectory } from "./actions-util";
import { dbIsFinalized } from "./analyze";
import { getCodeQL } from "./codeql";
import { Config } from "./config-utils";
import { EnvVar } from "./environment";
import { Language } from "./languages";
import { Logger } from "./logging";
import { Logger, withGroup } from "./logging";
import {
bundleDb,
doesDirectoryExist,
getCodeQLDatabasePath,
getErrorMessage,
listFolder,
} from "./util";

export function sanitizeArifactName(name: string): string {
export function sanitizeArtifactName(name: string): string {
return name.replace(/[^a-zA-Z0-9_\\-]+/g, "");
}

/**
* Upload Actions SARIF artifacts for debugging when CODEQL_ACTION_DEBUG_COMBINED_SARIF
* environment variable is set
*/
export async function uploadCombinedSarifArtifacts(logger: Logger) {
const tempDir = getTemporaryDirectory();

// Upload Actions SARIF artifacts for debugging when environment variable is set
if (process.env["CODEQL_ACTION_DEBUG_COMBINED_SARIF"] === "true") {
logger.info(
"Uploading available combined SARIF files as Actions debugging artifact...",
);

const baseTempDir = path.resolve(tempDir, "combined-sarif");

const toUpload: string[] = [];

if (fs.existsSync(baseTempDir)) {
const outputDirs = fs.readdirSync(baseTempDir);

for (const outputDir of outputDirs) {
const sarifFiles = fs
.readdirSync(path.resolve(baseTempDir, outputDir))
.filter((f) => f.endsWith(".sarif"));

for (const sarifFile of sarifFiles) {
toUpload.push(path.resolve(baseTempDir, outputDir, sarifFile));
}
}
}

try {
await uploadDebugArtifacts(
toUpload,
baseTempDir,
"combined-sarif-artifacts",
);
} catch (e) {
logger.warning(
`Failed to upload combined SARIF files as Actions debugging artifact. Reason: ${getErrorMessage(
e,
)}`,
);
}
}
}

/**
* Try to prepare a SARIF result debug artifact for the given language.
*
* @return The path to that debug artifact, or undefined if an error occurs.
*/
function tryPrepareSarifDebugArtifact(
config: Config,
language: Language,
logger: Logger,
): string | undefined {
try {
const analyzeActionOutputDir = process.env[EnvVar.SARIF_RESULTS_OUTPUT_DIR];
if (
analyzeActionOutputDir !== undefined &&
fs.existsSync(analyzeActionOutputDir) &&
fs.lstatSync(analyzeActionOutputDir).isDirectory()
) {
const sarifFile = path.resolve(
analyzeActionOutputDir,
`${language}.sarif`,
);
// Move SARIF to DB location so that they can be uploaded with the same root directory as the other artifacts.
if (fs.existsSync(sarifFile)) {
const sarifInDbLocation = path.resolve(
config.dbLocation,
`${language}.sarif`,
);
fs.copyFileSync(sarifFile, sarifInDbLocation);
return sarifInDbLocation;
}
}
} catch (e) {
logger.warning(
`Failed to find SARIF results path for ${language}. Reason: ${getErrorMessage(
e,
)}`,
);
}
return undefined;
}

/**
* Try to bundle the database for the given language.
*
* @return The path to the database bundle, or undefined if an error occurs.
*/
async function tryBundleDatabase(
config: Config,
language: Language,
logger: Logger,
): Promise<string | undefined> {
try {
if (dbIsFinalized(config, language, logger)) {
try {
return await createDatabaseBundleCli(config, language);
} catch (e) {
logger.warning(
`Failed to bundle database for ${language} using the CLI. ` +
`Falling back to a partial bundle. Reason: ${getErrorMessage(e)}`,
);
}
}
return await createPartialDatabaseBundle(config, language);
} catch (e) {
logger.warning(
`Failed to bundle database for ${language}. Reason: ${getErrorMessage(
e,
)}`,
);
return undefined;
}
}

/**
* Attempt to upload all available debug artifacts.
*
* Logs and suppresses any errors that occur.
*/
export async function tryUploadAllAvailableDebugArtifacts(
config: Config,
logger: Logger,
) {
const filesToUpload: string[] = [];
try {
for (const language of config.languages) {
await withGroup(`Uploading debug artifacts for ${language}`, async () => {
logger.info("Preparing SARIF result debug artifact...");
const sarifResultDebugArtifact = tryPrepareSarifDebugArtifact(
config,
language,
logger,
);
if (sarifResultDebugArtifact) {
filesToUpload.push(sarifResultDebugArtifact);
logger.info("SARIF result debug artifact ready for upload.");
}

logger.info("Preparing database logs debug artifact...");
const databaseDirectory = getCodeQLDatabasePath(config, language);
const logsDirectory = path.resolve(databaseDirectory, "log");
if (doesDirectoryExist(logsDirectory)) {
filesToUpload.push(...listFolder(logsDirectory));
logger.info("Database logs debug artifact ready for upload.");
}

// Multilanguage tracing: there are additional logs in the root of the cluster
logger.info("Preparing database cluster logs debug artifact...");
const multiLanguageTracingLogsDirectory = path.resolve(
config.dbLocation,
"log",
);
if (doesDirectoryExist(multiLanguageTracingLogsDirectory)) {
filesToUpload.push(...listFolder(multiLanguageTracingLogsDirectory));
logger.info("Database cluster logs debug artifact ready for upload.");
}

// Add database bundle
logger.info("Preparing database bundle debug artifact...");
const databaseBundle = await tryBundleDatabase(
config,
language,
logger,
);
if (databaseBundle) {
filesToUpload.push(databaseBundle);
logger.info("Database bundle debug artifact ready for upload.");
}
});
}
} catch (e) {
logger.warning(
`Failed to prepare debug artifacts. Reason: ${getErrorMessage(e)}`,
);
return;
}

try {
await withGroup("Uploading debug artifacts", async () =>
uploadDebugArtifacts(
filesToUpload,
config.dbLocation,
config.debugArtifactName,
),
);
} catch (e) {
logger.warning(
`Failed to upload debug artifacts. Reason: ${getErrorMessage(e)}`,
);
}
}

export async function uploadDebugArtifacts(
toUpload: string[],
rootDir: string,
@@ -46,64 +246,15 @@ export async function uploadDebugArtifacts(
}
}

try {
await artifact.create().uploadArtifact(
sanitizeArifactName(`${artifactName}${suffix}`),
toUpload.map((file) => path.normalize(file)),
path.normalize(rootDir),
{
continueOnError: true,
// ensure we don't keep the debug artifacts around for too long since they can be large.
retentionDays: 7,
},
);
} catch (e) {
// A failure to upload debug artifacts should not fail the entire action.
core.warning(`Failed to upload debug artifacts: ${e}`);
}
}

export async function uploadSarifDebugArtifact(
config: Config,
outputDir: string,
) {
if (!doesDirectoryExist(outputDir)) {
return;
}

let toUpload: string[] = [];
for (const lang of config.languages) {
const sarifFile = path.resolve(outputDir, `${lang}.sarif`);
if (fs.existsSync(sarifFile)) {
toUpload = toUpload.concat(sarifFile);
}
}
await uploadDebugArtifacts(toUpload, outputDir, config.debugArtifactName);
}

export async function uploadLogsDebugArtifact(config: Config) {
let toUpload: string[] = [];
for (const language of config.languages) {
const databaseDirectory = getCodeQLDatabasePath(config, language);
const logsDirectory = path.resolve(databaseDirectory, "log");
if (doesDirectoryExist(logsDirectory)) {
toUpload = toUpload.concat(listFolder(logsDirectory));
}
}

// Multilanguage tracing: there are additional logs in the root of the cluster
const multiLanguageTracingLogsDirectory = path.resolve(
config.dbLocation,
"log",
);
if (doesDirectoryExist(multiLanguageTracingLogsDirectory)) {
toUpload = toUpload.concat(listFolder(multiLanguageTracingLogsDirectory));
}

await uploadDebugArtifacts(
toUpload,
config.dbLocation,
config.debugArtifactName,
await artifact.create().uploadArtifact(
sanitizeArtifactName(`${artifactName}${suffix}`),
toUpload.map((file) => path.normalize(file)),
path.normalize(rootDir),
{
continueOnError: true,
// ensure we don't keep the debug artifacts around for too long since they can be large.
retentionDays: 7,
},
);
}

@@ -141,7 +292,6 @@ async function createDatabaseBundleCli(
config: Config,
language: Language,
): Promise<string> {
// Otherwise run `codeql database bundle` command.
const databaseBundlePath = await bundleDb(
config,
language,
@@ -150,31 +300,3 @@ async function createDatabaseBundleCli(
);
return databaseBundlePath;
}

export async function uploadDatabaseBundleDebugArtifact(
config: Config,
logger: Logger,
) {
for (const language of config.languages) {
try {
let databaseBundlePath: string;
if (!dbIsFinalized(config, language, logger)) {
databaseBundlePath = await createPartialDatabaseBundle(
config,
language,
);
} else {
databaseBundlePath = await createDatabaseBundleCli(config, language);
}
await uploadDebugArtifacts(
[databaseBundlePath],
config.dbLocation,
config.debugArtifactName,
);
} catch (error) {
core.info(
`Failed to upload database debug bundle for ${config.debugDatabaseName}-${language}: ${error}`,
);
}
}
}
8 changes: 4 additions & 4 deletions src/defaults.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"bundleVersion": "codeql-bundle-v2.18.4",
"cliVersion": "2.18.4",
"priorBundleVersion": "codeql-bundle-v2.18.3",
"priorCliVersion": "2.18.3"
"bundleVersion": "codeql-bundle-v2.19.0",
"cliVersion": "2.19.0",
"priorBundleVersion": "codeql-bundle-v2.18.4",
"priorCliVersion": "2.18.4"
}
3 changes: 3 additions & 0 deletions src/environment.ts
Original file line number Diff line number Diff line change
@@ -64,6 +64,9 @@ export enum EnvVar {

ODASA_TRACER_CONFIGURATION = "ODASA_TRACER_CONFIGURATION",

/** The value of the `output` input for the analyze action. */
SARIF_RESULTS_OUTPUT_DIR = "CODEQL_ACTION_SARIF_RESULTS_OUTPUT_DIR",

/**
* What percentage of the total amount of RAM over 8 GB that the Action should reserve for the
* system.
18 changes: 6 additions & 12 deletions src/init-action-post-helper.test.ts
Original file line number Diff line number Diff line change
@@ -35,22 +35,19 @@ test("post: init action with debug mode off", async (t) => {
packs: [],
} as unknown as configUtils.Config);

const uploadDatabaseBundleSpy = sinon.spy();
const uploadLogsSpy = sinon.spy();
const uploadAllAvailableDebugArtifactsSpy = sinon.spy();
const printDebugLogsSpy = sinon.spy();

await initActionPostHelper.run(
uploadDatabaseBundleSpy,
uploadLogsSpy,
uploadAllAvailableDebugArtifactsSpy,
printDebugLogsSpy,
createTestConfig({ debugMode: false }),
parseRepositoryNwo("github/codeql-action"),
createFeatures([]),
getRunnerLogger(true),
);

t.assert(uploadDatabaseBundleSpy.notCalled);
t.assert(uploadLogsSpy.notCalled);
t.assert(uploadAllAvailableDebugArtifactsSpy.notCalled);
t.assert(printDebugLogsSpy.notCalled);
});
});
@@ -60,22 +57,19 @@ test("post: init action with debug mode on", async (t) => {
process.env["GITHUB_REPOSITORY"] = "github/codeql-action-fake-repository";
process.env["RUNNER_TEMP"] = tmpDir;

const uploadDatabaseBundleSpy = sinon.spy();
const uploadLogsSpy = sinon.spy();
const uploadAllAvailableDebugArtifactsSpy = sinon.spy();
const printDebugLogsSpy = sinon.spy();

await initActionPostHelper.run(
uploadDatabaseBundleSpy,
uploadLogsSpy,
uploadAllAvailableDebugArtifactsSpy,
printDebugLogsSpy,
createTestConfig({ debugMode: true }),
parseRepositoryNwo("github/codeql-action"),
createFeatures([]),
getRunnerLogger(true),
);

t.assert(uploadDatabaseBundleSpy.called);
t.assert(uploadLogsSpy.called);
t.assert(uploadAllAvailableDebugArtifactsSpy.called);
t.assert(printDebugLogsSpy.called);
});
});
7 changes: 2 additions & 5 deletions src/init-action-post-helper.ts
Original file line number Diff line number Diff line change
@@ -158,11 +158,10 @@ export async function tryUploadSarifIfRunFailed(
}

export async function run(
uploadDatabaseBundleDebugArtifact: (
uploadAllAvailableDebugArtifacts: (
config: Config,
logger: Logger,
) => Promise<void>,
uploadLogsDebugArtifact: (config: Config) => Promise<void>,
printDebugLogs: (config: Config) => Promise<void>,
config: Config,
repositoryNwo: RepositoryNwo,
@@ -211,9 +210,7 @@ export async function run(
logger.info(
"Debug mode is on. Uploading available database bundles and logs as Actions debugging artifacts...",
);
await uploadDatabaseBundleDebugArtifact(config, logger);
await uploadLogsDebugArtifact(config);

await uploadAllAvailableDebugArtifacts(config, logger);
await printDebugLogs(config);
}

3 changes: 1 addition & 2 deletions src/init-action-post.ts
Original file line number Diff line number Diff line change
@@ -64,8 +64,7 @@ async function runWrapper() {
}

uploadFailedSarifResult = await initActionPostHelper.run(
debugArtifacts.uploadDatabaseBundleDebugArtifact,
debugArtifacts.uploadLogsDebugArtifact,
debugArtifacts.tryUploadAllAvailableDebugArtifacts,
printDebugLogs,
config,
repositoryNwo,
3 changes: 2 additions & 1 deletion src/init-action.ts
Original file line number Diff line number Diff line change
@@ -62,6 +62,7 @@ import {
wrapError,
checkActionVersion,
cloneObject,
getErrorMessage,
} from "./util";
import { validateWorkflow } from "./workflow";

@@ -700,7 +701,7 @@ async function runWrapper() {
try {
await run();
} catch (error) {
core.setFailed(`init action failed: ${wrapError(error).message}`);
core.setFailed(`init action failed: ${getErrorMessage(error)}`);
}
await checkForTimeout();
}
10 changes: 4 additions & 6 deletions src/init.ts
Original file line number Diff line number Diff line change
@@ -177,17 +177,15 @@ export function cleanupDatabaseClusterDirectory(
if (isSelfHostedRunner()) {
throw new util.ConfigurationError(
`${blurb} This can happen if another process is using the directory or the directory is owned by a different user. ` +
`Please clean up the directory manually and rerun the job. Details: ${
util.wrapError(e).message
}`,
`Please clean up the directory manually and rerun the job. Details: ${util.getErrorMessage(
e,
)}`,
);
} else {
throw new Error(
`${blurb} This shouldn't typically happen on hosted runners. ` +
"If you are using an advanced setup, please check your workflow, otherwise we " +
`recommend rerunning the job. Details: ${
util.wrapError(e).message
}`,
`recommend rerunning the job. Details: ${util.getErrorMessage(e)}`,
);
}
}
9 changes: 9 additions & 0 deletions src/logging.ts
Original file line number Diff line number Diff line change
@@ -31,3 +31,12 @@ export function getRunnerLogger(debugMode: boolean): Logger {
endGroup: () => undefined,
};
}

export function withGroup<T>(groupName: string, f: () => T): T {
core.startGroup(groupName);
try {
return f();
} finally {
core.endGroup();
}
}
7 changes: 4 additions & 3 deletions src/resolve-environment-action.ts
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ import {
checkDiskUsage,
checkForTimeout,
checkGitHubVersionInRange,
getErrorMessage,
wrapError,
} from "./util";

@@ -117,9 +118,9 @@ async function runWrapper() {
await run();
} catch (error) {
core.setFailed(
`${ActionName.ResolveEnvironment} action failed: ${
wrapError(error).message
}`,
`${ActionName.ResolveEnvironment} action failed: ${getErrorMessage(
error,
)}`,
);
}
await checkForTimeout();
4 changes: 2 additions & 2 deletions src/setup-codeql.test.ts
Original file line number Diff line number Diff line change
@@ -17,10 +17,10 @@ import {
setupTests,
} from "./testing-utils";
import {
getErrorMessage,
GitHubVariant,
initializeEnvironment,
withTmpDir,
wrapError,
} from "./util";

setupTests(test);
@@ -56,7 +56,7 @@ test("convert to semver", (t) => {
);
t.deepEqual(parsedVersion, expectedVersion);
} catch (e) {
t.fail(wrapError(e).message);
t.fail(getErrorMessage(e));
}
}
});
4 changes: 2 additions & 2 deletions src/start-proxy-action-post.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import * as core from "@actions/core";

import * as actionsUtil from "./actions-util";
import * as configUtils from "./config-utils";
import { wrapError } from "./util";
import { getErrorMessage } from "./util";

async function runWrapper() {
try {
@@ -18,7 +18,7 @@ async function runWrapper() {
}
} catch (error) {
core.setFailed(
`start-proxy post-action step failed: ${wrapError(error).message}`,
`start-proxy post-action step failed: ${getErrorMessage(error)}`,
);
}
const config = await configUtils.getConfig(
4 changes: 1 addition & 3 deletions src/start-proxy-action.ts
Original file line number Diff line number Diff line change
@@ -169,9 +169,7 @@ async function startProxy(
core.setOutput("proxy_port", port.toString());
core.setOutput("proxy_ca_certificate", config.ca.cert);
} catch (error) {
core.setFailed(
`start-proxy action failed: ${util.wrapError(error).message}`,
);
core.setFailed(`start-proxy action failed: ${util.getErrorMessage(error)}`);
}
}

8 changes: 4 additions & 4 deletions src/status-report.ts
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ import {
DiskUsage,
assertNever,
BuildMode,
wrapError,
getErrorMessage,
} from "./util";

export enum ActionName {
@@ -440,9 +440,9 @@ export async function sendStatusReport<S extends StatusReportBase>(
// something else has gone wrong and the request/response will be logged by octokit
// it's possible this is a transient error and we should continue scanning
core.warning(
`An unexpected error occurred when sending code scanning status report: ${
wrapError(e).message
}`,
`An unexpected error occurred when sending code scanning status report: ${getErrorMessage(
e,
)}`,
);
}
}
54 changes: 33 additions & 21 deletions src/testdata/with-invalid-uri.sarif
Original file line number Diff line number Diff line change
@@ -8,30 +8,42 @@
"name": "LGTM.com",
"organization": "Semmle",
"version": "1.24.0-SNAPSHOT",
"rules": []
"rules": [
{
"id": "js/unused-local-variable",
"shortDescription": {
"text": "Unused local variable"
},
"helpUri": "not a valid URI"
}
]
}
},
"results" : [ {
"ruleId" : "js/unused-local-variable",
"ruleIndex" : 0,
"message" : {
"text" : "Unused variable foo."
},
"locations" : [ {
"physicalLocation" : {
"artifactLocation" : {
"uri" : "not a valid URI",
"uriBaseId" : "%SRCROOT%",
"index" : 0
},
"region" : {
"startLine" : 2,
"startColumn" : 7,
"endColumn" : 10
"results": [
{
"ruleId": "js/unused-local-variable",
"ruleIndex": 0,
"message": {
"text": "Unused variable foo."
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "not a valid URI",
"uriBaseId": "%SRCROOT%",
"index": 0
},
"region": {
"startLine": 2,
"startColumn": 7,
"endColumn": 10
}
}
}
}
} ]
} ],
]
}
],
"columnKind": "utf16CodeUnits",
"properties": {
"semmle.formatSpecifier": "2.1.0",
9 changes: 7 additions & 2 deletions src/trap-caching.ts
Original file line number Diff line number Diff line change
@@ -11,7 +11,12 @@ import { DocUrl } from "./doc-url";
import { Feature, FeatureEnablement } from "./feature-flags";
import { Language } from "./languages";
import { Logger } from "./logging";
import { isHTTPError, tryGetFolderBytes, withTimeout, wrapError } from "./util";
import {
getErrorMessage,
isHTTPError,
tryGetFolderBytes,
withTimeout,
} from "./util";

// This constant should be bumped if we make a breaking change
// to how the CodeQL Action stores or retrieves the TRAP cache,
@@ -239,7 +244,7 @@ export async function cleanupTrapCaches(
} else {
logger.info(`Failed to cleanup TRAP caches, continuing. Details: ${e}`);
}
return { trap_cache_cleanup_error: wrapError(e).message };
return { trap_cache_cleanup_error: getErrorMessage(e) };
}
}

3 changes: 2 additions & 1 deletion src/upload-lib.test.ts
Original file line number Diff line number Diff line change
@@ -317,9 +317,10 @@ test("accept results with invalid artifactLocation.uri value", (t) => {
const sarifFile = `${__dirname}/../src/testdata/with-invalid-uri.sarif`;
uploadLib.validateSarifFileSchema(sarifFile, mockLogger);

t.deepEqual(loggedMessages.length, 2);
t.deepEqual(loggedMessages.length, 3);
t.deepEqual(
loggedMessages[1],
"Warning: 'not a valid URI' is not a valid URI in 'instance.runs[0].tool.driver.rules[0].helpUri'.",
"Warning: 'not a valid URI' is not a valid URI in 'instance.runs[0].results[0].locations[0].physicalLocation.artifactLocation.uri'.",
);
});
21 changes: 15 additions & 6 deletions src/upload-lib.ts
Original file line number Diff line number Diff line change
@@ -24,12 +24,12 @@ import { ToolsFeature } from "./tools-features";
import * as util from "./util";
import {
ConfigurationError,
getErrorMessage,
getRequiredEnvParam,
GitHubVariant,
GitHubVersion,
SarifFile,
SarifRun,
wrapError,
} from "./util";

const GENERIC_403_MSG =
@@ -440,7 +440,7 @@ export function validateSarifFileSchema(sarifFilePath: string, logger: Logger) {
sarif = JSON.parse(fs.readFileSync(sarifFilePath, "utf8")) as SarifFile;
} catch (e) {
throw new InvalidSarifUploadError(
`Invalid SARIF. JSON syntax error: ${wrapError(e).message}`,
`Invalid SARIF. JSON syntax error: ${getErrorMessage(e)}`,
);
}
// eslint-disable-next-line @typescript-eslint/no-require-imports
@@ -449,11 +449,20 @@ export function validateSarifFileSchema(sarifFilePath: string, logger: Logger) {
const result = new jsonschema.Validator().validate(sarif, schema);
// Filter errors related to invalid URIs in the artifactLocation field as this
// is a breaking change. See https://github.com/github/codeql-action/issues/1703
const errors = (result.errors || []).filter(
(err) => err.argument !== "uri-reference",
const warningAttributes = ["uri-reference", "uri"];
const errors = (result.errors ?? []).filter(
(err) =>
!(
err.name === "format" &&
typeof err.argument === "string" &&
warningAttributes.includes(err.argument)
),
);
const warnings = (result.errors || []).filter(
(err) => err.argument === "uri-reference",
const warnings = (result.errors ?? []).filter(
(err) =>
err.name === "format" &&
typeof err.argument === "string" &&
warningAttributes.includes(err.argument),
);

for (const warning of warnings) {
49 changes: 0 additions & 49 deletions src/upload-sarif-action-post-helper.ts

This file was deleted.

18 changes: 12 additions & 6 deletions src/upload-sarif-action-post.ts
Original file line number Diff line number Diff line change
@@ -6,17 +6,23 @@
import * as core from "@actions/core";

import * as debugArtifacts from "./debug-artifacts";
import * as uploadSarifActionPostHelper from "./upload-sarif-action-post-helper";
import { wrapError } from "./util";
import { EnvVar } from "./environment";
import { getActionsLogger, withGroup } from "./logging";
import { getErrorMessage } from "./util";

async function runWrapper() {
try {
await uploadSarifActionPostHelper.uploadArtifacts(
debugArtifacts.uploadDebugArtifacts,
);
const logger = getActionsLogger();
// Upload SARIF artifacts if we determine that this is a third-party analysis run.
// For first-party runs, this artifact will be uploaded in the `analyze-post` step.
if (process.env[EnvVar.INIT_ACTION_HAS_RUN] !== "true") {
await withGroup("Uploading combined SARIF debug artifact", () =>
debugArtifacts.uploadCombinedSarifArtifacts(logger),
);
}
} catch (error) {
core.setFailed(
`upload-sarif post-action step failed: ${wrapError(error).message}`,
`upload-sarif post-action step failed: ${getErrorMessage(error)}`,
);
}
}
3 changes: 2 additions & 1 deletion src/upload-sarif-action.ts
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ import {
ConfigurationError,
checkActionVersion,
checkDiskUsage,
getErrorMessage,
getRequiredEnvParam,
initializeEnvironment,
isInTestMode,
@@ -133,7 +134,7 @@ async function runWrapper() {
await run();
} catch (error) {
core.setFailed(
`codeql/upload-sarif action failed: ${wrapError(error).message}`,
`codeql/upload-sarif action failed: ${getErrorMessage(error)}`,
);
}
}
8 changes: 7 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
@@ -998,8 +998,14 @@ export function wrapError(error: unknown): Error {
return error instanceof Error ? error : new Error(String(error));
}

/**
* Returns an appropriate message for the error.
*
* If the error is an `Error` instance, this returns the error message without
* an `Error: ` prefix.
*/
export function getErrorMessage(error: unknown): string {
return error instanceof Error ? error.toString() : String(error);
return error instanceof Error ? error.message : String(error);
}

export function prettyPrintPack(pack: Pack) {
2 changes: 1 addition & 1 deletion upload-sarif/action.yml
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ inputs:
description: "The sha of the HEAD of the ref where results will be uploaded. If not provided, the Action will use the GITHUB_SHA environment variable. If provided, the ref input must be provided as well. This input is ignored for pull requests from forks."
required: false
token:
description: "GitHub token to use for authenticating with this instance of GitHub. The token needs the `security-events: write` permission."
description: "GitHub token to use for authenticating with this instance of GitHub. The token must be the built-in GitHub Actions token, and the workflow must have the `security-events: write` permission. Most of the time it is advisable to avoid specifying this input so that the workflow falls back to using the default value."
required: false
default: ${{ github.token }}
matrix: