Add a CodeQL extractor for SAP CAP cds files #907
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "Code Scanning" | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| # The branches below must be a subset of the branches above | |
| branches: [ "main" ] | |
| schedule: | |
| - cron: '39 12 * * 2' | |
| workflow_dispatch: | |
| env: | |
| LGTM_INDEX_XML_MODE: all | |
| LGTM_INDEX_FILETYPES: ".json:JSON\n.cds:JSON" | |
| jobs: | |
| analyze-javascript: | |
| name: Analyze | |
| runs-on: 'ubuntu-latest' | |
| permissions: | |
| actions: read | |
| contents: read | |
| security-events: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Prepare local CodeQL model packs | |
| run: | | |
| mkdir -p .github/codeql/extensions | |
| for ext in $(find . -name 'qlpack.yml' -exec fgrep -l dataExtensions {} \;); do | |
| dir=$(dirname $ext) | |
| echo "Moving $ext to .github/codeql/extensions/$dir" | |
| mkdir -p .github/codeql/extensions/$dir | |
| mv $dir .github/codeql/extensions/$dir | |
| done | |
| - name: Extract CodeQL bundle version from qlt.conf.json | |
| run: | | |
| echo "BUNDLE_VERSION=$(jq .CodeQLCLIBundle qlt.conf.json -r)" >> $GITHUB_ENV | |
| - name: Initialize CodeQL | |
| uses: github/codeql-action/init@v3 | |
| env: | |
| # Add our custom extractor to the CodeQL search path | |
| CODEQL_ACTION_EXTRA_OPTIONS: '{"database":{"init":["--search-path","${{ github.workspace }}/extractors"]}}' | |
| with: | |
| languages: javascript | |
| config-file: ./.github/codeql/codeql-config.yaml | |
| tools: https://github.com/github/codeql-action/releases/download/${{env.BUNDLE_VERSION}}/codeql-bundle-linux64.tar.gz | |
| debug: true | |
| - name: Run CDS extractor | |
| shell: bash | |
| run: | | |
| ${{ github.workspace }}/scripts/compile-cds.sh | |
| - name: Perform CodeQL Analysis | |
| id: analyze | |
| uses: github/codeql-action/analyze@v3 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/pip | |
| key: ${{ runner.os }}-pip | |
| - name: Validate results | |
| continue-on-error: true | |
| id: validate | |
| run: | | |
| pip install sarif-tools | |
| sarif --version | |
| sarif diff ${{ steps.analyze.outputs.sarif-output }} .github/workflows/javascript.sarif.expected -o sarif-diff.json | |
| cat sarif-diff.json | |
| ! grep -q "[1-9]" sarif-diff.json | |
| - name: Upload sarif change | |
| if: steps.validate.outcome != 'success' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: sarif | |
| path: | | |
| sarif-diff.json | |
| ${{ steps.analyze.outputs.sarif-output }} | |
| - name: Unexpected Code Scanning results | |
| if: steps.validate.outcome != 'success' | |
| run: | | |
| cat sarif-diff.json | |
| echo "::error::Unexpected Code Scanning results!" && exit 1 |