Skip to content

Commit b114377

Browse files
authored
Merge branch 'main' into mbaluda/xsrf-tests
2 parents 39d02f7 + fd6beae commit b114377

File tree

73 files changed

+5096
-3428
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+5096
-3428
lines changed

.github/workflows/release-codeql.yml

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,6 @@ jobs:
4343
release_name: ${{ steps.version.outputs.release_name }}
4444
version: ${{ steps.version.outputs.version }}
4545

46-
env:
47-
PUBLISHABLE_PACKS_LIST: |
48-
javascript/frameworks/cap/src
49-
javascript/frameworks/cap/ext
50-
javascript/frameworks/cap/lib
51-
javascript/frameworks/ui5/src
52-
javascript/frameworks/ui5/ext
53-
javascript/frameworks/ui5/lib
54-
javascript/frameworks/xsjs/src
55-
javascript/frameworks/xsjs/ext
56-
javascript/frameworks/xsjs/lib
57-
javascript/heuristic-models/ext
58-
5946
steps:
6047
- name: CodeQL - Validate and parse version
6148
id: version
@@ -91,9 +78,7 @@ jobs:
9178
9279
- name: CodeQL - Install pack dependencies
9380
shell: bash
94-
run: |
95-
chmod +x ./scripts/install-packs.sh
96-
./scripts/install-packs.sh
81+
run: ./scripts/install-packs.sh
9782

9883
- name: CodeQL - Validate version consistency
9984
run: |
@@ -106,50 +91,14 @@ jobs:
10691
if: inputs.publish_codeql_packs
10792
env:
10893
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
109-
run: |
110-
# Read the shared pack list from the job-level environment variable.
111-
mapfile -t PUBLISHABLE_PACKS <<< "${PUBLISHABLE_PACKS_LIST}"
112-
113-
echo "Publishing CodeQL packs..."
114-
for pack_dir in "${PUBLISHABLE_PACKS[@]}"; do
115-
if [ -d "${pack_dir}" ]; then
116-
pack_name=$(grep -m1 "^name:" "${pack_dir}/qlpack.yml" | awk '{print $2}')
117-
echo "📦 Publishing ${pack_name} from ${pack_dir}..."
118-
echo "${GITHUB_TOKEN}" | codeql pack publish --github-auth-stdin --threads=-1 -- "${pack_dir}"
119-
echo "✅ Published ${pack_name}"
120-
else
121-
echo "⚠️ Skipping: ${pack_dir} not found"
122-
fi
123-
done
94+
run: ./scripts/publish-packs.sh "${{ steps.version.outputs.release_name }}"
12495

12596
- name: CodeQL - Skip pack publishing
12697
if: '!inputs.publish_codeql_packs'
12798
run: echo "⏭️ CodeQL pack publishing disabled via workflow input"
12899

129100
- name: CodeQL - Bundle CodeQL packs
130-
run: |
131-
mkdir -p dist-packs
132-
133-
# Bundle all publishable packs
134-
# Read the pack list from the environment into a Bash array.
135-
# Each line in PUBLISHABLE_PACKS_LIST becomes one element.
136-
mapfile -t PUBLISHABLE_PACKS <<< "${PUBLISHABLE_PACKS_LIST}"
137-
138-
echo "Bundling CodeQL packs..."
139-
for pack_dir in "${PUBLISHABLE_PACKS[@]}"; do
140-
if [ -d "${pack_dir}" ]; then
141-
pack_name=$(grep -m1 "^name:" "${pack_dir}/qlpack.yml" | awk '{print $2}')
142-
# Convert pack name to filename: advanced-security/foo -> foo
143-
bundle_name="${pack_name#advanced-security/}"
144-
output="dist-packs/${bundle_name}.tar.gz"
145-
echo "📦 Bundling ${pack_name} -> ${output}..."
146-
codeql pack bundle --threads=-1 --output="${output}" -- "${pack_dir}"
147-
echo "✅ Bundled ${bundle_name}"
148-
fi
149-
done
150-
echo ""
151-
echo "Bundled packs:"
152-
ls -lh dist-packs/
101+
run: ./scripts/bundle-packs.sh --output-dir dist-packs
153102

