mirror of
https://github.com/actions/setup-go.git
synced 2025-04-24 01:50:52 +00:00
Use semver for gitDir cache
This commit is contained in:
parent
4fbc5a7020
commit
c087bf9a31
2 changed files with 16 additions and 11 deletions
|
@ -25,8 +25,8 @@ beforeAll(cleanup, 100000);
|
|||
afterAll(cleanup, 100000);
|
||||
|
||||
const describeTable = describe.each([
|
||||
['tip', '+60f14fd', 'go1.13beta1', '60f14fddfee107dedd76c0be6b422a3d8ccc841a'],
|
||||
['tip', '+a5bfd9d', 'go1.14beta1', 'a5bfd9da1d1b24f326399b6b75558ded14514f23'],
|
||||
['tip', '+60f14fd', 'go1.13beta1', '0.0.0-devel.60f14fddfee107dedd76c0be6b422a3d8ccc841a'],
|
||||
['tip', '+a5bfd9d', 'go1.14beta1', '0.0.0-devel.a5bfd9da1d1b24f326399b6b75558ded14514f23'],
|
||||
['latest', 'go1.13', 'n/a', '1.13.0'],
|
||||
['1.x', 'go1.13', 'n/a', '1.13.0'],
|
||||
['1.10.x', 'go1.10.8', 'n/a', '1.10.8'],
|
||||
|
@ -64,14 +64,14 @@ describeTable('Go %s (%s)', (version: string, goVersion: string, gitRef: string,
|
|||
}, timeout);
|
||||
|
||||
if (gotip) {
|
||||
const gitDir = path.join(toolDir, cacheDir, 'master', '');
|
||||
const gitDir = path.join(toolDir, cacheDir, '0.0.0-devel', 'noarch');
|
||||
test('git cache check', async () => {
|
||||
const promise = fs.promises.access(gitDir);
|
||||
await expect(promise).resolves.toBeUndefined();
|
||||
});
|
||||
}
|
||||
|
||||
test('tool executable check', async () => {
|
||||
test('tool existence check', async () => {
|
||||
const promise = fs.promises.access(goTool);
|
||||
await expect(promise).resolves.toBeUndefined();
|
||||
});
|
||||
|
|
|
@ -63,8 +63,7 @@ async function acquireGo(version: string, gotipRef: string, bootstrapGo: string)
|
|||
let workTree: string;
|
||||
let commitHash: string;
|
||||
// Avoid cloning multiple times by caching git dir.
|
||||
// Empty string means that we don’t care about arch.
|
||||
gitDir = tc.find('gotip', 'master', '')
|
||||
gitDir = tc.find('gotip', '0.0.0-devel', 'noarch');
|
||||
if (!gitDir) {
|
||||
gitDir = path.join(extPath, 'gotip.git');
|
||||
workTree = path.join(extPath, filename);
|
||||
|
@ -74,6 +73,13 @@ async function acquireGo(version: string, gotipRef: string, bootstrapGo: string)
|
|||
|
||||
// Extract current commit hash.
|
||||
commitHash = await executil.gitRevParse(gitDir, 'HEAD');
|
||||
|
||||
// Add cache for git dir. Note that in the current tool-cache
|
||||
// implementation adding result of find to the cache actually
|
||||
// purges both. That is, we can’t update the cache explicitly
|
||||
// and tool-cache assumes we won’t change tool in the cache.
|
||||
// And in the other branch we break that assumption.
|
||||
gitDir = await tc.cacheDir(gitDir, 'gotip', '0.0.0-devel', 'noarch');
|
||||
} else {
|
||||
// We don’t have a work tree (yet) in this case.
|
||||
workTree = '';
|
||||
|
@ -84,11 +90,9 @@ async function acquireGo(version: string, gotipRef: string, bootstrapGo: string)
|
|||
// Extract latest commit hash.
|
||||
commitHash = await executil.gitRevParse(gitDir, 'FETCH_HEAD');
|
||||
}
|
||||
// Update cache for git dir.
|
||||
gitDir = await tc.cacheDir(gitDir, 'gotip', 'master', '');
|
||||
|
||||
// Avoid building multiple times by caching work tree.
|
||||
let workTreeCache = tc.find('gotip', commitHash);
|
||||
let workTreeCache = tc.find('gotip', `0.0.0-devel.${commitHash}`);
|
||||
if (workTreeCache) {
|
||||
workTree = workTreeCache;
|
||||
} else {
|
||||
|
@ -140,8 +144,9 @@ async function acquireGo(version: string, gotipRef: string, bootstrapGo: string)
|
|||
cmd = 'make.bat';
|
||||
}
|
||||
await exec.exec(cmd, undefined, { cwd, env });
|
||||
// Update cache for work tree.
|
||||
workTree = await tc.cacheDir(workTree, 'gotip', commitHash);
|
||||
|
||||
// Add cache for work tree.
|
||||
workTree = await tc.cacheDir(workTree, 'gotip', `0.0.0-devel.${commitHash}`);
|
||||
}
|
||||
toolRoot = workTree;
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue