Signed-off-by: Xuanwo <github@xuanwo.io>
This commit is contained in:
Xuanwo
2023-01-09 23:47:21 +08:00
parent 5b9624008f
commit a2811a1f48
2 changed files with 22 additions and 8 deletions

11
dist/index.js vendored
View File

@@ -47,20 +47,22 @@ function setup() {
// is not input.
const version = core.getInput('version');
console.log('try to setup sccache version: ', version);
const downloadUrl = `https://github.com/mozilla/sccache/releases/download/${version}/${getFilename(version)}`;
const filename = getFilename(version);
const dirname = getDirname(version);
const downloadUrl = `https://github.com/mozilla/sccache/releases/download/${version}/${filename}`;
console.log('sccache download from url: ', downloadUrl);
// Download and extract.
const sccachePackage = yield (0, tool_cache_1.downloadTool)(downloadUrl);
var sccachePath;
if (getExtension() == 'zip') {
sccachePath = yield (0, tool_cache_1.extractTar)(sccachePackage);
sccachePath = yield (0, tool_cache_1.extractZip)(sccachePackage);
}
else {
sccachePath = yield (0, tool_cache_1.extractTar)(sccachePackage);
}
console.log('sccache extracted to: ', sccachePath);
// Cache sccache.
const sccacheHome = yield (0, tool_cache_1.cacheDir)(sccachePath, 'sccache', version);
const sccacheHome = yield (0, tool_cache_1.cacheDir)(`${sccachePath}/${dirname}`, 'sccache', version);
console.log('sccache cached to: ', sccacheHome);
// Add cached sccache into path.
core.addPath(`${sccacheHome}`);
@@ -71,6 +73,9 @@ function setup() {
function getFilename(version) {
return `sccache-${version}-${getArch()}-${getPlatform()}.${getExtension()}`;
}
function getDirname(version) {
return `sccache-${version}-${getArch()}-${getPlatform()}}`;
}
function getArch() {
switch (process.arch) {
case 'x64':

View File

@@ -15,9 +15,10 @@ async function setup() {
const version = core.getInput('version');
console.log('try to setup sccache version: ', version);
const downloadUrl = `https://github.com/mozilla/sccache/releases/download/${version}/${getFilename(
version
)}`;
const filename = getFilename(version);
const dirname = getDirname(version);
const downloadUrl = `https://github.com/mozilla/sccache/releases/download/${version}/${filename}`;
console.log('sccache download from url: ', downloadUrl);
// Download and extract.
@@ -25,14 +26,18 @@ async function setup() {
var sccachePath;
if (getExtension() == 'zip') {
sccachePath = await extractTar(sccachePackage);
sccachePath = await extractZip(sccachePackage);
} else {
sccachePath = await extractTar(sccachePackage);
}
console.log('sccache extracted to: ', sccachePath);
// Cache sccache.
const sccacheHome = await cacheDir(sccachePath, 'sccache', version);
const sccacheHome = await cacheDir(
`${sccachePath}/${dirname}`,
'sccache',
version
);
console.log('sccache cached to: ', sccacheHome);
// Add cached sccache into path.
@@ -45,6 +50,10 @@ function getFilename(version: string): Error | string {
return `sccache-${version}-${getArch()}-${getPlatform()}.${getExtension()}`;
}
function getDirname(version: string): Error | string {
return `sccache-${version}-${getArch()}-${getPlatform()}}`;
}
function getArch(): Error | string {
switch (process.arch) {
case 'x64':