Skip to content

Commit f0a422f

Browse files
authored
Merge pull request #1630 from github/henrymercer/automate-bundle-upgrade
Automate the bundle upgrade
2 parents bb28e7e + 98173be commit f0a422f

Some content is hidden

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

55 files changed

+235
-70
lines changed
File renamed without changes.

.github/query-filter-test/action.yml renamed to .github/actions/query-filter-test/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ runs:
4444
env:
4545
CODEQL_ACTION_TEST_MODE: "true"
4646
- name: Check SARIF
47-
uses: ./../action/.github/check-sarif
47+
uses: ./../action/.github/actions/check-sarif
4848
with:
4949
sarif-file: ${{ inputs.sarif-file }}
5050
queries-run: ${{ inputs.queries-run}}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Update default CodeQL bundle
2+
description: Updates 'src/defaults.json' to point to a new CodeQL bundle release.
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Install ts-node
8+
shell: bash
9+
run: npm install -g ts-node
10+
11+
- name: Run update script
12+
working-directory: ${{ github.action_path }}
13+
shell: bash
14+
run: ts-node ./index.ts
+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import * as fs from 'fs';
2+
import * as github from '@actions/github';
3+
4+
interface BundleInfo {
5+
bundleVersion: string;
6+
cliVersion: string;
7+
}
8+
9+
interface Defaults {
10+
bundleVersion: string;
11+
cliVersion: string;
12+
priorBundleVersion: string;
13+
priorCliVersion: string;
14+
}
15+
16+
const CODEQL_BUNDLE_PREFIX = 'codeql-bundle-';
17+
18+
function getCodeQLCliVersionForRelease(release): string {
19+
// We do not currently tag CodeQL bundles based on the CLI version they contain.
20+
// Instead, we use a marker file `cli-version-<version>.txt` to record the CLI version.
21+
// This marker file is uploaded as a release asset for all new CodeQL bundles.
22+
const cliVersionsFromMarkerFiles = release.assets
23+
.map((asset) => asset.name.match(/cli-version-(.*)\.txt/)?.[1])
24+
.filter((v) => v)
25+
.map((v) => v as string);
26+
if (cliVersionsFromMarkerFiles.length > 1) {
27+
throw new Error(
28+
`Release ${release.tag_name} has multiple CLI version marker files.`
29+
);
30+
} else if (cliVersionsFromMarkerFiles.length === 0) {
31+
throw new Error(
32+
`Failed to find the CodeQL CLI version for release ${release.tag_name}.`
33+
);
34+
}
35+
return cliVersionsFromMarkerFiles[0];
36+
}
37+
38+
async function getBundleInfoFromRelease(release): Promise<BundleInfo> {
39+
return {
40+
bundleVersion: release.tag_name.substring(CODEQL_BUNDLE_PREFIX.length),
41+
cliVersion: getCodeQLCliVersionForRelease(release)
42+
};
43+
}
44+
45+
async function getNewDefaults(currentDefaults: Defaults): Promise<Defaults> {
46+
const release = github.context.payload.release;
47+
console.log('Updating default bundle as a result of the following release: ' +
48+
`${JSON.stringify(release)}.`)
49+
50+
const bundleInfo = await getBundleInfoFromRelease(release);
51+
return {
52+
bundleVersion: bundleInfo.bundleVersion,
53+
cliVersion: bundleInfo.cliVersion,
54+
priorBundleVersion: currentDefaults.bundleVersion,
55+
priorCliVersion: currentDefaults.cliVersion
56+
};
57+
}
58+
59+
async function main() {
60+
const previousDefaults: Defaults = JSON.parse(fs.readFileSync('../../../src/defaults.json', 'utf8'));
61+
const newDefaults = await getNewDefaults(previousDefaults);
62+
// Update the source file in the repository. Calling workflows should subsequently rebuild
63+
// the Action to update `lib/defaults.json`.
64+
fs.writeFileSync('../../../src/defaults.json', JSON.stringify(newDefaults, null, 2) + "\n");
65+
}
66+
67+
// Ideally, we'd await main() here, but that doesn't work well with `ts-node`.
68+
// So instead we rely on the fact that Node won't exit until the event loop is empty.
69+
main();

.github/dependabot.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ updates:
1616
schedule:
1717
interval: weekly
1818
- package-ecosystem: github-actions
19-
directory: "/.github/setup-swift/" # All subdirectories outside of "/.github/workflows" must be explicitly included.
19+
directory: "/.github/actions/setup-swift/" # All subdirectories outside of "/.github/workflows" must be explicitly included.
2020
schedule:
2121
interval: weekly

.github/workflows/__analyze-ref-input.yml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__autobuild-action.yml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__config-export.yml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__diagnostics-export.yml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__export-file-baseline-information.yml

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__extractor-ram-threads.yml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__go-custom-queries.yml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__go-tracing-autobuilder.yml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__go-tracing-custom-build-steps.yml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__go-tracing-legacy-workflow.yml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__init-with-registries.yml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__javascript-source-root.yml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__ml-powered-queries.yml

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__multi-language-autodetect.yml

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__packaging-codescanning-config-inputs-js.yml

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__packaging-config-inputs-js.yml

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__packaging-config-js.yml

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__packaging-inputs-js.yml

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__remote-config.yml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__rubocop-multi-language.yml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__ruby.yml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__split-workflow.yml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__submit-sarif-failure.yml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__swift-custom-build.yml

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__test-autobuild-working-dir.yml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)