mirror of
https://github.com/mozilla-actions/sccache-action
synced 2026-09-14 20:13:56 +00:00
feat: Implement basic sccache action support
Signed-off-by: Xuanwo <github@xuanwo.io>
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import * as core from '@actions/core';
|
||||
import {downloadTool, extractTar, cacheDir} from '@actions/tool-cache';
|
||||
import {exec} from 'child_process';
|
||||
import * as fs from 'fs';
|
||||
import {promisify} from 'util';
|
||||
|
||||
async function setup() {
|
||||
// TODO: we can support install latest version by default if version
|
||||
// is not input.
|
||||
const version = core.getInput('version');
|
||||
console.log('try to setup for version: ', version);
|
||||
|
||||
const downloadUrl = `https://github.com/mozilla/sccache/releases/download/${version}/${getFilename}`;
|
||||
console.log('try to setup from url: ', downloadUrl);
|
||||
|
||||
// Download and extract.
|
||||
const sccachePackage = await downloadTool(downloadUrl);
|
||||
const sccachePath = (await extractTar(sccachePackage)) + `/sccache`;
|
||||
|
||||
// Cache sccache.
|
||||
const sccacheHome = await cacheDir(sccachePath, 'sccache', version);
|
||||
// Add cached sccache into path.
|
||||
core.addPath(`${sccacheHome}`);
|
||||
// Expose the sccache path as env.
|
||||
core.exportVariable('SCCACHE_PATH', `${sccacheHome}/sccache`);
|
||||
}
|
||||
|
||||
function getFilename(version: string): Error | string {
|
||||
return `sccache-${version}-${getArch()}-${getPlatform()}.${getExtension()}`;
|
||||
}
|
||||
|
||||
function getArch(): Error | string {
|
||||
switch (process.arch) {
|
||||
case 'x64':
|
||||
return 'x86_64';
|
||||
case 'arm64':
|
||||
return 'aarch64';
|
||||
default:
|
||||
return Error('not supported arch');
|
||||
}
|
||||
}
|
||||
|
||||
function getPlatform(): Error | string {
|
||||
switch (process.platform) {
|
||||
case 'darwin':
|
||||
return 'apple-darwin';
|
||||
case 'win32':
|
||||
return 'pc-windows-msvc';
|
||||
case 'linux':
|
||||
return 'unknown-linux-musl';
|
||||
default:
|
||||
return Error('not supported platform');
|
||||
}
|
||||
}
|
||||
|
||||
function getExtension(): string {
|
||||
switch (process.platform) {
|
||||
case 'win32':
|
||||
return 'zip';
|
||||
default:
|
||||
return 'tar.gz';
|
||||
}
|
||||
}
|
||||
|
||||
setup().catch(err => {
|
||||
core.error(err);
|
||||
core.setFailed(err.message);
|
||||
});
|
||||
Reference in New Issue
Block a user