Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions dist/restore-only/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92559,7 +92559,7 @@ function restoreFromGCS(_paths_1, primaryKey_1) {
const archiveFolder = yield utils.createTempDirectory();
const archivePath = path.join(archiveFolder, utils.getCacheFileName(compressionMethod));
const keys = [primaryKey, ...restoreKeys];
const gcsPath = yield findFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod);
const gcsPath = yield findLatestFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod);
if (!gcsPath) {
core.info(`No matching cache found`);
return undefined;
Expand Down Expand Up @@ -92643,24 +92643,34 @@ function saveToGCS(paths, key) {
}
});
}
function findFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod) {
function findLatestFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod) {
return __awaiter(this, void 0, void 0, function* () {
let latestFile = undefined;
for (const key of keys) {
const gcsPath = getGCSPath(pathPrefix, key, compressionMethod);
if (yield checkFileExists(storage, bucket, gcsPath)) {
core.info(`Found file on bucket: ${bucket} with key: ${gcsPath}`);
return gcsPath;
const prefix = `${pathPrefix}/${key}`;
const [files] = yield storage.bucket(bucket).getFiles({ prefix });
for (const file of files) {
if (!file.name.endsWith(utils.getCacheFileName(compressionMethod)))
continue;
core.debug(`Found file: ${file.name} (created: ${file.metadata.timeCreated})`);
const created = file.metadata.timeCreated
? new Date(file.metadata.timeCreated)
: undefined;
if (!created) {
continue;
}
if (!latestFile || created > latestFile.updated) {
latestFile = { path: file.name, updated: created };
}
}
}
if (latestFile) {
core.info(`Use cache: ${latestFile.path} from GCS bucket ${bucket}`);
return latestFile.path;
}
return undefined;
});
}
function checkFileExists(storage, bucket, path) {
return __awaiter(this, void 0, void 0, function* () {
const [exists] = yield storage.bucket(bucket).file(path).exists();
return exists;
});
}


/***/ }),
Expand Down
34 changes: 22 additions & 12 deletions dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92559,7 +92559,7 @@ function restoreFromGCS(_paths_1, primaryKey_1) {
const archiveFolder = yield utils.createTempDirectory();
const archivePath = path.join(archiveFolder, utils.getCacheFileName(compressionMethod));
const keys = [primaryKey, ...restoreKeys];
const gcsPath = yield findFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod);
const gcsPath = yield findLatestFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod);
if (!gcsPath) {
core.info(`No matching cache found`);
return undefined;
Expand Down Expand Up @@ -92643,24 +92643,34 @@ function saveToGCS(paths, key) {
}
});
}
function findFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod) {
function findLatestFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod) {
return __awaiter(this, void 0, void 0, function* () {
let latestFile = undefined;
for (const key of keys) {
const gcsPath = getGCSPath(pathPrefix, key, compressionMethod);
if (yield checkFileExists(storage, bucket, gcsPath)) {
core.info(`Found file on bucket: ${bucket} with key: ${gcsPath}`);
return gcsPath;
const prefix = `${pathPrefix}/${key}`;
const [files] = yield storage.bucket(bucket).getFiles({ prefix });
for (const file of files) {
if (!file.name.endsWith(utils.getCacheFileName(compressionMethod)))
continue;
core.debug(`Found file: ${file.name} (created: ${file.metadata.timeCreated})`);
const created = file.metadata.timeCreated
? new Date(file.metadata.timeCreated)
: undefined;
if (!created) {
continue;
}
if (!latestFile || created > latestFile.updated) {
latestFile = { path: file.name, updated: created };
}
}
}
if (latestFile) {
core.info(`Use cache: ${latestFile.path} from GCS bucket ${bucket}`);
return latestFile.path;
}
return undefined;
});
}
function checkFileExists(storage, bucket, path) {
return __awaiter(this, void 0, void 0, function* () {
const [exists] = yield storage.bucket(bucket).file(path).exists();
return exists;
});
}


/***/ }),
Expand Down
34 changes: 22 additions & 12 deletions dist/save-only/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92572,7 +92572,7 @@ function restoreFromGCS(_paths_1, primaryKey_1) {
const archiveFolder = yield utils.createTempDirectory();
const archivePath = path.join(archiveFolder, utils.getCacheFileName(compressionMethod));
const keys = [primaryKey, ...restoreKeys];
const gcsPath = yield findFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod);
const gcsPath = yield findLatestFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod);
if (!gcsPath) {
core.info(`No matching cache found`);
return undefined;
Expand Down Expand Up @@ -92656,24 +92656,34 @@ function saveToGCS(paths, key) {
}
});
}
function findFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod) {
function findLatestFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod) {
return __awaiter(this, void 0, void 0, function* () {
let latestFile = undefined;
for (const key of keys) {
const gcsPath = getGCSPath(pathPrefix, key, compressionMethod);
if (yield checkFileExists(storage, bucket, gcsPath)) {
core.info(`Found file on bucket: ${bucket} with key: ${gcsPath}`);
return gcsPath;
const prefix = `${pathPrefix}/${key}`;
const [files] = yield storage.bucket(bucket).getFiles({ prefix });
for (const file of files) {
if (!file.name.endsWith(utils.getCacheFileName(compressionMethod)))
continue;
core.debug(`Found file: ${file.name} (created: ${file.metadata.timeCreated})`);
const created = file.metadata.timeCreated
? new Date(file.metadata.timeCreated)
: undefined;
if (!created) {
continue;
}
if (!latestFile || created > latestFile.updated) {
latestFile = { path: file.name, updated: created };
}
}
}
if (latestFile) {
core.info(`Use cache: ${latestFile.path} from GCS bucket ${bucket}`);
return latestFile.path;
}
return undefined;
});
}
function checkFileExists(storage, bucket, path) {
return __awaiter(this, void 0, void 0, function* () {
const [exists] = yield storage.bucket(bucket).file(path).exists();
return exists;
});
}


/***/ }),
Expand Down
34 changes: 22 additions & 12 deletions dist/save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92572,7 +92572,7 @@ function restoreFromGCS(_paths_1, primaryKey_1) {
const archiveFolder = yield utils.createTempDirectory();
const archivePath = path.join(archiveFolder, utils.getCacheFileName(compressionMethod));
const keys = [primaryKey, ...restoreKeys];
const gcsPath = yield findFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod);
const gcsPath = yield findLatestFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod);
if (!gcsPath) {
core.info(`No matching cache found`);
return undefined;
Expand Down Expand Up @@ -92656,24 +92656,34 @@ function saveToGCS(paths, key) {
}
});
}
function findFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod) {
function findLatestFileOnGCS(storage, bucket, pathPrefix, keys, compressionMethod) {
return __awaiter(this, void 0, void 0, function* () {
let latestFile = undefined;
for (const key of keys) {
const gcsPath = getGCSPath(pathPrefix, key, compressionMethod);
if (yield checkFileExists(storage, bucket, gcsPath)) {
core.info(`Found file on bucket: ${bucket} with key: ${gcsPath}`);
return gcsPath;
const prefix = `${pathPrefix}/${key}`;
const [files] = yield storage.bucket(bucket).getFiles({ prefix });
for (const file of files) {
if (!file.name.endsWith(utils.getCacheFileName(compressionMethod)))
continue;
core.debug(`Found file: ${file.name} (created: ${file.metadata.timeCreated})`);
const created = file.metadata.timeCreated
? new Date(file.metadata.timeCreated)
: undefined;
if (!created) {
continue;
}
if (!latestFile || created > latestFile.updated) {
latestFile = { path: file.name, updated: created };
}
}
}
if (latestFile) {
core.info(`Use cache: ${latestFile.path} from GCS bucket ${bucket}`);
return latestFile.path;
}
return undefined;
});
}
function checkFileExists(storage, bucket, path) {
return __awaiter(this, void 0, void 0, function* () {
const [exists] = yield storage.bucket(bucket).file(path).exists();
return exists;
});
}


/***/ }),
Expand Down
39 changes: 24 additions & 15 deletions src/utils/gcsCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async function restoreFromGCS(
);

