Skip to content

Commit

Permalink
Add saveOnly entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
mattlewis92 committed Feb 5, 2024
1 parent 57f09e4 commit 6c87b0a
Show file tree
Hide file tree
Showing 9 changed files with 103,348 additions and 151 deletions.
68 changes: 67 additions & 1 deletion dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102749,12 +102749,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.isExactKeyMatch = exports.saveMatchedKey = exports.listObjects = exports.findObject = exports.setCacheSizeOutput = exports.setCacheHitOutput = exports.formatSize = exports.getInputAsInt = exports.getInputAsArray = exports.getInputAsBoolean = exports.newMinio = exports.getInput = exports.isGhes = void 0;
exports.saveCache = exports.isExactKeyMatch = exports.saveMatchedKey = exports.listObjects = exports.findObject = exports.setCacheSizeOutput = exports.setCacheHitOutput = exports.formatSize = exports.getInputAsInt = exports.getInputAsArray = exports.getInputAsBoolean = exports.newMinio = exports.getInput = exports.isGhes = void 0;
const utils = __importStar(__nccwpck_require__(1518));
const core = __importStar(__nccwpck_require__(2186));
const minio = __importStar(__nccwpck_require__(8308));
const state_1 = __nccwpck_require__(9738);
const path_1 = __importDefault(__nccwpck_require__(1017));
const tar_1 = __nccwpck_require__(6490);
const cache = __importStar(__nccwpck_require__(7799));
function isGhes() {
const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com");
return ghUrl.hostname.toUpperCase() !== "GITHUB.COM";
Expand Down Expand Up @@ -102889,6 +102895,66 @@ function isExactKeyMatch() {
return result;
}
exports.isExactKeyMatch = isExactKeyMatch;
function saveCache(standalone) {
return __awaiter(this, void 0, void 0, function* () {
try {
if (!standalone && isExactKeyMatch()) {
core.info("Cache was exact key match, not saving");
return;
}
const bucket = core.getInput("bucket", { required: true });
// Inputs are re-evaluted before the post action, so we want the original key
const key = standalone ? core.getInput("key", { required: true }) : core.getState(state_1.State.PrimaryKey);
const useFallback = getInputAsBoolean("use-fallback");
const paths = getInputAsArray("path");
try {
const mc = newMinio({
// Inputs are re-evaluted before the post action, so we want the original keys & tokens
accessKey: standalone ? getInput("accessKey", "AWS_ACCESS_KEY_ID") : core.getState(state_1.State.AccessKey),
secretKey: standalone ? getInput("secretKey", "AWS_SECRET_ACCESS_KEY") : core.getState(state_1.State.SecretKey),
sessionToken: standalone ? getInput("sessionToken", "AWS_SESSION_TOKEN") : core.getState(state_1.State.SessionToken),
region: standalone ? getInput("region", "AWS_REGION") : core.getState(state_1.State.Region),
});
const compressionMethod = yield utils.getCompressionMethod();
const cachePaths = yield utils.resolvePaths(paths);
core.debug("Cache Paths:");
core.debug(`${JSON.stringify(cachePaths)}`);
const archiveFolder = yield utils.createTempDirectory();
const cacheFileName = utils.getCacheFileName(compressionMethod);
const archivePath = path_1.default.join(archiveFolder, cacheFileName);
core.debug(`Archive Path: ${archivePath}`);
yield (0, tar_1.createTar)(archiveFolder, cachePaths, compressionMethod);
if (core.isDebug()) {
yield (0, tar_1.listTar)(archivePath, compressionMethod);
}
const object = path_1.default.join(key, cacheFileName);
core.info(`Uploading tar to s3. Bucket: ${bucket}, Object: ${object}`);
yield mc.fPutObject(bucket, object, archivePath, {});
core.info("Cache saved to s3 successfully");
}
catch (e) {
core.info("Save s3 cache failed: " + e.message);
if (useFallback) {
if (isGhes()) {
core.warning("Cache fallback is not supported on Github Enterpise.");
}
else {
core.info("Saving cache using fallback");
yield cache.saveCache(paths, key);
core.info("Save cache using fallback successfully");
}
}
else {
core.debug("skipped fallback cache");
}
}
}
catch (e) {
core.info("warning: " + e.message);
}
});
}
exports.saveCache = saveCache;


/***/ }),
Expand Down
143 changes: 68 additions & 75 deletions dist/save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102610,84 +102610,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const cache = __importStar(__nccwpck_require__(7799));
const utils = __importStar(__nccwpck_require__(1518));
const tar_1 = __nccwpck_require__(6490);
const core = __importStar(__nccwpck_require__(2186));
const path = __importStar(__nccwpck_require__(1017));
const state_1 = __nccwpck_require__(9738);
const utils_1 = __nccwpck_require__(1314);
process.on("uncaughtException", (e) => core.info("warning: " + e.message));
function saveCache() {
return __awaiter(this, void 0, void 0, function* () {
try {
if ((0, utils_1.isExactKeyMatch)()) {
core.info("Cache was exact key match, not saving");
return;
}
const bucket = core.getInput("bucket", { required: true });
// Inputs are re-evaluted before the post action, so we want the original key
const key = core.getState(state_1.State.PrimaryKey);
const useFallback = (0, utils_1.getInputAsBoolean)("use-fallback");
const paths = (0, utils_1.getInputAsArray)("path");
try {
const mc = (0, utils_1.newMinio)({
// Inputs are re-evaluted before the post action, so we want the original keys & tokens
accessKey: core.getState(state_1.State.AccessKey),
secretKey: core.getState(state_1.State.SecretKey),
sessionToken: core.getState(state_1.State.SessionToken),
region: core.getState(state_1.State.Region),
});
const compressionMethod = yield utils.getCompressionMethod();
const cachePaths = yield utils.resolvePaths(paths);
core.debug("Cache Paths:");
core.debug(`${JSON.stringify(cachePaths)}`);
const archiveFolder = yield utils.createTempDirectory();
const cacheFileName = utils.getCacheFileName(compressionMethod);
const archivePath = path.join(archiveFolder, cacheFileName);
core.debug(`Archive Path: ${archivePath}`);
yield (0, tar_1.createTar)(archiveFolder, cachePaths, compressionMethod);
if (core.isDebug()) {
yield (0, tar_1.listTar)(archivePath, compressionMethod);
}
const object = path.join(key, cacheFileName);
core.info(`Uploading tar to s3. Bucket: ${bucket}, Object: ${object}`);
yield mc.fPutObject(bucket, object, archivePath, {});
core.info("Cache saved to s3 successfully");
}
catch (e) {
core.info("Save s3 cache failed: " + e.message);
if (useFallback) {
if ((0, utils_1.isGhes)()) {
core.warning("Cache fallback is not supported on Github Enterpise.");
}
else {
core.info("Saving cache using fallback");
yield cache.saveCache(paths, key);
core.info("Save cache using fallback successfully");
}
}
else {
core.debug("skipped fallback cache");
}
}
}
catch (e) {
core.info("warning: " + e.message);
}
});
}
saveCache();
(0, utils_1.saveCache)(false);


