mirror of
https://github.com/Mozilla-Actions/sccache-action.git
synced 2026-04-08 17:42:13 +08:00
Merge pull request #4 from Xuanwo/gha-support
feat: Add native gha cache and post-hook support
This commit is contained in:
3
.gitattributes
vendored
3
.gitattributes
vendored
@@ -1,2 +1,3 @@
|
||||
# Ignore dist changes
|
||||
dist/index.js -diff
|
||||
dist/setup/index.js -diff
|
||||
dist/show_stats/index.js -diff
|
||||
|
||||
4
.github/workflows/CI.yml
vendored
4
.github/workflows/CI.yml
vendored
@@ -65,6 +65,6 @@ jobs:
|
||||
with:
|
||||
version: "v0.3.3"
|
||||
|
||||
- name: Run sccache stat for check
|
||||
- name: Run sccache for check
|
||||
shell: bash
|
||||
run: ${SCCACHE_PATH} --show-stats
|
||||
run: ${SCCACHE_PATH} --start-server
|
||||
|
||||
@@ -8,7 +8,8 @@ inputs:
|
||||
required: true
|
||||
runs:
|
||||
using: "node16"
|
||||
main: "dist/index.js"
|
||||
main: "dist/setup/index.js"
|
||||
post: "dist/show_stats/index.js"
|
||||
branding:
|
||||
icon: "star"
|
||||
color: "orange"
|
||||
|
||||
6834
dist/index.js
vendored
6834
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
1
dist/setup/index.js
vendored
Normal file
1
dist/setup/index.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
dist/show_stats/index.js
vendored
Normal file
1
dist/show_stats/index.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -2,11 +2,10 @@
|
||||
"name": "sccache-action",
|
||||
"version": "0.0.1",
|
||||
"description": "Github Action for Sccache",
|
||||
"main": "dist/index.js",
|
||||
"main": "dist/setup/index.js",
|
||||
"scripts": {
|
||||
"tsc": "tsc",
|
||||
"ncc": "ncc build lib/sccache.js",
|
||||
"build": "prettier --write **/*.ts && tsc && ncc build lib/sccache.js",
|
||||
"build-dist": "ncc build lib/setup.js -m -o dist/setup/ && ncc build lib/show_stats.js -m -o dist/show_stats",
|
||||
"build": "prettier --write **/*.ts && tsc && npm run build-dist",
|
||||
"format": "prettier --write **/*.ts",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"lint": "eslint **/*.ts --cache",
|
||||
|
||||
@@ -24,13 +24,13 @@ 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);
|
||||
core.info(`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);
|
||||
core.info(`sccache download from url: ${downloadUrl}`);
|
||||
|
||||
// Download and extract.
|
||||
const sccachePackage = await downloadTool(downloadUrl);
|
||||
@@ -41,7 +41,7 @@ async function setup() {
|
||||
} else {
|
||||
sccachePath = await extractTar(sccachePackage);
|
||||
}
|
||||
console.log('sccache extracted to: ', sccachePath);
|
||||
core.info(`sccache extracted to: ${sccachePath}`);
|
||||
|
||||
// Cache sccache.
|
||||
const sccacheHome = await cacheDir(
|
||||
@@ -49,12 +49,20 @@ async function setup() {
|
||||
'sccache',
|
||||
version
|
||||
);
|
||||
console.log('sccache cached to: ', sccacheHome);
|
||||
core.info(`sccache cached to: ${sccacheHome}`);
|
||||
|
||||
// Add cached sccache into path.
|
||||
core.addPath(`${sccacheHome}`);
|
||||
// Expose the sccache path as env.
|
||||
core.exportVariable('SCCACHE_PATH', `${sccacheHome}/sccache`);
|
||||
|
||||
// Expose the gha cache related variable to make users eaiser to
|
||||
// integrate with gha support.
|
||||
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
|
||||
core.exportVariable(
|
||||
'ACTIONS_RUNTIME_TOKEN',
|
||||
process.env.ACTIONS_RUNTIME_TOKEN || ''
|
||||
);
|
||||
}
|
||||
|
||||
function getFilename(version: string): Error | string {
|
||||
37
src/show_stats.ts
Normal file
37
src/show_stats.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
// 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 * as exec from '@actions/exec';
|
||||
|
||||
async function show_stats() {
|
||||
core.debug('start sccache show starts');
|
||||
|
||||
const defaultListener = {
|
||||
stdout: (data: Buffer) => {
|
||||
stdout.push(data.toString());
|
||||
}
|
||||
};
|
||||
|
||||
const stdout: string[] = [];
|
||||
|
||||
await exec.getExecOutput(`${process.env.SCCACHE_PATH}`, ['--show-stats'], {
|
||||
listeners: defaultListener
|
||||
});
|
||||
}
|
||||
|
||||
show_stats().catch(err => {
|
||||
core.error(err);
|
||||
core.setFailed(err.message);
|
||||
});
|
||||
Reference in New Issue
Block a user