Format .github/actions/update-bundle/index.ts
This commit is contained in:
parent
1c0a788663
commit
33f30874a7
1 changed files with 42 additions and 41 deletions
83
.github/actions/update-bundle/index.ts
vendored
83
.github/actions/update-bundle/index.ts
vendored
|
|
@ -2,63 +2,64 @@ import * as fs from 'fs';
|
||||||
import * as github from '@actions/github';
|
import * as github from '@actions/github';
|
||||||
|
|
||||||
interface BundleInfo {
|
interface BundleInfo {
|
||||||
bundleVersion: string;
|
bundleVersion: string;
|
||||||
cliVersion: string;
|
cliVersion: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Defaults {
|
interface Defaults {
|
||||||
bundleVersion: string;
|
bundleVersion: string;
|
||||||
cliVersion: string;
|
cliVersion: string;
|
||||||
priorBundleVersion: string;
|
priorBundleVersion: string;
|
||||||
priorCliVersion: string;
|
priorCliVersion: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CODEQL_BUNDLE_PREFIX = 'codeql-bundle-';
|
const CODEQL_BUNDLE_PREFIX = 'codeql-bundle-';
|
||||||
|
|
||||||
function getCodeQLCliVersionForRelease(release): string {
|
function getCodeQLCliVersionForRelease(release): string {
|
||||||
const cliVersionsFromMarkerFiles = release.assets
|
const cliVersionsFromMarkerFiles = release.assets
|
||||||
.map((asset) => asset.name.match(/cli-version-(.*)\.txt/)?.[1])
|
.map((asset) => asset.name.match(/cli-version-(.*)\.txt/)?.[1])
|
||||||
.filter((v) => v)
|
.filter((v) => v)
|
||||||
.map((v) => v as string);
|
.map((v) => v as string);
|
||||||
if (cliVersionsFromMarkerFiles.length > 1) {
|
if (cliVersionsFromMarkerFiles.length > 1) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Release ${release.tag_name} has multiple CLI version marker files.`
|
`Release ${release.tag_name} has multiple CLI version marker files.`
|
||||||
);
|
);
|
||||||
} else if (cliVersionsFromMarkerFiles.length === 0) {
|
} else if (cliVersionsFromMarkerFiles.length === 0) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Failed to find the CodeQL CLI version for release ${release.tag_name}.`
|
`Failed to find the CodeQL CLI version for release ${release.tag_name}.`
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
return cliVersionsFromMarkerFiles[0];
|
||||||
}
|
}
|
||||||
return cliVersionsFromMarkerFiles[0];
|
|
||||||
}
|
async function getBundleInfoFromRelease(release): Promise<BundleInfo> {
|
||||||
|
return {
|
||||||
async function getBundleInfoFromRelease(release): Promise<BundleInfo> {
|
|
||||||
return {
|
|
||||||
bundleVersion: release.tag_name.substring(CODEQL_BUNDLE_PREFIX.length),
|
bundleVersion: release.tag_name.substring(CODEQL_BUNDLE_PREFIX.length),
|
||||||
cliVersion: getCodeQLCliVersionForRelease(release)
|
cliVersion: getCodeQLCliVersionForRelease(release)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getNewDefaults(currentDefaults: Defaults): Promise<Defaults> {
|
async function getNewDefaults(currentDefaults: Defaults): Promise<Defaults> {
|
||||||
const release = github.context.payload.release;
|
const release = github.context.payload.release;
|
||||||
console.log('Updating default bundle as a result of the following release: ' +
|
console.log('Updating default bundle as a result of the following release: ' +
|
||||||
`${JSON.stringify(release)}.`)
|
`${JSON.stringify(release)}.`)
|
||||||
|
|
||||||
const bundleInfo = await getBundleInfoFromRelease(release);
|
const bundleInfo = await getBundleInfoFromRelease(release);
|
||||||
return {
|
return {
|
||||||
bundleVersion: bundleInfo.bundleVersion,
|
bundleVersion: bundleInfo.bundleVersion,
|
||||||
cliVersion: bundleInfo.cliVersion,
|
cliVersion: bundleInfo.cliVersion,
|
||||||
priorBundleVersion: currentDefaults.bundleVersion,
|
priorBundleVersion: currentDefaults.bundleVersion,
|
||||||
priorCliVersion: currentDefaults.cliVersion
|
priorCliVersion: currentDefaults.cliVersion
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const previousDefaults: Defaults = JSON.parse(fs.readFileSync('../../../src/defaults.json', 'utf8'));
|
const previousDefaults: Defaults = JSON.parse(fs.readFileSync('../../../src/defaults.json', 'utf8'));
|
||||||
const newDefaults = await getNewDefaults(previousDefaults);
|
const newDefaults = await getNewDefaults(previousDefaults);
|
||||||
fs.writeFileSync('../../../src/defaults.json', JSON.stringify(newDefaults, null, 2) + "\n");
|
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`.
|
// 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.
|
// So instead we rely on the fact that Node won't exit until the event loop is empty.
|
||||||
main();
|
main();
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue