mirror of
https://github.com/Mozilla-Actions/sccache-action.git
synced 2026-04-08 17:42:13 +08:00
feat: Implement basic sccache action support
Signed-off-by: Xuanwo <github@xuanwo.io>
This commit is contained in:
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
# Ignore dist changes
|
||||
dist/index.js -diff
|
||||
6
.github/dependabot.yml
vendored
Normal file
6
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
35
.github/workflows/test.yml
vendored
Normal file
35
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
name: Test sccache
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
v0_3_3:
|
||||
name: Test version 0.3.3
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- windows-latest
|
||||
- macos-lastest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Set Node.js 16.x
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 16.x
|
||||
|
||||
- name: npm install
|
||||
run: npm install
|
||||
|
||||
- name: Run sccache-cache
|
||||
uses: ./
|
||||
with:
|
||||
version: "v0.3.3"
|
||||
|
||||
- name: Run sccache stat for check
|
||||
shell: bash
|
||||
run: ${SCCACHE_PATH} --stat
|
||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
node_modules/
|
||||
lib/
|
||||
11
.prettierrc.json
Normal file
11
.prettierrc.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"printWidth": 80,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": false,
|
||||
"arrowParens": "avoid",
|
||||
"parser": "typescript"
|
||||
}
|
||||
14
action.yml
Normal file
14
action.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
name: "Sccache Action"
|
||||
description: "Setup sccache action"
|
||||
author: "mozilla"
|
||||
inputs:
|
||||
version:
|
||||
description: "The installed sccache version."
|
||||
required: true
|
||||
runs:
|
||||
using: "node16"
|
||||
main: "dist/index.js"
|
||||
branding:
|
||||
icon: "star"
|
||||
color: "orange"
|
||||
6808
dist/index.js
vendored
Normal file
6808
dist/index.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
10851
package-lock.json
generated
Normal file
10851
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
42
package.json
Normal file
42
package.json
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "sccache-action",
|
||||
"version": "0.0.1",
|
||||
"description": "Github Action for Sccache",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"tsc": "tsc",
|
||||
"ncc": "ncc build lib/sccache.js",
|
||||
"build": "prettier --write **/*.ts && tsc && ncc build lib/sccache.js",
|
||||
"format": "prettier --write **/*.ts",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"test": "jest"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/mozilla/sccache-action.git"
|
||||
},
|
||||
"keywords": [
|
||||
"sccache"
|
||||
],
|
||||
"author": "",
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/mozilla/sccache-action/issues"
|
||||
},
|
||||
"homepage": "https://github.com/mozilla/sccache-action#readme",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/io": "^1.1.2",
|
||||
"@actions/tool-cache": "^2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^27.4.1",
|
||||
"@types/node": "^18.11.18",
|
||||
"@vercel/ncc": "^0.36.0",
|
||||
"jest": "^27.5.1",
|
||||
"jest-circus": "^29.3.1",
|
||||
"prettier": "^2.8.1",
|
||||
"ts-jest": "^27.1.4",
|
||||
"typescript": "^4.9.4"
|
||||
}
|
||||
}
|
||||
68
src/sccache.ts
Normal file
68
src/sccache.ts
Normal file
@@ -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);
|
||||
});
|
||||
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"outDir": "./lib",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"**/*.test.ts"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user