/***/ }),
Expand Down Expand Up @@ -102749,12 +102676,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.isExactKeyMatch = exports.saveMatchedKey = exports.listObjects = exports.findObject = exports.setCacheSizeOutput = exports.setCacheHitOutput = exports.formatSize = exports.getInputAsInt = exports.getInputAsArray = exports.getInputAsBoolean = exports.newMinio = exports.getInput = exports.isGhes = void 0;
exports.saveCache = exports.isExactKeyMatch = exports.saveMatchedKey = exports.listObjects = exports.findObject = exports.setCacheSizeOutput = exports.setCacheHitOutput = exports.formatSize = exports.getInputAsInt = exports.getInputAsArray = exports.getInputAsBoolean = exports.newMinio = exports.getInput = exports.isGhes = void 0;
const utils = __importStar(__nccwpck_require__(1518));
const core = __importStar(__nccwpck_require__(2186));
const minio = __importStar(__nccwpck_require__(8308));
const state_1 = __nccwpck_require__(9738);
const path_1 = __importDefault(__nccwpck_require__(1017));
const tar_1 = __nccwpck_require__(6490);
const cache = __importStar(__nccwpck_require__(7799));
function isGhes() {
const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com");
return ghUrl.hostname.toUpperCase() !== "GITHUB.COM";
Expand Down Expand Up @@ -102889,6 +102822,66 @@ function isExactKeyMatch() {
return result;
}
exports.isExactKeyMatch = isExactKeyMatch;
function saveCache(standalone) {
return __awaiter(this, void 0, void 0, function* () {
try {
if (!standalone && isExactKeyMatch()) {
core.info("Cache was exact key match, not saving");
return;
}
const bucket = core.getInput("bucket", { required: true });
// Inputs are re-evaluted before the post action, so we want the original key
const key = standalone ? core.getInput("key", { required: true }) : core.getState(state_1.State.PrimaryKey);
const useFallback = getInputAsBoolean("use-fallback");
const paths = getInputAsArray("path");
try {
const mc = newMinio({
// Inputs are re-evaluted before the post action, so we want the original keys & tokens
accessKey: standalone ? getInput("accessKey", "AWS_ACCESS_KEY_ID") : core.getState(state_1.State.AccessKey),
secretKey: standalone ? getInput("secretKey", "AWS_SECRET_ACCESS_KEY") : core.getState(state_1.State.SecretKey),
sessionToken: standalone ? getInput("sessionToken", "AWS_SESSION_TOKEN") : core.getState(state_1.State.SessionToken),
region: standalone ? getInput("region", "AWS_REGION") : core.getState(state_1.State.Region),
});
const compressionMethod = yield utils.getCompressionMethod();
const cachePaths = yield utils.resolvePaths(paths);
core.debug("Cache Paths:");
core.debug(`${JSON.stringify(cachePaths)}`);
const archiveFolder = yield utils.createTempDirectory();
const cacheFileName = utils.getCacheFileName(compressionMethod);
const archivePath = path_1.default.join(archiveFolder, cacheFileName);
core.debug(`Archive Path: ${archivePath}`);
yield (0, tar_1.createTar)(archiveFolder, cachePaths, compressionMethod);
if (core.isDebug()) {
yield (0, tar_1.listTar)(archivePath, compressionMethod);
}
const object = path_1.default.join(key, cacheFileName);
core.info(`Uploading tar to s3. Bucket: ${bucket}, Object: ${object}`);
yield mc.fPutObject(bucket, object, archivePath, {});
core.info("Cache saved to s3 successfully");
}
catch (e) {
core.info("Save s3 cache failed: " + e.message);
if (useFallback) {
if (isGhes()) {
core.warning("Cache fallback is not supported on Github Enterpise.");
}
else {
core.info("Saving cache using fallback");
yield cache.saveCache(paths, key);
core.info("Save cache using fallback successfully");
}
}
else {
core.debug("skipped fallback cache");
}
}
}
catch (e) {
core.info("warning: " + e.message);
}
});
}
exports.saveCache = saveCache;


/***/ }),
Expand Down
Loading

0 comments on commit 6c87b0a

Please sign in to comment.