Skip to content

Commit a5ca7a6

Browse files
authored
Merge pull request #328 from advanced-security/knewbury01/change-code-scanning-workflow-configfile
Improve code scanning workflow
2 parents 79fe955 + 7f5e235 commit a5ca7a6

File tree

3 files changed

+72
-74
lines changed

3 files changed

+72
-74
lines changed

.github/codeql/codeql-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,11 @@ queries:
66
- uses: ./javascript/frameworks/cap/src/codeql-suites/javascript-security-extended.qls
77
- uses: ./javascript/frameworks/xsjs/src/codeql-suites/javascript-security-extended.qls
88

9+
packs:
10+
javascript:
11+
- advanced-security/javascript-sap-ui5-models
12+
- advanced-security/javascript-sap-cap-models
13+
- advanced-security/javascript-sap-xsjs-models
14+
915
paths-ignore:
1016
- "**/frameworks/*/test/models"

.github/workflows/code_scanning.yml

Lines changed: 65 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ name: "Code Scanning"
22

33
on:
44
push:
5-
branches: [ "main" ]
5+
branches: ["main"]
66
pull_request:
77
# The branches below must be a subset of the branches above
8-
branches: [ "main" ]
8+
branches: ["main"]
99
schedule:
10-
- cron: '39 12 * * 2'
10+
- cron: "39 12 * * 2"
1111
workflow_dispatch:
1212

1313
permissions:
@@ -19,88 +19,80 @@ env:
1919
jobs:
2020
analyze-javascript:
2121
name: Analyze
22-
runs-on: 'ubuntu-latest'
22+
runs-on: "ubuntu-latest"
2323
permissions:
2424
actions: read
2525
contents: read
2626
security-events: write
2727

2828
steps:
29-
- name: Checkout repository
30-
uses: actions/checkout@v6
29+
- name: Checkout repository
30+
uses: actions/checkout@v6
3131

32-
- name: Prepare local CodeQL model packs
33-
run: |
34-
mkdir -p .github/codeql/extensions
35-
for ext in $(find . -name 'qlpack.yml' -exec fgrep -l dataExtensions {} \;); do
36-
dir=$(dirname $ext)
37-
echo "Moving $ext to .github/codeql/extensions/$dir"
38-
mkdir -p .github/codeql/extensions/$dir
39-
mv $dir .github/codeql/extensions/$dir
40-
done
32+
- name: Extract CodeQL bundle version from qlt.conf.json
33+
run: |
34+
echo "BUNDLE_VERSION=$(jq .CodeQLCLIBundle qlt.conf.json -r)" >> $GITHUB_ENV
4135
42-
- name: Extract CodeQL bundle version from qlt.conf.json
43-
run: |
44-
echo "BUNDLE_VERSION=$(jq .CodeQLCLIBundle qlt.conf.json -r)" >> $GITHUB_ENV
36+
- name: Initialize CodeQL
37+
id: initialize-codeql
38+
uses: github/codeql-action/init@v4
39+
env:
40+
# Add our custom extractor to the CodeQL search path
41+
CODEQL_ACTION_EXTRA_OPTIONS: '{"database":{"init":["--search-path","${{ github.workspace }}/extractors:${{ github.workspace }}"]}}'
42+
with:
43+
languages: javascript
44+
config-file: ./.github/codeql/codeql-config.yaml
45+
db-location: ${{ runner.temp }}/codeql-database
46+
tools: https://github.com/github/codeql-action/releases/download/${{env.BUNDLE_VERSION}}/codeql-bundle-linux64.tar.gz
47+
debug: true
4548

