mirror of
https://github.com/docker/build-push-action.git
synced 2025-04-19 01:46:45 +00:00
Remove GitHub Cache support for now (future release or buildkit cache provider?)
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
2962fe9789
commit
44d05b9191
9 changed files with 32 additions and 54196 deletions
|
@ -17,7 +17,6 @@ export interface Inputs {
|
|||
outputs: string[];
|
||||
cacheFrom: string[];
|
||||
cacheTo: string[];
|
||||
cacheGithub: boolean;
|
||||
}
|
||||
|
||||
export async function getInputs(): Promise<Inputs> {
|
||||
|
@ -37,8 +36,7 @@ export async function getInputs(): Promise<Inputs> {
|
|||
push: /true/i.test(core.getInput('push')),
|
||||
outputs: await getInputList('outputs'),
|
||||
cacheFrom: await getInputList('cache-from'),
|
||||
cacheTo: await getInputList('cache-to'),
|
||||
cacheGithub: /true/i.test(core.getInput('cache-github'))
|
||||
cacheTo: await getInputList('cache-to')
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import {Inputs} from './context';
|
||||
import * as stateHelper from './state-helper';
|
||||
import * as cache from '@actions/cache';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
const cachePath = path.join(os.tmpdir(), 'docker-build-push');
|
||||
|
||||
export async function restoreCache(inputs: Inputs): Promise<Inputs> {
|
||||
if (!inputs.cacheGithub) {
|
||||
return inputs;
|
||||
}
|
||||
|
||||
const primaryKey = `${process.env.RUNNER_OS}-docker-build-push-${process.env.GITHUB_SHA}`;
|
||||
stateHelper.setCachePrimaryKey(primaryKey);
|
||||
|
||||
try {
|
||||
const cacheKey = await cache.restoreCache([cachePath], primaryKey, [`${process.env.RUNNER_OS}-docker-build-push-`]);
|
||||
|
||||
if (!cacheKey) {
|
||||
core.info(`GitHub Cache not found for key: ${primaryKey}`);
|
||||
} else {
|
||||
inputs.cacheFrom = [`type=local,src=${cachePath}`];
|
||||
stateHelper.setCacheMatchedKey(cacheKey);
|
||||
core.info(`GitHub Cache restored from key: ${cacheKey}`);
|
||||
}
|
||||
|
||||
inputs.cacheTo = [`type=local,dest=${cachePath}`];
|
||||
return inputs;
|
||||
} catch (err) {
|
||||
if (err.name === cache.ValidationError.name) {
|
||||
throw err;
|
||||
} else {
|
||||
core.warning(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
return inputs;
|
||||
}
|
||||
|
||||
export async function saveCache(inputs: Inputs): Promise<void> {
|
||||
if (!inputs.cacheGithub) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!stateHelper.cachePrimaryKey) {
|
||||
core.warning(`Error retrieving GitHub Cache key from state.`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (stateHelper.isExactKeyMatch(stateHelper.cachePrimaryKey, stateHelper.cacheMatchedKey)) {
|
||||
core.info(`GitHub Cache hit occurred on the primary key ${stateHelper.cachePrimaryKey}, not saving cache.`);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await cache.saveCache([cachePath], stateHelper.cachePrimaryKey);
|
||||
} catch (err) {
|
||||
if (err.name === cache.ValidationError.name) {
|
||||
throw err;
|
||||
} else if (err.name === cache.ReserveCacheError.name) {
|
||||
core.info(err.message);
|
||||
} else {
|
||||
core.warning(err.message);
|
||||
}
|
||||
}
|
||||
}
|
14
src/main.ts
14
src/main.ts
|
@ -1,8 +1,6 @@
|
|||
import * as os from 'os';
|
||||
import * as buildx from './buildx';
|
||||
import {Inputs, getInputs, getArgs} from './context';
|
||||
import * as github from './github';
|
||||
import * as stateHelper from './state-helper';
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
|
||||
|
@ -23,7 +21,6 @@ async function run(): Promise<void> {
|
|||
core.info(`📌 Using builder instance ${inputs.builder}`);
|
||||
await buildx.use(inputs.builder);
|
||||
}
|
||||
inputs = await github.restoreCache(inputs);
|
||||
|
||||
core.info(`🏃 Starting build...`);
|
||||
const args: string[] = await getArgs(inputs);
|
||||
|
@ -33,13 +30,4 @@ async function run(): Promise<void> {
|
|||
}
|
||||
}
|
||||
|
||||
async function post(): Promise<void> {
|
||||
const inputs: Inputs = await getInputs();
|
||||
await github.saveCache(inputs);
|
||||
}
|
||||
|
||||
if (!stateHelper.IsPost) {
|
||||
run();
|
||||
} else {
|
||||
post();
|
||||
}
|
||||
run();
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
import * as core from '@actions/core';
|
||||
|
||||
export const IsPost = !!process.env['STATE_isPost'];
|
||||
export const cachePrimaryKey = process.env['STATE_cachePrimaryKey'] || '';
|
||||
export const cacheMatchedKey = process.env['STATE_cacheMatchedKey'] || '';
|
||||
|
||||
export function setCachePrimaryKey(cachePrimaryKey: string) {
|
||||
core.saveState('cachePrimaryKey', cachePrimaryKey);
|
||||
}
|
||||
|
||||
export function setCacheMatchedKey(cacheMatchedKey: string) {
|
||||
core.saveState('cacheMatchedKey', cacheMatchedKey);
|
||||
}
|
||||
|
||||
export function isExactKeyMatch(key: string, cacheKey?: string): boolean {
|
||||
return !!(
|
||||
cacheKey &&
|
||||
cacheKey.localeCompare(key, undefined, {
|
||||
sensitivity: 'accent'
|
||||
}) === 0
|
||||
);
|
||||
}
|
||||
|
||||
if (!IsPost) {
|
||||
core.saveState('isPost', 'true');
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue