| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| name: 'Prepare release job' | ||
| description: 'Prepare for updating a release branch' | ||
|
|
||
| runs: | ||
| using: "composite" | ||
| steps: | ||
|
|
||
| - name: Dump environment | ||
| run: env | ||
| shell: bash | ||
|
|
||
| - name: Dump GitHub context | ||
| env: | ||
| GITHUB_CONTEXT: '${{ toJson(github) }}' | ||
| run: echo "$GITHUB_CONTEXT" | ||
| shell: bash | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: 3.12 | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install PyGithub==2.3.0 requests | ||
| shell: bash | ||
|
|
||
| - name: Update git config | ||
| run: | | ||
| git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
| git config --global user.name "github-actions[bot]" | ||
| shell: bash |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| name: "Set up Swift on Linux" | ||
| description: Sets up an appropriate Swift version on Linux. | ||
| inputs: | ||
| codeql-path: | ||
| description: Path to the CodeQL CLI executable. | ||
| required: true | ||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: Get Swift version | ||
| id: get_swift_version | ||
| if: runner.os == 'Linux' | ||
| shell: bash | ||
| env: | ||
| CODEQL_PATH: ${{ inputs.codeql-path }} | ||
| run: | | ||
| SWIFT_EXTRACTOR_DIR="$("$CODEQL_PATH" resolve languages --format json | jq -r '.swift[0]')" | ||
| if [ $SWIFT_EXTRACTOR_DIR = "null" ]; then | ||
| VERSION="null" | ||
| else | ||
| VERSION="$("$SWIFT_EXTRACTOR_DIR/tools/linux64/extractor" --version | awk '/version/ { print $3 }')" | ||
| # Specify 5.x.0, otherwise setup Action will default to latest minor version. | ||
| if [ $VERSION = "5.7" ]; then | ||
| VERSION="5.7.0" | ||
| elif [ $VERSION = "5.8" ]; then | ||
| VERSION="5.8.0" | ||
| elif [ $VERSION = "5.9" ]; then | ||
| VERSION="5.9.0" | ||
| # setup-swift does not yet support v5.9.1 Remove this when it does. | ||
| elif [ $VERSION = "5.9.1" ]; then | ||
| VERSION="5.9.0" | ||
| fi | ||
| fi | ||
| echo "version=$VERSION" | tee -a $GITHUB_OUTPUT | ||
| - uses: redsun82/setup-swift@362f49f31da2f5f4f851657046bdd1290d03edc8 # Please update the corresponding SHA in the CLI's CodeQL Action Integration Test. | ||
| if: runner.os == 'Linux' && steps.get_swift_version.outputs.version != 'null' | ||
| with: | ||
| swift-version: "${{ steps.get_swift_version.outputs.version }}" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| name: Update default CodeQL bundle | ||
| description: Updates 'src/defaults.json' to point to a new CodeQL bundle release. | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Install ts-node | ||
| shell: bash | ||
| run: npm install -g ts-node | ||
|
|
||
| - name: Run update script | ||
| working-directory: ${{ github.action_path }} | ||
| shell: bash | ||
| run: ts-node ./index.ts |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import * as fs from 'fs'; | ||
| import * as github from '@actions/github'; | ||
|
|
||
| interface BundleInfo { | ||
| bundleVersion: string; | ||
| cliVersion: string; | ||
| } | ||
|
|
||
| interface Defaults { | ||
| bundleVersion: string; | ||
| cliVersion: string; | ||
| priorBundleVersion: string; | ||
| priorCliVersion: string; | ||
| } | ||
|
|
||
| function getCodeQLCliVersionForRelease(release): string { | ||
| // We do not currently tag CodeQL bundles based on the CLI version they contain. | ||
| // Instead, we use a marker file `cli-version-<version>.txt` to record the CLI version. | ||
| // This marker file is uploaded as a release asset for all new CodeQL bundles. | ||
| const cliVersionsFromMarkerFiles = release.assets | ||
| .map((asset) => asset.name.match(/cli-version-(.*)\.txt/)?.[1]) | ||
| .filter((v) => v) | ||
| .map((v) => v as string); | ||
| if (cliVersionsFromMarkerFiles.length > 1) { | ||
| throw new Error( | ||
| `Release ${release.tag_name} has multiple CLI version marker files.` | ||
| ); | ||
| } else if (cliVersionsFromMarkerFiles.length === 0) { | ||
| throw new Error( | ||
| `Failed to find the CodeQL CLI version for release ${release.tag_name}.` | ||
| ); | ||
| } | ||
| return cliVersionsFromMarkerFiles[0]; | ||
| } | ||
|
|
||
| async function getBundleInfoFromRelease(release): Promise<BundleInfo> { | ||
| return { | ||
| bundleVersion: release.tag_name, | ||
| cliVersion: getCodeQLCliVersionForRelease(release) | ||
| }; | ||
| } | ||
|
|
||
| async function getNewDefaults(currentDefaults: Defaults): Promise<Defaults> { | ||
| const release = github.context.payload.release; | ||
| console.log('Updating default bundle as a result of the following release: ' + | ||
| `${JSON.stringify(release)}.`) | ||
|
|
||
| const bundleInfo = await getBundleInfoFromRelease(release); | ||
| return { | ||
| bundleVersion: bundleInfo.bundleVersion, | ||
| cliVersion: bundleInfo.cliVersion, | ||
| priorBundleVersion: currentDefaults.bundleVersion, | ||
| priorCliVersion: currentDefaults.cliVersion | ||
| }; | ||
| } | ||
|
|
||
| async function main() { | ||
| const previousDefaults: Defaults = JSON.parse(fs.readFileSync('../../../src/defaults.json', 'utf8')); | ||
| const newDefaults = await getNewDefaults(previousDefaults); | ||
| // Update the source file in the repository. Calling workflows should subsequently rebuild | ||
| // the Action to update `lib/defaults.json`. | ||
| fs.writeFileSync('../../../src/defaults.json', JSON.stringify(newDefaults, null, 2) + "\n"); | ||
| } | ||
|
|
||
| // Ideally, we'd await main() here, but that doesn't work well with `ts-node`. | ||
| // So instead we rely on the fact that Node won't exit until the event loop is empty. | ||
| main(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| OLDEST_SUPPORTED_MAJOR_VERSION=2 |