mirror of
https://github.com/Mozilla-Actions/sccache-action.git
synced 2026-04-17 19:14:05 +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
|
# 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:
|
with:
|
||||||
version: "v0.3.3"
|
version: "v0.3.3"
|
||||||
|
|
||||||
- name: Run sccache stat for check
|
- name: Run sccache for check
|
||||||
shell: bash
|
shell: bash
|
||||||
run: ${SCCACHE_PATH} --show-stats
|
run: ${SCCACHE_PATH} --start-server
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ inputs:
|
|||||||
required: true
|
required: true
|
||||||
runs:
|
runs:
|
||||||
using: "node16"
|
using: "node16"
|
||||||
main: "dist/index.js"
|
main: "dist/setup/index.js"
|
||||||
|
post: "dist/show_stats/index.js"
|
||||||
branding:
|
branding:
|
||||||
icon: "star"
|
icon: "star"
|
||||||
color: "orange"
|
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",
|
"name": "sccache-action",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "Github Action for Sccache",
|
"description": "Github Action for Sccache",
|
||||||
"main": "dist/index.js",
|
"main": "dist/setup/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"tsc": "tsc",
|
"build-dist": "ncc build lib/setup.js -m -o dist/setup/ && ncc build lib/show_stats.js -m -o dist/show_stats",
|
||||||
"ncc": "ncc build lib/sccache.js",
|
"build": "prettier --write **/*.ts && tsc && npm run build-dist",
|
||||||
"build": "prettier --write **/*.ts && tsc && ncc build lib/sccache.js",
|
|
||||||
"format": "prettier --write **/*.ts",
|
"format": "prettier --write **/*.ts",
|
||||||
"format-check": "prettier --check **/*.ts",
|
"format-check": "prettier --check **/*.ts",
|
||||||
"lint": "eslint **/*.ts --cache",
|
"lint": "eslint **/*.ts --cache",
|
||||||
|
|||||||
@@ -24,13 +24,13 @@ async function setup() {
|
|||||||
// TODO: we can support install latest version by default if version
|
// TODO: we can support install latest version by default if version
|
||||||
// is not input.
|
// is not input.
|
||||||
const version = core.getInput('version');
|
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 filename = getFilename(version);
|
||||||
const dirname = getDirname(version);
|
const dirname = getDirname(version);
|
||||||
|
|
||||||
const downloadUrl = `https://github.com/mozilla/sccache/releases/download/${version}/${filename}`;
|
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.
|
// Download and extract.
|
||||||
const sccachePackage = await downloadTool(downloadUrl);
|
const sccachePackage = await downloadTool(downloadUrl);
|
||||||
@@ -41,7 +41,7 @@ async function setup() {
|
|||||||
} else {
|
} else {
|
||||||
sccachePath = await extractTar(sccachePackage);
|
sccachePath = await extractTar(sccachePackage);
|
||||||
}
|
}
|
||||||
console.log('sccache extracted to: ', sccachePath);
|
core.info(`sccache extracted to: ${sccachePath}`);
|
||||||
|
|
||||||
// Cache sccache.
|
// Cache sccache.
|
||||||
const sccacheHome = await cacheDir(
|
const sccacheHome = await cacheDir(
|
||||||
@@ -49,12 +49,20 @@ async function setup() {
|
|||||||
'sccache',
|
'sccache',
|
||||||
version
|
version
|
||||||
);
|
);
|
||||||
console.log('sccache cached to: ', sccacheHome);
|
core.info(`sccache cached to: ${sccacheHome}`);
|
||||||
|
|
||||||
// Add cached sccache into path.
|
// Add cached sccache into path.
|
||||||
core.addPath(`${sccacheHome}`);
|
core.addPath(`${sccacheHome}`);
|
||||||
// Expose the sccache path as env.
|
// Expose the sccache path as env.
|
||||||
core.exportVariable('SCCACHE_PATH', `${sccacheHome}/sccache`);
|
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 {
|
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