154103
- name: CodeQL - Upload pack artifacts
155104
uses: actions/upload-artifact@v6

.github/workflows/release.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ on:
2424
permissions:
2525
contents: read
2626

27+
concurrency:
28+
group: release-${{ github.event.inputs.version || github.ref_name }}
29+
cancel-in-progress: true
30+
2731
jobs:
2832
# ─────────────────────────────────────────────────────────────────────────────
2933
# Step 1: Determine the release version

.github/workflows/update-codeql.yml

Lines changed: 104 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ jobs:
1515
#
1616
# Compares the current CodeQL CLI version in qlt.conf.json against the latest
1717
# release from github/codeql-cli-binaries. If a newer version is available,
18-
# downstream jobs orchestrate a full release using the same child workflows
19-
# as release.yml, guarded by environment approval gates.
18+
# downstream jobs orchestrate the update and PR creation.
2019
# ─────────────────────────────────────────────────────────────────────────────
2120
detect-update:
2221
name: Detect CodeQL CLI Update
@@ -38,8 +37,21 @@ jobs:
3837
GH_TOKEN: ${{ github.token }}
3938
run: |
4039
echo "Checking latest CodeQL CLI version..."
40+
41+
# Read current version from qlt.conf.json
4142
current_version=$(jq -r .CodeQLCLI qlt.conf.json)
43+
44+
# Get latest release from codeql-cli-binaries
4245
latest_tag=$(gh release list --repo github/codeql-cli-binaries --json 'tagName,isLatest' --jq '.[] | select(.isLatest == true) | .tagName')
46+
47+
# Validate that we found a latest release
48+
if [ -z "${latest_tag}" ]; then
49+
echo "❌ Error: Could not determine latest CodeQL CLI version from github/codeql-cli-binaries" >&2
50+
echo "No release marked as 'latest' was found. This may indicate an API issue or repository change." >&2
51+
echo "update_needed=false" >> $GITHUB_OUTPUT
52+
exit 1
53+
fi
54+
4355
latest_clean="${latest_tag#v}"
4456
4557
echo "Current CodeQL CLI version: ${current_version}"
@@ -63,91 +75,115 @@ jobs:
6375
if [ "${{ steps.check-version.outputs.update_needed }}" == "true" ]; then
6476
echo "✅ Update available: ${{ steps.check-version.outputs.current_version }} → ${{ steps.check-version.outputs.latest_version }}" >> $GITHUB_STEP_SUMMARY
6577
echo "" >> $GITHUB_STEP_SUMMARY
66-
echo "Initiating release pipeline for \`v${{ steps.check-version.outputs.latest_version }}\`..." >> $GITHUB_STEP_SUMMARY
78+
echo "Initiating update pipeline for \`${{ steps.check-version.outputs.version }}\`..." >> $GITHUB_STEP_SUMMARY
6779
else
68-
echo "ℹ️ CodeQL CLI is already up-to-date. No release needed." >> $GITHUB_STEP_SUMMARY
80+
echo "ℹ️ CodeQL CLI is already up-to-date. No changes needed." >> $GITHUB_STEP_SUMMARY
6981
fi
7082
7183
# ─────────────────────────────────────────────────────────────────────────────
72-
# Step 2: Create release tag
84+
# Step 2: Update version, test, and create PR
7385
#
74-
# Calls the same release-tag workflow used by release.yml. This ensures the
75-
# version update, CodeQL installation, pack lock upgrade, unit tests, and tag
76-
# creation all follow the same validated process.
86+
# Updates all version-bearing files (qlt.conf.json, qlpack.yml files),
87+
# installs CodeQL, upgrades pack lock files, compiles CDS files, runs unit
88+
# tests, and creates a pull request with the changes.
7789
#
78-
# The release-tag environment approval gate provides human-in-the-loop review
79-
# before any changes are committed.
90+
# This does NOT trigger the release pipeline. Merging the PR and creating a
91+
# release tag is a separate, human-initiated step via release.yml.
8092
# ─────────────────────────────────────────────────────────────────────────────
81-
ensure-tag:
82-
name: Ensure Release Tag
93+
create-pr:
94+
name: Create Update Pull Request
8395
needs: detect-update
8496
if: needs.detect-update.outputs.update_needed == 'true'
85-
permissions:
86-
contents: write
87-
uses: ./.github/workflows/release-tag.yml
88-
with:
89-
version: ${{ needs.detect-update.outputs.version }}
90-
91-
# ─────────────────────────────────────────────────────────────────────────────
92-
# Step 3: Publish and bundle CodeQL packs
93-
#
94-
# Calls the same release-codeql workflow used by release.yml. Publishes packs
95-
# to GHCR and bundles them as artifacts for the GitHub Release.
96-
# ─────────────────────────────────────────────────────────────────────────────
97-
publish-codeql:
98-
name: Publish CodeQL Packs
99-
needs: [detect-update, ensure-tag]
100-
if: needs.detect-update.outputs.update_needed == 'true'
101-
permissions:
102-
contents: read
103-
packages: write
104-
uses: ./.github/workflows/release-codeql.yml
105-
with:
106-
publish_codeql_packs: true
107-
version: ${{ needs.detect-update.outputs.version }}
108-
109-
# ─────────────────────────────────────────────────────────────────────────────
110-
# Step 4: Create GitHub Release
111-
#
112-
# Downloads the CodeQL pack bundles and creates the GitHub Release with
113-
# auto-generated release notes and attached pack artifacts.
114-
# ─────────────────────────────────────────────────────────────────────────────
115-
create-release:
116-
name: Create GitHub Release
117-
needs: [detect-update, ensure-tag, publish-codeql]
118-
if: >-
119-
always() && !failure() && !cancelled()
120-
&& needs.detect-update.outputs.update_needed == 'true'
12197
runs-on: ubuntu-latest
12298

