1+ name : " Update the CodeQL CLI dependencies"
2+
3+ on :
4+ workflow_dispatch :
5+ # nightly runs to update the CodeQL CLI dependencies
6+ schedule :
7+ - cron : ' 30 0 * * *'
8+
9+ permissions :
10+ contents : write
11+ pull-requests : write
12+
13+ jobs :
14+ update-codeql :
15+ name : Update CodeQL CLI dependencies
16+ runs-on : ubuntu-latest
17+
18+ steps :
19+ - name : Checkout repository
20+ uses : actions/checkout@v4
21+
22+ - name : Check latest CodeQL CLI version and update qlt.conf.json
23+ id : check-version
24+ run : |
25+ echo "Checking latest CodeQL CLI version"
26+ current_version=$(jq .CodeQLCLI qlt.conf.json -r)
27+ latest_version=$(gh release list --repo github/codeql-cli-binaries --json 'tagName,isLatest' --jq '.[] | select(.isLatest == true) | .tagName')
28+ echo "Current CodeQL CLI version: $current_version"
29+ echo "Latest CodeQL CLI version: $latest_version"
30+
31+ # Remove 'v' prefix if present for comparison with current version
32+ latest_clean=$(echo "$latest_version" | sed 's/^v//')
33+
34+ if [ "$latest_clean" != "$current_version" ]; then
35+ echo "Updating CodeQL CLI from $current_version to $latest_clean"
36+ echo "update_needed=true" >> $GITHUB_OUTPUT
37+ echo "latest_version=$latest_clean" >> $GITHUB_OUTPUT
38+ echo "latest_version_tag=$latest_version" >> $GITHUB_OUTPUT
39+
40+ # Update qlt.conf.json with all properties
41+ echo "Updating qlt.conf.json with all properties for version $latest_clean"
42+ jq --arg cli_version "$latest_clean" \
43+ --arg std_lib "codeql-cli/$latest_version" \
44+ --arg bundle "codeql-bundle-$latest_version" \
45+ '.CodeQLCLI = $cli_version | .CodeQLStandardLibrary = $std_lib | .CodeQLCLIBundle = $bundle' \
46+ qlt.conf.json > qlt.conf.json.tmp && mv qlt.conf.json.tmp qlt.conf.json
47+
48+ echo "Updated qlt.conf.json contents:"
49+ cat qlt.conf.json
50+ else
51+ echo "CodeQL CLI is already up-to-date at version $current_version."
52+ echo "update_needed=false" >> $GITHUB_OUTPUT
53+ fi
54+
55+ - name : Install QLT
56+ if : steps.check-version.outputs.update_needed == 'true'
57+ id : install-qlt
58+ uses : advanced-security/codeql-development-toolkit/.github/actions/install-qlt@main
59+ with :
60+ qlt-version : ' latest'
61+ add-to-path : true
62+
63+ - name : Install CodeQL
64+ if : steps.check-version.outputs.update_needed == 'true'
65+ id : install-codeql
66+ shell : bash
67+ run : |
68+ echo "Installing CodeQL"
69+ qlt codeql run install
70+ echo "-----------------------------"
71+ echo "CodeQL Home: $QLT_CODEQL_HOME"
72+ echo "CodeQL Binary: $QLT_CODEQL_PATH"
73+
74+ - name : Upgrade CodeQL pack lock files
75+ if : steps.check-version.outputs.update_needed == 'true'
76+ shell : bash
77+ run : |
78+ echo "Upgrading CodeQL pack lock files"
79+ echo "Finding all directories with qlpack.yml files..."
80+
81+ # Find all directories containing qlpack.yml files
82+ find . -name "qlpack.yml" -type f | while read -r qlpack_file; do
83+ pack_dir=$(dirname "$qlpack_file")
84+ echo "Upgrading pack in directory: $pack_dir"
85+
86+ # Change to the directory and run codeql pack upgrade
87+ cd "$pack_dir"
88+ $QLT_CODEQL_PATH pack upgrade
89+ cd - > /dev/null
90+ done
91+
92+ echo "Finished upgrading all CodeQL pack lock files"
93+
94+ - name : Create Pull Request
95+ if : steps.check-version.outputs.update_needed == 'true'
96+ uses : peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
97+ with :
98+ title : " Upgrade CodeQL CLI dependency to ${{ steps.check-version.outputs.latest_version_tag }}"
99+ body : |
100+ This PR upgrades the CodeQL CLI version to ${{ steps.check-version.outputs.latest_version_tag }}.
101+
102+ **Changes made:**
103+ - Updated `CodeQLCLI` to `${{ steps.check-version.outputs.latest_version }}`
104+ - Updated `CodeQLStandardLibrary` to `codeql-cli/${{ steps.check-version.outputs.latest_version_tag }}`
105+ - Updated `CodeQLCLIBundle` to `codeql-bundle-${{ steps.check-version.outputs.latest_version_tag }}`
106+ - Upgraded all CodeQL pack lock files using `codeql pack upgrade`
107+ commit-message : " Upgrade CodeQL CLI dependency to ${{ steps.check-version.outputs.latest_version_tag }}"
108+ delete-branch : true
109+ branch : " codeql/upgrade-to-${{ steps.check-version.outputs.latest_version_tag }}"
0 commit comments