Skip to content

Commit

Permalink
feat(keyFileName): allow to pass key file name
Browse files Browse the repository at this point in the history
  • Loading branch information
kopax committed Nov 22, 2023
1 parent b1deb1d commit 1a84963
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/main/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/post/index.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ export interface Inputs {
path: string;
key: string;
restoreKeys: string[];
keyFileName?: string;
compressionMethod?: string;
}

export function getInputs(): Inputs {
const inputs = {
bucket: core.getInput('bucket', { required: true }),
path: core.getInput('path', { required: true }),
key: core.getInput('key', { required: true }),
keyFileName: core.getInput('key-file-name'),
compressionMethod: core.getInput('compression-method'),
restoreKeys: core
.getInput('restore-keys')
.split(',')
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ async function main() {
path: inputs.path,
cacheHitKind: 'none',
targetFileName: exactFileName,
keyFileName: inputs.keyFileName,
});
core.setOutput('cache-hit', 'false');
console.log('😢 No cache candidate found.');
Expand Down
4 changes: 3 additions & 1 deletion src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ async function main() {
return;
}

const bucket = new Storage().bucket(state.bucket);
const bucket = new Storage({ keyFilename: state.keyFileName }).bucket(
state.bucket,
);
const targetFileName = state.targetFileName;
const [targetFileExists] = await bucket
.file(targetFileName)
Expand Down
6 changes: 6 additions & 0 deletions src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export interface State {
bucket: string;
cacheHitKind: CacheHitKindState;
targetFileName: string;
keyFileName?: string;
compressionMethod?: string;
}

export function saveState(state: State): void {
Expand All @@ -16,6 +18,8 @@ export function saveState(state: State): void {
core.saveState('path', state.path);
core.saveState('cache-hit-kind', state.cacheHitKind);
core.saveState('target-file-name', state.targetFileName);
core.saveState('key-file-name', state.keyFileName);
core.saveState('compression-method', state.compressionMethod);
}

export function getState(): State {
Expand All @@ -24,6 +28,8 @@ export function getState(): State {
bucket: core.getState('bucket'),
cacheHitKind: core.getState('cache-hit-kind') as CacheHitKindState,
targetFileName: core.getState('target-file-name'),
keyFileName: core.getState('key-file-name'),
compressionMethod: core.getState('compression-method'),
};

core.debug(`Loaded state: ${JSON.stringify(state)}.`);
Expand Down
7 changes: 7 additions & 0 deletions src/tar-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import * as exec from '@actions/exec';
import * as semver from 'semver';

import { getState } from './state';

const ZSTD_WITHOUT_LONG_VERSION = '1.3.2';

export enum CompressionMethod {
Expand All @@ -15,6 +17,11 @@ async function getTarCompressionMethod(): Promise<CompressionMethod> {
if (process.platform === 'win32') {
return CompressionMethod.GZIP;
}
const state = getState();

if (state.compressionMethod) {
return CompressionMethod.GZIP;
}

const [zstdOutput, zstdVersion] = await exec
.getExecOutput('zstd', ['--version'], {
Expand Down

0 comments on commit 1a84963

Please sign in to comment.