52 lines
No EOL
2.4 KiB
YAML
52 lines
No EOL
2.4 KiB
YAML
name: "Diagnostic export"
|
|
description: "Tests that a manually added diagnostic is exported to SARIF."
|
|
versions: ["latest", "nightly-latest"]
|
|
env:
|
|
CODEQL_ACTION_EXPORT_DIAGNOSTICS: true
|
|
steps:
|
|
- uses: ./../action/init
|
|
id: init
|
|
with:
|
|
languages: javascript
|
|
queries: security-extended
|
|
tools: ${{ steps.prepare-test.outputs.tools-url }}
|
|
- name: Manually add a diagnostic
|
|
shell: bash
|
|
env:
|
|
CODEQL_PATH: ${{ steps.init.outputs.codeql-path }}
|
|
run: |
|
|
"$CODEQL_PATH" database add-diagnostic "$RUNNER_TEMP/codeql_databases/javascript" --plaintext-message="Plaintext message" --source-id="lang/diagnostics/example" --source-name="Diagnostic name"
|
|
- uses: ./../action/analyze
|
|
with:
|
|
output: "${{ runner.temp }}/results"
|
|
upload-database: false
|
|
- name: Upload SARIF
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: diagnostics-export-${{ matrix.os }}-${{ matrix.version }}.sarif.json
|
|
path: "${{ runner.temp }}/results/javascript.sarif"
|
|
retention-days: 7
|
|
- name: Check diagnostics appear in SARIF
|
|
uses: actions/github-script@v6
|
|
env:
|
|
SARIF_PATH: "${{ runner.temp }}/results/javascript.sarif"
|
|
with:
|
|
script: |
|
|
const fs = require('fs');
|
|
|
|
const sarif = JSON.parse(fs.readFileSync(process.env['SARIF_PATH'], 'utf8'));
|
|
const run = sarif.runs[0];
|
|
|
|
const toolExecutionNotifications = run.invocations[0].toolExecutionNotifications;
|
|
const diagnosticToolExecutionNotification = toolExecutionNotifications.filter(n => n.descriptor.id === 'lang/diagnostics/example' && n.message.text === 'Plaintext message');
|
|
if (diagnosticToolExecutionNotification.length !== 1) {
|
|
core.setFailed(`Expected exactly 1 entry for this diagnostic in the 'runs[].invocations[].toolExecutionNotifications[]' SARIF property, found ${diagnosticToolExecutionNotification.length}`);
|
|
}
|
|
|
|
const notifications = run.tool.driver.notifications;
|
|
const diagnosticNotification = notifications.filter(n => n.id === 'lang/diagnostics/example' && n.name === 'lang/diagnostics/example' && n.fullDescription.text && 'Diagnostic name');
|
|
if (diagnosticNotification.length !== 1) {
|
|
core.setFailed(`Expected exactly 1 entry for this diagnostic in the 'runs[].tool.driver.notifications[]' SARIF property, found ${diagnosticNotification.length}`);
|
|
}
|
|
|
|
core.info('Finished diagnostic export test'); |