Add env fallback for GCS cache bucket

pull/1786/head
Jasperhino 2 months ago
parent 5ed4dd939d
commit 993ce21c74

@ -203,6 +203,40 @@ test("getInputAsBool throws if required and value missing", () => {
).toThrowError();
});
test("getGCSBucket returns gcs-bucket input when provided", () => {
try {
testUtils.setInput("gcs-bucket", "input-bucket");
process.env["CULA_CACHE_GCS_BUCKET"] = "env-bucket";
expect(actionUtils.getGCSBucket()).toBe("input-bucket");
} finally {
testUtils.clearInputs();
delete process.env["CULA_CACHE_GCS_BUCKET"];
}
});
test("getGCSBucket falls back to CULA_CACHE_GCS_BUCKET", () => {
try {
process.env["CULA_CACHE_GCS_BUCKET"] = "env-bucket";
expect(actionUtils.getGCSBucket()).toBe("env-bucket");
} finally {
delete process.env["CULA_CACHE_GCS_BUCKET"];
}
});
test("getGCSBucket returns empty string without input or environment variable", () => {
try {
testUtils.clearInputs();
delete process.env["CULA_CACHE_GCS_BUCKET"];
expect(actionUtils.getGCSBucket()).toBe("");
} finally {
testUtils.clearInputs();
delete process.env["CULA_CACHE_GCS_BUCKET"];
}
});
test("isCacheFeatureAvailable for ac enabled", () => {
jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => true);

@ -27,7 +27,7 @@ inputs:
default: 'false'
required: false
gcs-bucket:
description: 'Google Cloud Storage bucket name to use for caching. When provided, GCS will be used as the cache backend.'
description: 'Google Cloud Storage bucket name to use for caching. When provided, GCS will be used as the cache backend. Defaults to the CULA_CACHE_GCS_BUCKET environment variable when omitted.'
required: false
gcs-path-prefix:
description: 'Optional prefix path within the GCS bucket for cache files'

@ -78328,6 +78328,7 @@ exports.isValidEvent = isValidEvent;
exports.getInputAsArray = getInputAsArray;
exports.getInputAsInt = getInputAsInt;
exports.getInputAsBool = getInputAsBool;
exports.getGCSBucket = getGCSBucket;
exports.isGCSAvailable = isGCSAvailable;
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
const cache = __importStar(__nccwpck_require__(5116));
@ -78374,10 +78375,13 @@ function getInputAsBool(name, options) {
const result = core.getInput(name, options);
return result.toLowerCase() === "true";
}
function getGCSBucket() {
return core.getInput(constants_1.Inputs.GCSBucket) || process.env["CULA_CACHE_GCS_BUCKET"] || "";
}
// Check if GCS is configured and available
function isGCSAvailable() {
try {
const bucket = core.getInput(constants_1.Inputs.GCSBucket);
const bucket = getGCSBucket();
if (!bucket) {
core.info("GCS bucket name not provided, falling back to GitHub cache");
return false;
@ -78548,7 +78552,7 @@ function restoreFromGCS(_paths_1, primaryKey_1) {
if (!storage) {
return undefined;
}
const bucket = core.getInput(constants_1.Inputs.GCSBucket);
const bucket = (0, actionUtils_1.getGCSBucket)();
const pathPrefix = core.getInput(constants_1.Inputs.GCSPathPrefix) || DEFAULT_PATH_PREFIX;
const compressionMethod = yield utils.getCompressionMethod();
const archiveFolder = yield utils.createTempDirectory();
@ -78605,7 +78609,7 @@ function saveToGCS(paths, key) {
if (!storage) {
return undefined;
}
const bucket = core.getInput(constants_1.Inputs.GCSBucket);
const bucket = (0, actionUtils_1.getGCSBucket)();
const pathPrefix = core.getInput(constants_1.Inputs.GCSPathPrefix) || DEFAULT_PATH_PREFIX;
const compressionMethod = yield utils.getCompressionMethod();
const cachePaths = yield utils.resolvePaths(paths);

@ -78328,6 +78328,7 @@ exports.isValidEvent = isValidEvent;
exports.getInputAsArray = getInputAsArray;
exports.getInputAsInt = getInputAsInt;
exports.getInputAsBool = getInputAsBool;
exports.getGCSBucket = getGCSBucket;
exports.isGCSAvailable = isGCSAvailable;
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
const cache = __importStar(__nccwpck_require__(5116));
@ -78374,10 +78375,13 @@ function getInputAsBool(name, options) {
const result = core.getInput(name, options);
return result.toLowerCase() === "true";
}
function getGCSBucket() {
return core.getInput(constants_1.Inputs.GCSBucket) || process.env["CULA_CACHE_GCS_BUCKET"] || "";
}
// Check if GCS is configured and available
function isGCSAvailable() {
try {
const bucket = core.getInput(constants_1.Inputs.GCSBucket);
const bucket = getGCSBucket();
if (!bucket) {
core.info("GCS bucket name not provided, falling back to GitHub cache");
return false;
@ -78548,7 +78552,7 @@ function restoreFromGCS(_paths_1, primaryKey_1) {
if (!storage) {
return undefined;
}
const bucket = core.getInput(constants_1.Inputs.GCSBucket);
const bucket = (0, actionUtils_1.getGCSBucket)();
const pathPrefix = core.getInput(constants_1.Inputs.GCSPathPrefix) || DEFAULT_PATH_PREFIX;
const compressionMethod = yield utils.getCompressionMethod();
const archiveFolder = yield utils.createTempDirectory();
@ -78605,7 +78609,7 @@ function saveToGCS(paths, key) {
if (!storage) {
return undefined;
}
const bucket = core.getInput(constants_1.Inputs.GCSBucket);
const bucket = (0, actionUtils_1.getGCSBucket)();
const pathPrefix = core.getInput(constants_1.Inputs.GCSPathPrefix) || DEFAULT_PATH_PREFIX;
const compressionMethod = yield utils.getCompressionMethod();
const cachePaths = yield utils.resolvePaths(paths);

@ -78341,6 +78341,7 @@ exports.isValidEvent = isValidEvent;
exports.getInputAsArray = getInputAsArray;
exports.getInputAsInt = getInputAsInt;
exports.getInputAsBool = getInputAsBool;
exports.getGCSBucket = getGCSBucket;
exports.isGCSAvailable = isGCSAvailable;
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
const cache = __importStar(__nccwpck_require__(5116));
@ -78387,10 +78388,13 @@ function getInputAsBool(name, options) {
const result = core.getInput(name, options);
return result.toLowerCase() === "true";
}
function getGCSBucket() {
return core.getInput(constants_1.Inputs.GCSBucket) || process.env["CULA_CACHE_GCS_BUCKET"] || "";
}
// Check if GCS is configured and available
function isGCSAvailable() {
try {
const bucket = core.getInput(constants_1.Inputs.GCSBucket);
const bucket = getGCSBucket();
if (!bucket) {
core.info("GCS bucket name not provided, falling back to GitHub cache");
return false;
@ -78561,7 +78565,7 @@ function restoreFromGCS(_paths_1, primaryKey_1) {
if (!storage) {
return undefined;
}
const bucket = core.getInput(constants_1.Inputs.GCSBucket);
const bucket = (0, actionUtils_1.getGCSBucket)();
const pathPrefix = core.getInput(constants_1.Inputs.GCSPathPrefix) || DEFAULT_PATH_PREFIX;
const compressionMethod = yield utils.getCompressionMethod();
const archiveFolder = yield utils.createTempDirectory();
@ -78618,7 +78622,7 @@ function saveToGCS(paths, key) {
if (!storage) {
return undefined;
}
const bucket = core.getInput(constants_1.Inputs.GCSBucket);
const bucket = (0, actionUtils_1.getGCSBucket)();
const pathPrefix = core.getInput(constants_1.Inputs.GCSPathPrefix) || DEFAULT_PATH_PREFIX;
const compressionMethod = yield utils.getCompressionMethod();
const cachePaths = yield utils.resolvePaths(paths);

10
dist/save/index.js vendored

@ -78341,6 +78341,7 @@ exports.isValidEvent = isValidEvent;
exports.getInputAsArray = getInputAsArray;
exports.getInputAsInt = getInputAsInt;
exports.getInputAsBool = getInputAsBool;
exports.getGCSBucket = getGCSBucket;
exports.isGCSAvailable = isGCSAvailable;
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
const cache = __importStar(__nccwpck_require__(5116));
@ -78387,10 +78388,13 @@ function getInputAsBool(name, options) {
const result = core.getInput(name, options);
return result.toLowerCase() === "true";
}
function getGCSBucket() {
return core.getInput(constants_1.Inputs.GCSBucket) || process.env["CULA_CACHE_GCS_BUCKET"] || "";
}
// Check if GCS is configured and available
function isGCSAvailable() {
try {
const bucket = core.getInput(constants_1.Inputs.GCSBucket);
const bucket = getGCSBucket();
if (!bucket) {
core.info("GCS bucket name not provided, falling back to GitHub cache");
return false;
@ -78561,7 +78565,7 @@ function restoreFromGCS(_paths_1, primaryKey_1) {
if (!storage) {
return undefined;
}
const bucket = core.getInput(constants_1.Inputs.GCSBucket);
const bucket = (0, actionUtils_1.getGCSBucket)();
const pathPrefix = core.getInput(constants_1.Inputs.GCSPathPrefix) || DEFAULT_PATH_PREFIX;
const compressionMethod = yield utils.getCompressionMethod();
const archiveFolder = yield utils.createTempDirectory();
@ -78618,7 +78622,7 @@ function saveToGCS(paths, key) {
if (!storage) {
return undefined;
}
const bucket = core.getInput(constants_1.Inputs.GCSBucket);
const bucket = (0, actionUtils_1.getGCSBucket)();
const pathPrefix = core.getInput(constants_1.Inputs.GCSPathPrefix) || DEFAULT_PATH_PREFIX;
const compressionMethod = yield utils.getCompressionMethod();
const cachePaths = yield utils.resolvePaths(paths);

@ -24,7 +24,7 @@ inputs:
default: 'false'
required: false
gcs-bucket:
description: 'Google Cloud Storage bucket name to use for caching. When provided, GCS will be used as the cache backend.'
description: 'Google Cloud Storage bucket name to use for caching. When provided, GCS will be used as the cache backend. Defaults to the CULA_CACHE_GCS_BUCKET environment variable when omitted.'
required: false
gcs-path-prefix:
description: 'Optional prefix path within the GCS bucket for cache files'

@ -16,7 +16,7 @@ inputs:
default: 'false'
required: false
gcs-bucket:
description: 'Google Cloud Storage bucket name to use for caching. When provided, GCS will be used as the cache backend.'
description: 'Google Cloud Storage bucket name to use for caching. When provided, GCS will be used as the cache backend. Defaults to the CULA_CACHE_GCS_BUCKET environment variable when omitted.'
required: false
gcs-path-prefix:
description: 'Optional prefix path within the GCS bucket for cache files'

@ -66,10 +66,14 @@ export function getInputAsBool(
return result.toLowerCase() === "true";
}
export function getGCSBucket(): string {
return core.getInput(Inputs.GCSBucket) || process.env["CULA_CACHE_GCS_BUCKET"] || "";
}
// Check if GCS is configured and available
export function isGCSAvailable(): boolean {
try {
const bucket = core.getInput(Inputs.GCSBucket);
const bucket = getGCSBucket();
if (!bucket) {
core.info(
"GCS bucket name not provided, falling back to GitHub cache"

@ -12,7 +12,7 @@ import { Storage } from "@google-cloud/storage";
import * as path from "path";
import { Inputs } from "../constants";
import { isGCSAvailable } from "./actionUtils";
import { getGCSBucket, isGCSAvailable } from "./actionUtils";
const DEFAULT_PATH_PREFIX = "github-cache";
@ -116,7 +116,7 @@ async function restoreFromGCS(
return undefined;
}
const bucket = core.getInput(Inputs.GCSBucket);
const bucket = getGCSBucket();
const pathPrefix =
core.getInput(Inputs.GCSPathPrefix) || DEFAULT_PATH_PREFIX;
const compressionMethod = await utils.getCompressionMethod();
@ -202,7 +202,7 @@ async function saveToGCS(
return undefined;
}
const bucket = core.getInput(Inputs.GCSBucket);
const bucket = getGCSBucket();
const pathPrefix =
core.getInput(Inputs.GCSPathPrefix) || DEFAULT_PATH_PREFIX;
const compressionMethod = await utils.getCompressionMethod();

@ -42,4 +42,5 @@ export function clearInputs(): void {
delete process.env[getInputName(Inputs.EnableCrossOsArchive)];
delete process.env[getInputName(Inputs.FailOnCacheMiss)];
delete process.env[getInputName(Inputs.LookupOnly)];
delete process.env[getInputName(Inputs.GCSBucket)];
}

Loading…
Cancel
Save