mirror of
https://github.com/mozilla-actions/sccache-action
synced 2026-09-07 20:04:02 +00:00
Merge pull request #1 from Xuanwo/poc
feat: Implement basic sccache action support
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"env": {
|
||||
"node": true,
|
||||
"jest": true
|
||||
},
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2020,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:import/errors",
|
||||
"plugin:import/warnings",
|
||||
"plugin:import/typescript",
|
||||
"plugin:prettier/recommended"
|
||||
],
|
||||
"plugins": [
|
||||
"@typescript-eslint",
|
||||
"jest"
|
||||
],
|
||||
"rules": {
|
||||
"import/first": "error",
|
||||
"import/newline-after-import": "error",
|
||||
"import/no-duplicates": "error"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
# Ignore dist changes
|
||||
dist/index.js -diff
|
||||
@@ -0,0 +1,6 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
@@ -0,0 +1,70 @@
|
||||
# Copyright 2023 Mozilla Foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
name: CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Setup Node.js 16.x
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16.x
|
||||
cache: npm
|
||||
|
||||
- name: npm install
|
||||
run: npm install
|
||||
- name: Prettier Format Check
|
||||
run: npm run format-check
|
||||
- name: ESLint Check
|
||||
run: npm run lint
|
||||
- name: Build & Test
|
||||
run: npm run test
|
||||
|
||||
test_v0_3_3:
|
||||
name: Test version 0.3.3
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- windows-latest
|
||||
- macos-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set Node.js 16.x
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16.x
|
||||
cache: npm
|
||||
|
||||
- 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} --show-stats
|
||||
@@ -0,0 +1,4 @@
|
||||
node_modules/
|
||||
lib/
|
||||
# Cache file of eslint
|
||||
.eslintcache
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"printWidth": 80,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": false,
|
||||
"arrowParens": "avoid",
|
||||
"parser": "typescript"
|
||||
}
|
||||
+14
@@ -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"
|
||||
Vendored
+6834
File diff suppressed because it is too large
Load Diff
Generated
+14495
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"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",
|
||||
"lint": "eslint **/*.ts --cache",
|
||||
"test": "jest --passWithNoTests"
|
||||
},
|
||||
"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",
|
||||
"@typescript-eslint/eslint-plugin": "^5.45.0",
|
||||
"@typescript-eslint/parser": "^5.45.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"eslint-plugin-jest": "^26.9.0",
|
||||
"eslint-plugin-prettier": "^4.2.1"
|
||||
}
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
// Copyright 2023 Mozilla Foundation
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import * as core from '@actions/core';
|
||||
import {
|
||||
downloadTool,
|
||||
extractTar,
|
||||
extractZip,
|
||||
cacheDir
|
||||
} from '@actions/tool-cache';
|
||||
|
||||
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 sccache version: ', 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 = await downloadTool(downloadUrl);
|
||||
|
||||
let sccachePath;
|
||||
if (getExtension() == 'zip') {
|
||||
sccachePath = await extractZip(sccachePackage);
|
||||
} else {
|
||||
sccachePath = await extractTar(sccachePackage);
|
||||
}
|
||||
console.log('sccache extracted to: ', sccachePath);
|
||||
|
||||
// Cache sccache.
|
||||
const sccacheHome = await cacheDir(
|
||||
`${sccachePath}/${dirname}`,
|
||||
'sccache',
|
||||
version
|
||||
);
|
||||
console.log('sccache cached to: ', sccacheHome);
|
||||
|
||||
// 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 getDirname(version: string): Error | string {
|
||||
return `sccache-${version}-${getArch()}-${getPlatform()}`;
|
||||
}
|
||||
|
||||
function getArch(): Error | string {
|
||||
switch (process.arch) {
|
||||
case 'x64':
|
||||
return 'x86_64';
|
||||
case 'arm64':
|
||||
return 'aarch64';
|
||||
default:
|
||||
return Error('Unsupported arch "${process.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('Unsupported platform "${process.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);
|
||||
});
|
||||
@@ -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