Skip to content

Use bundle URL version as the cache version #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 19, 2020
Merged
Prev Previous commit
Next Next commit
switch to semver instead of hash
  • Loading branch information
Alex Kalyvitis committed Jun 18, 2020
commit 3f2a60be8a02f3d0d30c4cd412be8d71466ff676
35 changes: 28 additions & 7 deletions src/setup-tools.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as core from '@actions/core';
import * as toolcache from '@actions/tool-cache';
import * as crypto from 'crypto';
import * as semver from 'semver';
import * as path from 'path';

export class CodeQLSetup {
Expand Down Expand Up @@ -30,18 +30,17 @@ export class CodeQLSetup {
}

export async function setupCodeQL(): Promise<CodeQLSetup> {
const hash = crypto.createHash('sha256');
const codeqlURL = core.getInput('tools', { required: true });
const codeqlURLHash = hash.update(codeqlURL).digest('hex');

try {
let codeqlFolder = toolcache.find('CodeQL', codeqlURLHash);
const codeqlURL = core.getInput('tools', { required: true });
const codeqlURLVersion = getCodeQLURLVersion(codeqlURL);

let codeqlFolder = toolcache.find('CodeQL', codeqlURLVersion);
if (codeqlFolder) {
core.debug(`CodeQL found in cache ${codeqlFolder}`);
} else {
const codeqlPath = await toolcache.downloadTool(codeqlURL);
const codeqlExtracted = await toolcache.extractTar(codeqlPath);
codeqlFolder = await toolcache.cacheDir(codeqlExtracted, 'CodeQL', codeqlURLHash);
codeqlFolder = await toolcache.cacheDir(codeqlExtracted, 'CodeQL', codeqlURLVersion);
}
return new CodeQLSetup(path.join(codeqlFolder, 'codeql'));

Expand All @@ -50,3 +49,25 @@ export async function setupCodeQL(): Promise<CodeQLSetup> {
throw new Error("Unable to download and extract CodeQL CLI");
}
}

export function getCodeQLURLVersion(url: string): string {

const match = url.match(/codeql-bundle-([\d+(\.\d+)]+)/);
if (match === null || match.length < 2) {
throw new Error(`Malformed tools url: ${url}. Version could not be inferred`);
}

let version = match[1];

if (!semver.valid(version)) {
core.debug(`Bundle version ${version} is not in SemVer format. Will treat it as pre-release 0.0.0-${version}.`);
version = '0.0.0-' + version;
}

const s = semver.clean(version);
if (!s) {
throw new Error(`Malformed tools url ${url}. Version should be in SemVer format but have ${version} instead`);
}

return s;
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy