Merge pull request #257 from crazy-max/buildx-install-nocache-opt
Some checks failed
publish / publish (push) Has been cancelled
Some checks failed
publish / publish (push) Has been cancelled
buildx: ghaNoCache opt for download/build to disable binary cache
This commit is contained in:
@@ -67,6 +67,17 @@ describe('download', () => {
|
|||||||
expect(fs.existsSync(toolPath)).toBe(true);
|
expect(fs.existsSync(toolPath)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// prettier-ignore
|
||||||
|
test.each([
|
||||||
|
['v0.11.2'],
|
||||||
|
['v0.12.0'],
|
||||||
|
])(
|
||||||
|
'acquires %p of buildx without cache', async (version) => {
|
||||||
|
const install = new Install({standalone: false});
|
||||||
|
const toolPath = await install.download(version, true);
|
||||||
|
expect(fs.existsSync(toolPath)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
// TODO: add tests for arm
|
// TODO: add tests for arm
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
test.each([
|
test.each([
|
||||||
|
|||||||
@@ -47,10 +47,11 @@ export class Install {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Download buildx binary from GitHub release
|
* Download buildx binary from GitHub release
|
||||||
* @param version semver version or latest
|
* @param v: version semver version or latest
|
||||||
|
* @param ghaNoCache: disable binary caching in GitHub Actions cache backend
|
||||||
* @returns path to the buildx binary
|
* @returns path to the buildx binary
|
||||||
*/
|
*/
|
||||||
public async download(v: string): Promise<string> {
|
public async download(v: string, ghaNoCache?: boolean): Promise<string> {
|
||||||
const version: DownloadVersion = await Install.getDownloadVersion(v);
|
const version: DownloadVersion = await Install.getDownloadVersion(v);
|
||||||
core.debug(`Install.download version: ${version.version}`);
|
core.debug(`Install.download version: ${version.version}`);
|
||||||
|
|
||||||
@@ -69,7 +70,8 @@ export class Install {
|
|||||||
htcName: version.key != 'official' ? `buildx-dl-bin-${version.key}` : 'buildx-dl-bin',
|
htcName: version.key != 'official' ? `buildx-dl-bin-${version.key}` : 'buildx-dl-bin',
|
||||||
htcVersion: vspec,
|
htcVersion: vspec,
|
||||||
baseCacheDir: path.join(Buildx.configDir, '.bin'),
|
baseCacheDir: path.join(Buildx.configDir, '.bin'),
|
||||||
cacheFile: os.platform() == 'win32' ? 'docker-buildx.exe' : 'docker-buildx'
|
cacheFile: os.platform() == 'win32' ? 'docker-buildx.exe' : 'docker-buildx',
|
||||||
|
ghaNoCache: ghaNoCache
|
||||||
});
|
});
|
||||||
|
|
||||||
const cacheFoundPath = await installCache.find();
|
const cacheFoundPath = await installCache.find();
|
||||||
@@ -91,10 +93,11 @@ export class Install {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Build buildx binary from source
|
* Build buildx binary from source
|
||||||
* @param gitContext git repo context
|
* @param gitContext: git repo context
|
||||||
|
* @param ghaNoCache: disable binary caching in GitHub Actions cache backend
|
||||||
* @returns path to the buildx binary
|
* @returns path to the buildx binary
|
||||||
*/
|
*/
|
||||||
public async build(gitContext: string): Promise<string> {
|
public async build(gitContext: string, ghaNoCache?: boolean): Promise<string> {
|
||||||
const vspec = await this.vspec(gitContext);
|
const vspec = await this.vspec(gitContext);
|
||||||
core.debug(`Install.build vspec: ${vspec}`);
|
core.debug(`Install.build vspec: ${vspec}`);
|
||||||
|
|
||||||
@@ -102,7 +105,8 @@ export class Install {
|
|||||||
htcName: 'buildx-build-bin',
|
htcName: 'buildx-build-bin',
|
||||||
htcVersion: vspec,
|
htcVersion: vspec,
|
||||||
baseCacheDir: path.join(Buildx.configDir, '.bin'),
|
baseCacheDir: path.join(Buildx.configDir, '.bin'),
|
||||||
cacheFile: os.platform() == 'win32' ? 'docker-buildx.exe' : 'docker-buildx'
|
cacheFile: os.platform() == 'win32' ? 'docker-buildx.exe' : 'docker-buildx',
|
||||||
|
ghaNoCache: ghaNoCache
|
||||||
});
|
});
|
||||||
|
|
||||||
const cacheFoundPath = await installCache.find();
|
const cacheFoundPath = await installCache.find();
|
||||||
|
|||||||
@@ -27,17 +27,20 @@ export interface CacheOpts {
|
|||||||
htcVersion: string;
|
htcVersion: string;
|
||||||
baseCacheDir: string;
|
baseCacheDir: string;
|
||||||
cacheFile: string;
|
cacheFile: string;
|
||||||
|
ghaNoCache?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Cache {
|
export class Cache {
|
||||||
private readonly opts: CacheOpts;
|
private readonly opts: CacheOpts;
|
||||||
private readonly ghaCacheKey: string;
|
private readonly ghaCacheKey: string;
|
||||||
|
private readonly ghaNoCache?: boolean;
|
||||||
private readonly cacheDir: string;
|
private readonly cacheDir: string;
|
||||||
private readonly cachePath: string;
|
private readonly cachePath: string;
|
||||||
|
|
||||||
constructor(opts: CacheOpts) {
|
constructor(opts: CacheOpts) {
|
||||||
this.opts = opts;
|
this.opts = opts;
|
||||||
this.ghaCacheKey = util.format('%s-%s-%s', this.opts.htcName, this.opts.htcVersion, this.platform());
|
this.ghaCacheKey = util.format('%s-%s-%s', this.opts.htcName, this.opts.htcVersion, this.platform());
|
||||||
|
this.ghaNoCache = this.opts.ghaNoCache;
|
||||||
this.cacheDir = path.join(this.opts.baseCacheDir, this.opts.htcVersion, this.platform());
|
this.cacheDir = path.join(this.opts.baseCacheDir, this.opts.htcVersion, this.platform());
|
||||||
this.cachePath = path.join(this.cacheDir, this.opts.cacheFile);
|
this.cachePath = path.join(this.cacheDir, this.opts.cacheFile);
|
||||||
if (!fs.existsSync(this.cacheDir)) {
|
if (!fs.existsSync(this.cacheDir)) {
|
||||||
@@ -52,7 +55,7 @@ export class Cache {
|
|||||||
const htcPath = await tc.cacheDir(this.cacheDir, this.opts.htcName, this.opts.htcVersion, this.platform());
|
const htcPath = await tc.cacheDir(this.cacheDir, this.opts.htcName, this.opts.htcVersion, this.platform());
|
||||||
core.debug(`Cache.save cached to hosted tool cache ${htcPath}`);
|
core.debug(`Cache.save cached to hosted tool cache ${htcPath}`);
|
||||||
|
|
||||||
if (cache.isFeatureAvailable()) {
|
if (!this.ghaNoCache && cache.isFeatureAvailable()) {
|
||||||
core.debug(`Cache.save caching ${this.ghaCacheKey} to GitHub Actions cache`);
|
core.debug(`Cache.save caching ${this.ghaCacheKey} to GitHub Actions cache`);
|
||||||
await cache.saveCache([this.cacheDir], this.ghaCacheKey);
|
await cache.saveCache([this.cacheDir], this.ghaCacheKey);
|
||||||
}
|
}
|
||||||
@@ -67,7 +70,7 @@ export class Cache {
|
|||||||
return this.copyToCache(`${htcPath}/${this.opts.cacheFile}`);
|
return this.copyToCache(`${htcPath}/${this.opts.cacheFile}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cache.isFeatureAvailable()) {
|
if (!this.ghaNoCache && cache.isFeatureAvailable()) {
|
||||||
core.debug(`GitHub Actions cache feature available`);
|
core.debug(`GitHub Actions cache feature available`);
|
||||||
if (await cache.restoreCache([this.cacheDir], this.ghaCacheKey)) {
|
if (await cache.restoreCache([this.cacheDir], this.ghaCacheKey)) {
|
||||||
core.info(`Restored ${this.ghaCacheKey} from GitHub Actions cache`);
|
core.info(`Restored ${this.ghaCacheKey} from GitHub Actions cache`);
|
||||||
@@ -75,6 +78,8 @@ export class Cache {
|
|||||||
core.info(`Restored to hosted tool cache ${htcPath}`);
|
core.info(`Restored to hosted tool cache ${htcPath}`);
|
||||||
return this.copyToCache(`${htcPath}/${this.opts.cacheFile}`);
|
return this.copyToCache(`${htcPath}/${this.opts.cacheFile}`);
|
||||||
}
|
}
|
||||||
|
} else if (this.ghaNoCache) {
|
||||||
|
core.info(`GitHub Actions cache disabled`);
|
||||||
} else {
|
} else {
|
||||||
core.info(`GitHub Actions cache feature not available`);
|
core.info(`GitHub Actions cache feature not available`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user