const keys = [primaryKey, ...restoreKeys];
const gcsPath = await findFileOnGCS(
const gcsPath = await findLatestFileOnGCS(
storage,
bucket,
pathPrefix,
Expand Down Expand Up @@ -248,28 +248,37 @@ async function saveToGCS(
}
}

async function findFileOnGCS(
async function findLatestFileOnGCS(
storage: Storage,
bucket: string,
pathPrefix: string,
keys: string[],
compressionMethod: CompressionMethod
): Promise<string | undefined> {
let latestFile: { path: string; updated: Date } | undefined = undefined;
for (const key of keys) {
const gcsPath = getGCSPath(pathPrefix, key, compressionMethod);
if (await checkFileExists(storage, bucket, gcsPath)) {
core.info(`Found file on bucket: ${bucket} with key: ${gcsPath}`);
return gcsPath;
const prefix = `${pathPrefix}/${key}`;
const [files] = await storage.bucket(bucket).getFiles({ prefix });
for (const file of files) {
if (!file.name.endsWith(utils.getCacheFileName(compressionMethod)))
continue;
core.debug(
`Found file: ${file.name} (created: ${file.metadata.timeCreated})`
);
const created = file.metadata.timeCreated
? new Date(file.metadata.timeCreated)
: undefined;
if (!created) {
continue;
}
if (!latestFile || created > latestFile.updated) {
latestFile = { path: file.name, updated: created };
}
}
}
if (latestFile) {
core.info(`Use cache: ${latestFile.path} from GCS bucket ${bucket}`);
return latestFile.path;
}
return undefined;
}

async function checkFileExists(
storage: Storage,
bucket: string,
path: string
): Promise<boolean> {
const [exists] = await storage.bucket(bucket).file(path).exists();
return exists;
}