From f66649ef5b56341ced71ae819b602e2704f70ec8 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sun, 11 Jul 2021 20:14:49 +0200 Subject: [PATCH] Explicit version for caching Signed-off-by: CrazyMax --- .github/workflows/ci.yml | 1 + dist/index.js | 14 ++++++++++---- src/buildx.ts | 13 +++++++++---- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d78e96c7..a1c38eb3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -323,6 +323,7 @@ jobs: - master - refs/tags/v0.5.1 - refs/pull/648/head + - 67bd6f4dc82a9cd96f34133dab3f6f7af803bb14 steps: - name: Checkout diff --git a/dist/index.js b/dist/index.js index 08c3e215..6f94b87c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -151,10 +151,16 @@ function build(inputBuildRef, dockerConfigHome) { if (ref.length == 0) { ref = 'master'; } - const sha = yield git.getRemoteSha(repo, ref); - core.debug(`Remote ref ${sha} found`); + let version; + if (ref.match(/^[0-9a-fA-F]{40}$/)) { + version = `v0.0.0+${ref}`; + } + else { + version = `v0.0.0+${yield git.getRemoteSha(repo, ref)}`; + } + core.debug(`Build version ${version}`); let toolPath; - toolPath = tc.find('buildx', sha); + toolPath = tc.find('buildx', version); if (!toolPath) { const outFolder = path.join(context.tmpDir(), 'out').split(path.sep).join(path.posix.sep); toolPath = yield exec @@ -165,7 +171,7 @@ function build(inputBuildRef, dockerConfigHome) { if (res.stderr.length > 0 && res.exitCode != 0) { core.warning(res.stderr.trim()); } - return tc.cacheFile(`${outFolder}/buildx`, context.osPlat == 'win32' ? 'docker-buildx.exe' : 'docker-buildx', 'buildx', sha); + return tc.cacheFile(`${outFolder}/buildx`, context.osPlat == 'win32' ? 'docker-buildx.exe' : 'docker-buildx', 'buildx', version); }); } return setPlugin(toolPath, dockerConfigHome); diff --git a/src/buildx.ts b/src/buildx.ts index 97bb475d..46b52d72 100644 --- a/src/buildx.ts +++ b/src/buildx.ts @@ -117,11 +117,16 @@ export async function build(inputBuildRef: string, dockerConfigHome: string): Pr ref = 'master'; } - const sha = await git.getRemoteSha(repo, ref); - core.debug(`Remote ref ${sha} found`); + let version: string; + if (ref.match(/^[0-9a-fA-F]{40}$/)) { + version = `v0.0.0+${ref}`; + } else { + version = `v0.0.0+${await git.getRemoteSha(repo, ref)}`; + } + core.debug(`Build version ${version}`); let toolPath: string; - toolPath = tc.find('buildx', sha); + toolPath = tc.find('buildx', version); if (!toolPath) { const outFolder = path.join(context.tmpDir(), 'out').split(path.sep).join(path.posix.sep); toolPath = await exec @@ -132,7 +137,7 @@ export async function build(inputBuildRef: string, dockerConfigHome: string): Pr if (res.stderr.length > 0 && res.exitCode != 0) { core.warning(res.stderr.trim()); } - return tc.cacheFile(`${outFolder}/buildx`, context.osPlat == 'win32' ? 'docker-buildx.exe' : 'docker-buildx', 'buildx', sha); + return tc.cacheFile(`${outFolder}/buildx`, context.osPlat == 'win32' ? 'docker-buildx.exe' : 'docker-buildx', 'buildx', version); }); }