Skip to content

Commit

Permalink
chore: handle chmod on storeCacheFile
Browse files Browse the repository at this point in the history
  • Loading branch information
Seiji Fouquet committed Oct 4, 2023
1 parent c90bd2d commit 9719f46
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 49 deletions.
32 changes: 16 additions & 16 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
name: 'github-action-cache-local-fs'
description: 'Cache artifacts like dependencies and build outputs inside a local filesystem in self-hosted runner environments'
author: 'khj809'
name: "cache-local-fs"
description: "Cache artifacts like dependencies and build outputs inside a local filesystem in self-hosted runner environments"
author: "SushiFu"
inputs:
path:
description: 'A list of files, directories, and wildcard patterns to cache and restore'
description: "A list of files, directories, and wildcard patterns to cache and restore"
required: true
key:
description: 'An explicit key for restoring and saving the cache'
description: "An explicit key for restoring and saving the cache"
required: true
restore-keys:
description: 'An ordered list of keys to use for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case.'
description: "An ordered list of keys to use for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case."
required: false
cache-base-path:
description: 'A base local filesystem path where cached files are stored.'
default: '/tmp/cache'
description: "A base local filesystem path where cached files are stored."
default: "/tmp/cache"
required: false
fail-on-cache-miss:
description: 'Fail the workflow if cache entry is not found'
default: 'false'
description: "Fail the workflow if cache entry is not found"
default: "false"
required: false
outputs:
cache-hit:
description: 'A boolean value to indicate an exact match was found for the primary key'
description: "A boolean value to indicate an exact match was found for the primary key"
runs:
using: 'node16'
main: 'dist/restore/index.js'
post: 'dist/save/index.js'
using: "node16"
main: "dist/restore/index.js"
post: "dist/save/index.js"
post-if: success()
branding:
icon: 'archive'
color: 'gray-dark'
icon: "archive"
color: "gray-dark"
19 changes: 13 additions & 6 deletions dist/restore-only/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5885,7 +5885,8 @@ function saveCache(paths, key, cacheBasePath) {
throw new Error(`Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.`);
}
const archiveFolder = yield utils.createTempDirectory();
const archivePath = path.join(archiveFolder, utils.getCacheFileName(compressionMethod));
const cacheFileName = utils.getCacheFileName(compressionMethod);
const archivePath = path.join(archiveFolder, cacheFileName);
core.debug(`Archive Path: ${archivePath}`);
try {
yield (0, tar_1.createTar)(archiveFolder, cachePaths, compressionMethod);
Expand All @@ -5896,7 +5897,7 @@ function saveCache(paths, key, cacheBasePath) {
core.debug(`File Size: ${archiveFileSize}`);
core.debug(`Saving Cache (Key: ${key})`);
const cacheStorePath = utils.getCacheStorePath(cacheBasePath, key);
yield utils.storeCacheFile(archivePath, cacheStorePath);
yield utils.storeCacheFile(archivePath, cacheStorePath, cacheFileName);
return true;
}
catch (error) {
Expand Down Expand Up @@ -8524,12 +8525,18 @@ function getCacheStorePath(cacheBasePath, cacheKey) {
return path.join(cacheBasePath || constants_1.DefaultCacheBasePath, process.env.GITHUB_REPOSITORY || "", cacheKey);
}
exports.getCacheStorePath = getCacheStorePath;
function storeCacheFile(archivePath, cacheStorePath) {
function storeCacheFile(archivePath, cacheStorePath, cacheFileName) {
return __awaiter(this, void 0, void 0, function* () {
yield io.mkdirP(cacheStorePath);
yield io.cp(archivePath, cacheStorePath, {
force: true
yield fs.promises.mkdir(cacheStorePath, {
recursive: true,
mode: fs.constants.S_IRWXU | fs.constants.S_IRWXG
});
yield io.cp(archivePath, cacheStorePath, { force: true });
const rw = fs.constants.S_IRUSR |
fs.constants.S_IWUSR |
fs.constants.S_IRGRP |
fs.constants.S_IWGRP;
yield fs.promises.chmod(path.join(cacheStorePath, cacheFileName), rw);
});
}
exports.storeCacheFile = storeCacheFile;
Expand Down
19 changes: 13 additions & 6 deletions dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5885,7 +5885,8 @@ function saveCache(paths, key, cacheBasePath) {
throw new Error(`Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.`);
}
const archiveFolder = yield utils.createTempDirectory();
const archivePath = path.join(archiveFolder, utils.getCacheFileName(compressionMethod));
const cacheFileName = utils.getCacheFileName(compressionMethod);
const archivePath = path.join(archiveFolder, cacheFileName);
core.debug(`Archive Path: ${archivePath}`);
try {
yield (0, tar_1.createTar)(archiveFolder, cachePaths, compressionMethod);
Expand All @@ -5896,7 +5897,7 @@ function saveCache(paths, key, cacheBasePath) {
core.debug(`File Size: ${archiveFileSize}`);
core.debug(`Saving Cache (Key: ${key})`);
const cacheStorePath = utils.getCacheStorePath(cacheBasePath, key);
yield utils.storeCacheFile(archivePath, cacheStorePath);
yield utils.storeCacheFile(archivePath, cacheStorePath, cacheFileName);
return true;
}
catch (error) {
Expand Down Expand Up @@ -8493,12 +8494,18 @@ function getCacheStorePath(cacheBasePath, cacheKey) {
return path.join(cacheBasePath || constants_1.DefaultCacheBasePath, process.env.GITHUB_REPOSITORY || "", cacheKey);
}
exports.getCacheStorePath = getCacheStorePath;
function storeCacheFile(archivePath, cacheStorePath) {
function storeCacheFile(archivePath, cacheStorePath, cacheFileName) {
return __awaiter(this, void 0, void 0, function* () {
yield io.mkdirP(cacheStorePath);
yield io.cp(archivePath, cacheStorePath, {
force: true
yield fs.promises.mkdir(cacheStorePath, {
recursive: true,
mode: fs.constants.S_IRWXU | fs.constants.S_IRWXG
});
yield io.cp(archivePath, cacheStorePath, { force: true });
const rw = fs.constants.S_IRUSR |
fs.constants.S_IWUSR |
fs.constants.S_IRGRP |
fs.constants.S_IWGRP;
yield fs.promises.chmod(path.join(cacheStorePath, cacheFileName), rw);
});
}
exports.storeCacheFile = storeCacheFile;
Expand Down
19 changes: 13 additions & 6 deletions dist/save-only/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5943,7 +5943,8 @@ function saveCache(paths, key, cacheBasePath) {
throw new Error(`Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.`);
}
const archiveFolder = yield utils.createTempDirectory();
const archivePath = path.join(archiveFolder, utils.getCacheFileName(compressionMethod));
const cacheFileName = utils.getCacheFileName(compressionMethod);
const archivePath = path.join(archiveFolder, cacheFileName);
core.debug(`Archive Path: ${archivePath}`);
try {
yield (0, tar_1.createTar)(archiveFolder, cachePaths, compressionMethod);
Expand All @@ -5954,7 +5955,7 @@ function saveCache(paths, key, cacheBasePath) {
core.debug(`File Size: ${archiveFileSize}`);
core.debug(`Saving Cache (Key: ${key})`);
const cacheStorePath = utils.getCacheStorePath(cacheBasePath, key);
yield utils.storeCacheFile(archivePath, cacheStorePath);
yield utils.storeCacheFile(archivePath, cacheStorePath, cacheFileName);
return true;
}
catch (error) {
Expand Down Expand Up @@ -8640,12 +8641,18 @@ function getCacheStorePath(cacheBasePath, cacheKey) {
return path.join(cacheBasePath || constants_1.DefaultCacheBasePath, process.env.GITHUB_REPOSITORY || "", cacheKey);
}
exports.getCacheStorePath = getCacheStorePath;
function storeCacheFile(archivePath, cacheStorePath) {
function storeCacheFile(archivePath, cacheStorePath, cacheFileName) {
return __awaiter(this, void 0, void 0, function* () {
yield io.mkdirP(cacheStorePath);
yield io.cp(archivePath, cacheStorePath, {
force: true
yield fs.promises.mkdir(cacheStorePath, {
recursive: true,
mode: fs.constants.S_IRWXU | fs.constants.S_IRWXG
});
yield io.cp(archivePath, cacheStorePath, { force: true });
const rw = fs.constants.S_IRUSR |
fs.constants.S_IWUSR |
fs.constants.S_IRGRP |
fs.constants.S_IWGRP;
yield fs.promises.chmod(path.join(cacheStorePath, cacheFileName), rw);
});
}
exports.storeCacheFile = storeCacheFile;
Expand Down
19 changes: 13 additions & 6 deletions dist/save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5885,7 +5885,8 @@ function saveCache(paths, key, cacheBasePath) {
throw new Error(`Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.`);
}
const archiveFolder = yield utils.createTempDirectory();
const archivePath = path.join(archiveFolder, utils.getCacheFileName(compressionMethod));
const cacheFileName = utils.getCacheFileName(compressionMethod);
const archivePath = path.join(archiveFolder, cacheFileName);
core.debug(`Archive Path: ${archivePath}`);
try {
yield (0, tar_1.createTar)(archiveFolder, cachePaths, compressionMethod);
Expand All @@ -5896,7 +5897,7 @@ function saveCache(paths, key, cacheBasePath) {
core.debug(`File Size: ${archiveFileSize}`);
core.debug(`Saving Cache (Key: ${key})`);
const cacheStorePath = utils.getCacheStorePath(cacheBasePath, key);
yield utils.storeCacheFile(archivePath, cacheStorePath);
yield utils.storeCacheFile(archivePath, cacheStorePath, cacheFileName);
return true;
}
catch (error) {
Expand Down Expand Up @@ -8582,12 +8583,18 @@ function getCacheStorePath(cacheBasePath, cacheKey) {
return path.join(cacheBasePath || constants_1.DefaultCacheBasePath, process.env.GITHUB_REPOSITORY || "", cacheKey);
}
exports.getCacheStorePath = getCacheStorePath;
function storeCacheFile(archivePath, cacheStorePath) {
function storeCacheFile(archivePath, cacheStorePath, cacheFileName) {
return __awaiter(this, void 0, void 0, function* () {
yield io.mkdirP(cacheStorePath);
yield io.cp(archivePath, cacheStorePath, {
force: true
yield fs.promises.mkdir(cacheStorePath, {
recursive: true,
mode: fs.constants.S_IRWXU | fs.constants.S_IRWXG
});
yield io.cp(archivePath, cacheStorePath, { force: true });
const rw = fs.constants.S_IRUSR |
fs.constants.S_IWUSR |
fs.constants.S_IRGRP |
fs.constants.S_IWGRP;
yield fs.promises.chmod(path.join(cacheStorePath, cacheFileName), rw);
});
}
exports.storeCacheFile = storeCacheFile;
Expand Down
8 changes: 3 additions & 5 deletions src/localCache/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,8 @@ export async function saveCache(
}

const archiveFolder = await utils.createTempDirectory();
const archivePath = path.join(
archiveFolder,
utils.getCacheFileName(compressionMethod)
);
const cacheFileName = utils.getCacheFileName(compressionMethod);
const archivePath = path.join(archiveFolder, cacheFileName);

core.debug(`Archive Path: ${archivePath}`);

Expand All @@ -192,7 +190,7 @@ export async function saveCache(
core.debug(`Saving Cache (Key: ${key})`);

const cacheStorePath = utils.getCacheStorePath(cacheBasePath, key);
await utils.storeCacheFile(archivePath, cacheStorePath);
await utils.storeCacheFile(archivePath, cacheStorePath, cacheFileName);

return true;
} catch (error) {
Expand Down
16 changes: 12 additions & 4 deletions src/localCache/internal/cacheUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,18 @@ export function getCacheStorePath(

export async function storeCacheFile(
archivePath: string,
cacheStorePath: string
cacheStorePath: string,
cacheFileName: string
) {
await io.mkdirP(cacheStorePath);
await io.cp(archivePath, cacheStorePath, {
force: true
await fs.promises.mkdir(cacheStorePath, {
recursive: true,
mode: fs.constants.S_IRWXU | fs.constants.S_IRWXG
});
await io.cp(archivePath, cacheStorePath, { force: true });
const rw =
fs.constants.S_IRUSR |
fs.constants.S_IWUSR |
fs.constants.S_IRGRP |
fs.constants.S_IWGRP;
await fs.promises.chmod(path.join(cacheStorePath, cacheFileName), rw);
}

0 comments on commit 9719f46

Please sign in to comment.