46-
- name: Initialize CodeQL
47-
id: initialize-codeql
48-
uses: github/codeql-action/init@v4
49-
env:
50-
# Add our custom extractor to the CodeQL search path
51-
CODEQL_ACTION_EXTRA_OPTIONS: '{"database":{"init":["--search-path","${{ github.workspace }}/extractors"]}}'
52-
with:
53-
languages: javascript
54-
config-file: ./.github/codeql/codeql-config.yaml
55-
db-location: ${{ runner.temp }}/codeql-database
56-
tools: https://github.com/github/codeql-action/releases/download/${{env.BUNDLE_VERSION}}/codeql-bundle-linux64.tar.gz
57-
debug: true
49+
- name: Run CDS extractor
50+
shell: bash
51+
run: |
52+
export CODEQL_DIST="$(dirname "${{ steps.initialize-codeql.outputs.codeql-path }}")"
53+
export CODEQL_EXTRACTOR_JAVASCRIPT_WIP_DATABASE="${{ runner.temp }}/codeql-database/javascript"
54+
${{ github.workspace }}/scripts/compile-cds.sh
5855
59-
- name: Run CDS extractor
60-
shell: bash
61-
run: |
62-
export CODEQL_DIST="$(dirname "${{ steps.initialize-codeql.outputs.codeql-path }}")"
63-
export CODEQL_EXTRACTOR_JAVASCRIPT_WIP_DATABASE="${{ runner.temp }}/codeql-database/javascript"
64-
${{ github.workspace }}/scripts/compile-cds.sh
56+
- name: Perform CodeQL Analysis
57+
id: analyze
58+
uses: github/codeql-action/analyze@v4
59+
env:
60+
LGTM_INDEX_XML_MODE: all
61+
LGTM_INDEX_FILETYPES: ".json:JSON"
62+
# Add our CodeQL workspace to the path to search for packs to then resolve the MaD locally
63+
CODEQL_ACTION_EXTRA_OPTIONS: '{"database":{"run-queries":["--additional-packs","${{ github.workspace }}/javascript/frameworks/xsjs/ext:${{ github.workspace }}/javascript/frameworks/cap/ext:${{ github.workspace }}/javascript/frameworks/ui5/ext"],"interpret-results":["--additional-packs","${{ github.workspace }}/javascript/frameworks/xsjs/ext:${{ github.workspace }}/javascript/frameworks/cap/ext:${{ github.workspace }}/javascript/frameworks/ui5/ext"]}}'
6564

66-
- name: Perform CodeQL Analysis
67-
id: analyze
68-
uses: github/codeql-action/analyze@v4
69-
env:
70-
LGTM_INDEX_XML_MODE: all
71-
LGTM_INDEX_FILETYPES: ".json:JSON"
65+
- name: Setup Python
66+
uses: actions/setup-python@v5
67+
with:
68+
python-version: "3.10"
7269

73-
- name: Setup Python
74-
uses: actions/setup-python@v5
75-
with:
76-
python-version: '3.10'
70+
- uses: actions/cache@v4
71+
with:
72+
path: ~/.cache/pip
73+
key: ${{ runner.os }}-pip
7774

78-
- uses: actions/cache@v4
79-
with:
80-
path: ~/.cache/pip
81-
key: ${{ runner.os }}-pip
75+
- name: Validate results
76+
continue-on-error: true
77+
id: validate
78+
run: |
79+
pip install sarif-tools
80+
sarif --version
81+
sarif diff ${{ steps.analyze.outputs.sarif-output }} .github/workflows/javascript.sarif.expected -o sarif-diff.json
82+
cat sarif-diff.json
83+
! grep -q "[1-9]" sarif-diff.json
8284
83-
- name: Validate results
84-
continue-on-error: true
85-
id: validate
86-
run: |
87-
pip install sarif-tools
88-
sarif --version
89-
sarif diff ${{ steps.analyze.outputs.sarif-output }} .github/workflows/javascript.sarif.expected -o sarif-diff.json
90-
cat sarif-diff.json
91-
! grep -q "[1-9]" sarif-diff.json
85+
- name: Upload sarif change
86+
if: steps.validate.outcome != 'success'
87+
uses: actions/upload-artifact@v6
88+
with:
89+
name: sarif
90+
path: |
91+
sarif-diff.json
92+
${{ steps.analyze.outputs.sarif-output }}
9293
93-
- name: Upload sarif change
94-
if: steps.validate.outcome != 'success'
95-
uses: actions/upload-artifact@v6
96-
with:
97-
name: sarif
98-
path: |
99-
sarif-diff.json
100-
${{ steps.analyze.outputs.sarif-output }}
101-
102-
- name: Unexpected Code Scanning results
103-
if: steps.validate.outcome != 'success'
104-
run: |
105-
cat sarif-diff.json
106-
echo "::error::Unexpected Code Scanning results!" && exit 1
94+
- name: Unexpected Code Scanning results
95+
if: steps.validate.outcome != 'success'
96+
run: |
97+
cat sarif-diff.json
98+
echo "::error::Unexpected Code Scanning results!" && exit 1

.github/workflows/javascript.sarif.expected

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)