Skip to content
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

fix caching by ignoring semver build metadata #60

Draft
wants to merge 5 commits into
base: default
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82128,8 +82128,15 @@ var require_versions = __commonJS({
x64: "x86_64"
}[arch];
const downloadUrl = `https://ziglang.org/builds/zig-${resolvedOs}-${resolvedArch}-${version3}.${ext}`;
const variantName = `zig-${resolvedOs}-${resolvedArch}-${version3}`;
return { downloadUrl, variantName, version: version3 };
const versionWithoutBuildHash = semver2.clean(version3);
const fileWithoutFileType = `zig-${resolvedOs}-${resolvedArch}-${version3}`;
const variantName = `zig-${resolvedOs}-${resolvedArch}-${versionWithoutBuildHash}`;
return {
downloadUrl,
fileWithoutFileType,
variantName,
version: versionWithoutBuildHash
};
}
__name(resolveCommit2, "resolveCommit");
function getJSON(opts) {
Expand Down Expand Up @@ -82194,7 +82201,12 @@ var {
var TOOL_NAME = "zig";
async function downloadZig(arch, platform, version3, useCache = true) {
const ext = extForPlatform(platform);
const { downloadUrl, variantName, version: useVersion } = version3.includes("+") ? resolveCommit(arch, platform, version3) : await resolveVersion(arch, platform, version3);
const {
downloadUrl,
fileWithoutFileType,
variantName,
version: useVersion
} = version3.includes("+") ? resolveCommit(arch, platform, version3) : await resolveVersion(arch, platform, version3);
const cachedPath = toolCache.find(TOOL_NAME, useVersion);
if (cachedPath) {
actions.info(`using cached zig install: ${cachedPath}`);
Expand All @@ -82213,7 +82225,7 @@ async function downloadZig(arch, platform, version3, useCache = true) {
actions.info(`no cached version found. downloading zig ${variantName}`);
const downloadPath = await toolCache.downloadTool(downloadUrl);
const zigPath = ext === "zip" ? await toolCache.extractZip(downloadPath) : await toolCache.extractTar(downloadPath, void 0, "x");
const binPath = path.join(zigPath, variantName);
const binPath = path.join(zigPath, fileWithoutFileType);
const cachePath = await toolCache.cacheDir(binPath, TOOL_NAME, useVersion);
if (useCache) {
actions.info(`adding zig ${useVersion} at ${cachePath} to local cache ${cacheKey}`);
Expand Down
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ const TOOL_NAME = 'zig'
async function downloadZig (arch, platform, version, useCache = true) {
const ext = extForPlatform(platform)

const { downloadUrl, variantName, version: useVersion } = version.includes('+')
const {
downloadUrl,
fileWithoutFileType,
variantName,
version: useVersion
} = version.includes('+')
? resolveCommit(arch, platform, version)
: await resolveVersion(arch, platform, version)

Expand All @@ -44,7 +49,7 @@ async function downloadZig (arch, platform, version, useCache = true) {
? await toolCache.extractZip(downloadPath)
: await toolCache.extractTar(downloadPath, undefined, 'x')

const binPath = path.join(zigPath, variantName)
const binPath = path.join(zigPath, fileWithoutFileType)
const cachePath = await toolCache.cacheDir(binPath, TOOL_NAME, useVersion)

if (useCache) {
Expand Down
22 changes: 18 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,27 @@ const {
async function test () {
assert.deepEqual(resolveCommit('x64', 'linux', '0.6.0+4b48fccad'), {
downloadUrl: 'https://ziglang.org/builds/zig-linux-x86_64-0.6.0+4b48fccad.tar.xz',
variantName: 'zig-linux-x86_64-0.6.0+4b48fccad',
version: '0.6.0+4b48fccad'
fileWithoutFileType: 'zig-linux-x86_64-0.6.0+4b48fccad',
variantName: 'zig-linux-x86_64-0.6.0',
version: '0.6.0'
})
assert.deepEqual(resolveCommit('x64', 'win32', '0.6.0+4b48fccad'), {
downloadUrl: 'https://ziglang.org/builds/zig-windows-x86_64-0.6.0+4b48fccad.zip',
variantName: 'zig-windows-x86_64-0.6.0+4b48fccad',
version: '0.6.0+4b48fccad'
fileWithoutFileType: 'zig-windows-x86_64-0.6.0+4b48fccad',
variantName: 'zig-windows-x86_64-0.6.0',
version: '0.6.0'
})
assert.deepEqual(resolveCommit('x64', 'win32', '0.12.0-dev.1092+68ed78775'), {
downloadUrl: 'https://ziglang.org/builds/zig-windows-x86_64-0.12.0-dev.1092+68ed78775.zip',
fileWithoutFileType: 'zig-windows-x86_64-0.12.0-dev.1092+68ed78775',
variantName: 'zig-windows-x86_64-0.12.0-dev.1092',
version: '0.12.0-dev.1092'
})
assert.deepEqual(resolveCommit('x64', 'darwin', '0.12.0-dev.1150+3c22cecee'), {
downloadUrl: 'https://ziglang.org/builds/zig-macos-x86_64-0.12.0-dev.1150+3c22cecee.tar.xz',
fileWithoutFileType: 'zig-macos-x86_64-0.12.0-dev.1150+3c22cecee',
variantName: 'zig-macos-x86_64-0.12.0-dev.1150',
version: '0.12.0-dev.1150'
})

assert.deepEqual(await resolveVersion('x64', 'linux', '0.7.0'), {
Expand Down
11 changes: 9 additions & 2 deletions versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@ function resolveCommit (arch, platform, version) {
}[arch]

const downloadUrl = `https://ziglang.org/builds/zig-${resolvedOs}-${resolvedArch}-${version}.${ext}`
const variantName = `zig-${resolvedOs}-${resolvedArch}-${version}`
const versionWithoutBuildHash = semver.clean(version)
const fileWithoutFileType = `zig-${resolvedOs}-${resolvedArch}-${version}`
const variantName = `zig-${resolvedOs}-${resolvedArch}-${versionWithoutBuildHash}`

return { downloadUrl, variantName, version }
return {
downloadUrl,
fileWithoutFileType,
variantName,
version: versionWithoutBuildHash
}
}

function getJSON (opts) {
Expand Down