|
7 | 7 | - cron: '30 0 * * *' |
8 | 8 |
|
9 | 9 | permissions: |
10 | | - contents: write |
11 | | - pull-requests: write |
| 10 | + contents: read |
12 | 11 |
|
13 | 12 | jobs: |
14 | | - update-codeql: |
15 | | - name: Update CodeQL CLI Dependencies |
| 13 | + # ───────────────────────────────────────────────────────────────────────────── |
| 14 | + # Step 1: Detect new CodeQL CLI version |
| 15 | + # |
| 16 | + # Compares the current CodeQL CLI version in qlt.conf.json against the latest |
| 17 | + # 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. |
| 20 | + # ───────────────────────────────────────────────────────────────────────────── |
| 21 | + detect-update: |
| 22 | + name: Detect CodeQL CLI Update |
16 | 23 | runs-on: ubuntu-latest |
17 | 24 |
|
| 25 | + outputs: |
| 26 | + current_version: ${{ steps.check-version.outputs.current_version }} |
| 27 | + latest_version: ${{ steps.check-version.outputs.latest_version }} |
| 28 | + update_needed: ${{ steps.check-version.outputs.update_needed }} |
| 29 | + version: ${{ steps.check-version.outputs.version }} |
| 30 | + |
18 | 31 | steps: |
19 | | - - name: Update - Checkout repository |
| 32 | + - name: Detect - Checkout repository |
20 | 33 | uses: actions/checkout@v6 |
21 | 34 |
|
22 | | - - name: Update - Check latest CodeQL CLI version |
| 35 | + - name: Detect - Check latest CodeQL CLI version |
23 | 36 | id: check-version |
24 | 37 | env: |
25 | 38 | GH_TOKEN: ${{ github.token }} |
26 | 39 | run: | |
27 | 40 | echo "Checking latest CodeQL CLI version..." |
28 | | - current_version=$(jq .CodeQLCLI qlt.conf.json -r) |
29 | | - latest_version=$(gh release list --repo github/codeql-cli-binaries --json 'tagName,isLatest' --jq '.[] | select(.isLatest == true) | .tagName') |
30 | | - echo "Current CodeQL CLI version: $current_version" |
31 | | - echo "Latest CodeQL CLI version: $latest_version" |
| 41 | + current_version=$(jq -r .CodeQLCLI qlt.conf.json) |
| 42 | + latest_tag=$(gh release list --repo github/codeql-cli-binaries --json 'tagName,isLatest' --jq '.[] | select(.isLatest == true) | .tagName') |
| 43 | + latest_clean="${latest_tag#v}" |
32 | 44 |
|
33 | | - # Remove 'v' prefix if present for comparison with current version |
34 | | - latest_clean=$(echo "$latest_version" | sed 's/^v//') |
| 45 | + echo "Current CodeQL CLI version: ${current_version}" |
| 46 | + echo "Latest CodeQL CLI version: ${latest_clean}" |
35 | 47 |
|
36 | | - if [ "$latest_clean" != "$current_version" ]; then |
37 | | - echo "Updating CodeQL CLI from $current_version to $latest_clean" |
| 48 | + if [ "${latest_clean}" != "${current_version}" ]; then |
| 49 | + echo "✅ Update available: ${current_version} → ${latest_clean}" |
38 | 50 | echo "update_needed=true" >> $GITHUB_OUTPUT |
39 | | - echo "current_version=$current_version" >> $GITHUB_OUTPUT |
40 | | - echo "latest_version=$latest_clean" >> $GITHUB_OUTPUT |
41 | | - echo "latest_version_tag=$latest_version" >> $GITHUB_OUTPUT |
42 | | -
|
43 | | - # Update qlt.conf.json with all properties |
44 | | - echo "Updating qlt.conf.json with all properties for version $latest_clean" |
45 | | - jq --arg cli_version "$latest_clean" \ |
46 | | - --arg std_lib "codeql-cli/$latest_version" \ |
47 | | - --arg bundle "codeql-bundle-$latest_version" \ |
48 | | - '.CodeQLCLI = $cli_version | .CodeQLStandardLibrary = $std_lib | .CodeQLCLIBundle = $bundle' \ |
49 | | - qlt.conf.json > qlt.conf.json.tmp && mv qlt.conf.json.tmp qlt.conf.json |
50 | | -
|
51 | | - echo "Updated qlt.conf.json contents:" |
52 | | - cat qlt.conf.json |
| 51 | + echo "current_version=${current_version}" >> $GITHUB_OUTPUT |
| 52 | + echo "latest_version=${latest_clean}" >> $GITHUB_OUTPUT |
| 53 | + echo "version=v${latest_clean}" >> $GITHUB_OUTPUT |
53 | 54 | else |
54 | | - echo "CodeQL CLI is already up-to-date at version $current_version." |
| 55 | + echo "ℹ️ CodeQL CLI is already up-to-date at version ${current_version}" |
55 | 56 | echo "update_needed=false" >> $GITHUB_OUTPUT |
56 | 57 | fi |
57 | 58 |
|
58 | | - - name: Update - Install QLT |
59 | | - if: steps.check-version.outputs.update_needed == 'true' |
60 | | - id: install-qlt |
61 | | - uses: advanced-security/codeql-development-toolkit/.github/actions/install-qlt@main |
62 | | - with: |
63 | | - qlt-version: 'latest' |
64 | | - add-to-path: true |
65 | | - |
66 | | - - name: Update - Install CodeQL |
67 | | - if: steps.check-version.outputs.update_needed == 'true' |
68 | | - shell: bash |
69 | | - run: | |
70 | | - echo "Installing CodeQL" |
71 | | - qlt codeql run install |
72 | | - echo "-----------------------------" |
73 | | - echo "CodeQL Home: $QLT_CODEQL_HOME" |
74 | | - echo "CodeQL Binary: $QLT_CODEQL_PATH" |
75 | | -
|
76 | | - - name: Update - Upgrade CodeQL pack lock files |
77 | | - if: steps.check-version.outputs.update_needed == 'true' |
78 | | - shell: bash |
79 | | - run: | |
80 | | - echo "Upgrading CodeQL pack lock files..." |
81 | | - find . -name "qlpack.yml" -type f | sort | while read -r qlpack_file; do |
82 | | - pack_dir=$(dirname "$qlpack_file") |
83 | | - echo "Upgrading pack in directory: $pack_dir" |
84 | | - cd "$pack_dir" |
85 | | - $QLT_CODEQL_PATH pack upgrade |
86 | | - cd - > /dev/null |
87 | | - done |
88 | | - echo "Finished upgrading all CodeQL pack lock files" |
89 | | -
|
90 | | - - name: Update - Create Pull Request |
91 | | - if: steps.check-version.outputs.update_needed == 'true' |
92 | | - uses: peter-evans/create-pull-request@v8 |
93 | | - with: |
94 | | - title: "Upgrade CodeQL CLI dependency to ${{ steps.check-version.outputs.latest_version_tag }}" |
95 | | - body: | |
96 | | - This PR upgrades the CodeQL CLI version to ${{ steps.check-version.outputs.latest_version_tag }}. |
97 | | -
|
98 | | - **Changes made:** |
99 | | - - Updated `CodeQLCLI` to `${{ steps.check-version.outputs.latest_version }}` |
100 | | - - Updated `CodeQLStandardLibrary` to `codeql-cli/${{ steps.check-version.outputs.latest_version_tag }}` |
101 | | - - Updated `CodeQLCLIBundle` to `codeql-bundle-${{ steps.check-version.outputs.latest_version_tag }}` |
102 | | - - Upgraded all CodeQL pack lock files using `codeql pack upgrade` |
103 | | - commit-message: "Upgrade CodeQL CLI dependency to ${{ steps.check-version.outputs.latest_version_tag }}" |
104 | | - delete-branch: true |
105 | | - branch: "codeql/upgrade-to-${{ steps.check-version.outputs.latest_version_tag }}" |
106 | | - |
107 | | - - name: Update - Summary |
| 59 | + - name: Detect - Summary |
108 | 60 | run: | |
109 | 61 | echo "## CodeQL CLI Update Check" >> $GITHUB_STEP_SUMMARY |
110 | 62 | echo "" >> $GITHUB_STEP_SUMMARY |
111 | 63 | if [ "${{ steps.check-version.outputs.update_needed }}" == "true" ]; then |
112 | 64 | echo "✅ Update available: ${{ steps.check-version.outputs.current_version }} → ${{ steps.check-version.outputs.latest_version }}" >> $GITHUB_STEP_SUMMARY |
113 | 65 | echo "" >> $GITHUB_STEP_SUMMARY |
114 | | - echo "| Property | Old Value | New Value |" >> $GITHUB_STEP_SUMMARY |
115 | | - echo "| -------- | --------- | --------- |" >> $GITHUB_STEP_SUMMARY |
116 | | - echo "| CodeQLCLI | ${{ steps.check-version.outputs.current_version }} | ${{ steps.check-version.outputs.latest_version }} |" >> $GITHUB_STEP_SUMMARY |
117 | | - echo "| CodeQLStandardLibrary | — | codeql-cli/${{ steps.check-version.outputs.latest_version_tag }} |" >> $GITHUB_STEP_SUMMARY |
118 | | - echo "| CodeQLCLIBundle | — | codeql-bundle-${{ steps.check-version.outputs.latest_version_tag }} |" >> $GITHUB_STEP_SUMMARY |
119 | | - echo "" >> $GITHUB_STEP_SUMMARY |
120 | | - echo "A pull request has been created with these changes." >> $GITHUB_STEP_SUMMARY |
| 66 | + echo "Initiating release pipeline for \`v${{ steps.check-version.outputs.latest_version }}\`..." >> $GITHUB_STEP_SUMMARY |
121 | 67 | else |
122 | | - echo "ℹ️ CodeQL CLI is already up-to-date. No changes needed." >> $GITHUB_STEP_SUMMARY |
| 68 | + echo "ℹ️ CodeQL CLI is already up-to-date. No release needed." >> $GITHUB_STEP_SUMMARY |
123 | 69 | fi |
| 70 | +
|
| 71 | + # ───────────────────────────────────────────────────────────────────────────── |
| 72 | + # Step 2: Create release tag |
| 73 | + # |
| 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. |
| 77 | + # |
| 78 | + # The release-tag environment approval gate provides human-in-the-loop review |
| 79 | + # before any changes are committed. |
| 80 | + # ───────────────────────────────────────────────────────────────────────────── |
| 81 | + ensure-tag: |
| 82 | + name: Ensure Release Tag |
| 83 | + needs: detect-update |
| 84 | + 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' |
| 121 | + runs-on: ubuntu-latest |
| 122 | + |
| 123 | + permissions: |
| 124 | + contents: write |
| 125 | + |
| 126 | + 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 |
| 132 | + |
| 133 | + - name: Release - Create GitHub Release |
| 134 | + uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2.5.0 |
| 135 | + with: |
| 136 | + files: | |
| 137 | + dist-packs/*.tar.gz |
| 138 | + generate_release_notes: true |
| 139 | + tag_name: ${{ needs.detect-update.outputs.version }} |
| 140 | + |
| 141 | + - name: Release - Summary |
| 142 | + run: | |
| 143 | + VERSION="${{ needs.detect-update.outputs.version }}" |
| 144 | + RELEASE_NAME="${{ needs.detect-update.outputs.latest_version }}" |
| 145 | + echo "## Automated Release Summary" >> $GITHUB_STEP_SUMMARY |
| 146 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 147 | + echo "Triggered by CodeQL CLI update: ${{ needs.detect-update.outputs.current_version }} → ${RELEASE_NAME}" >> $GITHUB_STEP_SUMMARY |
| 148 | + 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 |
0 commit comments