12399
permissions:
124100
contents: write
101+
pull-requests: write
125102

126103
steps:
127-
- name: Release - Download CodeQL pack artifacts
128-
uses: actions/download-artifact@v7
129-
with:
130-
name: codeql-pack-bundles-${{ needs.detect-update.outputs.version }}
131-
path: dist-packs
104+
- name: Update - Checkout repository
105+
uses: actions/checkout@v6
106+
107+
- name: Update - Update version in all files
108+
run: |
109+
LATEST="${{ needs.detect-update.outputs.latest_version }}"
110+
echo "Updating all version-bearing files to ${LATEST}..."
111+
./scripts/update-release-version.sh "${LATEST}"
132112
133-
- name: Release - Create GitHub Release
134-
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2.5.0
113+
- name: Update - Install CodeQL via GitHub CLI
114+
env:
115+
GH_TOKEN: ${{ github.token }}
116+
shell: bash
117+
run: |
118+
CODEQL_VERSION="${{ needs.detect-update.outputs.latest_version }}"
119+
echo "Installing CodeQL CLI ${CODEQL_VERSION} via gh-codeql..."
120+
gh extension install github/gh-codeql
121+
gh codeql set-version "${CODEQL_VERSION}"
122+
STUB_DIR="$HOME/.local/bin"
123+
mkdir -p "${STUB_DIR}"
124+
gh codeql install-stub "${STUB_DIR}/"
125+
echo "${STUB_DIR}" >> "$GITHUB_PATH"
126+
export PATH="${STUB_DIR}:${PATH}"
127+
echo "CodeQL version: $(codeql version --format=terse)"
128+
129+
- name: Update - Upgrade CodeQL pack lock files
130+
run: ./scripts/upgrade-packs.sh
131+
132+
- name: Update - Setup Node.js for CDS compilation
133+
uses: actions/setup-node@v6
135134
with:
136-
files: |
137-
dist-packs/*.tar.gz
138-
generate_release_notes: true
139-
tag_name: ${{ needs.detect-update.outputs.version }}
135+
node-version: '20'
136+
cache: 'npm'
137+
cache-dependency-path: 'extractors/cds/tools/package-lock.json'
140138

141-
- name: Release - Summary
139+
- name: Update - Compile CAP CDS files
140+
run: ./extractors/cds/tools/workflow/cds-compilation-for-actions.sh
141+
142+
- name: Update - Run CodeQL unit tests
143+
env:
144+
LGTM_INDEX_XML_MODE: all
145+
LGTM_INDEX_FILETYPES: ".json:JSON\n.cds:JSON"
146+
shell: bash
147+
run: |
148+
echo "Running CodeQL unit tests to validate update..."
149+
codeql test run \
150+
--threads=0 \
151+
--strict-test-discovery \
152+
--additional-packs="${GITHUB_WORKSPACE}" \
153+
-- javascript/
154+
155+
- name: Update - Create Pull Request
156+
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0
157+
with:
158+
title: 'Upgrade CodeQL CLI dependency to ${{ needs.detect-update.outputs.version }}'
159+
body: |
160+
This PR upgrades the CodeQL CLI version to ${{ needs.detect-update.outputs.version }}.
161+
162+
**Changes made:**
163+
- Updated `qlt.conf.json` (CodeQLCLI, CodeQLStandardLibrary, CodeQLCLIBundle) to `${{ needs.detect-update.outputs.latest_version }}`
164+
- Updated all version-bearing qlpack.yml files to `${{ needs.detect-update.outputs.latest_version }}`
165+
- Upgraded CodeQL pack lock files
166+
- Compiled CAP CDS files
167+
- CodeQL unit tests passed ✅
168+
169+
**To complete the release**, merge this PR and then trigger the release workflow
170+
via `workflow_dispatch` on `release.yml` with version `${{ needs.detect-update.outputs.version }}`.
171+
commit-message: 'Upgrade CodeQL CLI dependency to ${{ needs.detect-update.outputs.version }}'
172+
delete-branch: true
173+
branch: 'codeql/upgrade-to-${{ needs.detect-update.outputs.version }}'
174+
175+
- name: Update - Summary
142176
run: |
143177
VERSION="${{ needs.detect-update.outputs.version }}"
144-
RELEASE_NAME="${{ needs.detect-update.outputs.latest_version }}"
145-
echo "## Automated Release Summary" >> $GITHUB_STEP_SUMMARY
178+
CURRENT="${{ needs.detect-update.outputs.current_version }}"
179+
LATEST="${{ needs.detect-update.outputs.latest_version }}"
180+
echo "## CodeQL CLI Update Summary" >> $GITHUB_STEP_SUMMARY
181+
echo "" >> $GITHUB_STEP_SUMMARY
182+
echo "Triggered by CodeQL CLI update: ${CURRENT} → ${LATEST}" >> $GITHUB_STEP_SUMMARY
146183
echo "" >> $GITHUB_STEP_SUMMARY
147-
echo "Triggered by CodeQL CLI update: ${{ needs.detect-update.outputs.current_version }} → ${RELEASE_NAME}" >> $GITHUB_STEP_SUMMARY
184+
echo "| Property | Old Value | New Value |" >> $GITHUB_STEP_SUMMARY
185+
echo "| -------- | --------- | --------- |" >> $GITHUB_STEP_SUMMARY
186+
echo "| qlt.conf.json CodeQLCLI | ${CURRENT} | ${LATEST} |" >> $GITHUB_STEP_SUMMARY
187+
echo "| qlpack.yml versions | ${CURRENT} | ${LATEST} |" >> $GITHUB_STEP_SUMMARY
148188
echo "" >> $GITHUB_STEP_SUMMARY
149-
echo "| Step | Status |" >> $GITHUB_STEP_SUMMARY
150-
echo "| ---- | ------ |" >> $GITHUB_STEP_SUMMARY
151-
echo "| Tag | ✅ ${VERSION} |" >> $GITHUB_STEP_SUMMARY
152-
echo "| CodeQL pack publish | ✅ Published to GHCR |" >> $GITHUB_STEP_SUMMARY
153-
echo "| GitHub Release | ✅ Created |" >> $GITHUB_STEP_SUMMARY
189+
echo "A pull request has been created with these changes." >> $GITHUB_STEP_SUMMARY

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ This repository contains [CodeQL](https://codeql.github.com/) models and queries
1212

1313
- [advanced-security/javascript-sap-cap-queries](https://github.com/advanced-security/codeql-sap-js/pkgs/container/javascript-sap-cap-queries)
1414
- [advanced-security/javascript-sap-ui5-queries](https://github.com/advanced-security/codeql-sap-js/pkgs/container/javascript-sap-ui5-queries)
15-
- [advanced-security/javascript-sap-async-xsjs-queries](https://github.com/advanced-security/codeql-sap-js/pkgs/container/javascript-sap-async-xsjs-queries)
15+
- [advanced-security/javascript-sap-xsjs-queries](https://github.com/advanced-security/codeql-sap-js/pkgs/container/javascript-sap-xsjs-queries)
16+
- [advanced-security/javascript-sap-cap-models](https://github.com/advanced-security/codeql-sap-js/pkgs/container/javascript-sap-cap-models)
17+
- [advanced-security/javascript-sap-ui5-models](https://github.com/advanced-security/codeql-sap-js/pkgs/container/javascript-sap-ui5-models)
18+
- [advanced-security/javascript-sap-xsjs-models](https://github.com/advanced-security/codeql-sap-js/pkgs/container/javascript-sap-xsjs-models)
1619

1720
## Usage
1821

@@ -65,6 +68,9 @@ packs:
6568
- advanced-security/javascript-sap-xsjs-queries:codeql-suites/javascript-security-extended.qls
6669
- advanced-security/javascript-sap-cap-queries:codeql-suites/javascript-security-extended.qls
6770
- advanced-security/javascript-sap-ui5-queries:codeql-suites/javascript-security-extended.qls
71+
- advanced-security/javascript-sap-xsjs-models
72+
- advanced-security/javascript-sap-cap-models
73+
- advanced-security/javascript-sap-ui5-models
6874

6975
paths-ignore:
7076
- "**/node_modules"
@@ -105,6 +111,9 @@ codeql database analyze <DB_NAME> --format=sarif-latest --output=<OUTPUT_FILE> \
105111
--download advanced-security/javascript-sap-cap-queries \
106112
advanced-security/javascript-sap-ui5-queries \
107113
advanced-security/javascript-sap-xsjs-queries
114+
--model-packs=advanced-security/javascript-sap-cap-models
115+
--model-packs= advanced-security/javascript-sap-ui5-models
116+
--model-packs=advanced-security/javascript-sap-xsjs-models
108117
```
109118

110119
### Example `codeql database create` with CDS Extractor Invocation

extractors/cds/tools/cds-extractor.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { join } from 'path';
33
import { sync as globSync } from 'glob';
44

55
import { orchestrateCompilation } from './src/cds/compiler';
6+
import { orchestrateCdsIndexer } from './src/cds/indexer';
67
import { buildCdsProjectDependencyGraph, type CdsDependencyGraph } from './src/cds/parser';
78
import { handleEarlyExit, runJavaScriptExtractionWithMarker } from './src/codeql';
89
import {
@@ -206,6 +207,23 @@ if (projectCacheDirMap.size === 0) {
206207
);
207208
}
208209

210+
// Run cds-indexer for projects that use it (before compilation)
211+
logPerformanceTrackingStart('CDS Indexer');
212+
const cdsIndexerSummary = orchestrateCdsIndexer(
213+
dependencyGraph,
214+
sourceRoot,
215+
projectCacheDirMap,
216+
codeqlExePath,
217+
);
218+
logPerformanceTrackingStop('CDS Indexer');
219+
220+
if (cdsIndexerSummary.projectsRequiringIndexer > 0) {
221+
logPerformanceMilestone(
222+
'CDS indexer completed',
223+
`${cdsIndexerSummary.successfulRuns} succeeded, ${cdsIndexerSummary.failedRuns} failed`,
224+
);
225+
}
226+
209227
// Collect all CDS files to process
210228
const cdsFilePathsToProcess: string[] = [];
211229
for (const project of dependencyGraph.projects.values()) {

0 commit comments

Comments
 (0)