mirror of
https://github.com/Mozilla-Actions/sccache-action.git
synced 2026-04-08 17:42:13 +08:00
Compare commits
178 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7d986dd989 | ||
|
|
c3f03b40d2 | ||
|
|
213d335d8b | ||
|
|
65101d47ea | ||
|
|
784917c172 | ||
|
|
1220c18210 | ||
|
|
33f5b948b5 | ||
|
|
8bd7e91bd3 | ||
|
|
a2b43af3c6 | ||
|
|
a675e5f637 | ||
|
|
7017114a0a | ||
|
|
71e3ab63ec | ||
|
|
e5565ffc35 | ||
|
|
07cfce30d5 | ||
|
|
8762d1df13 | ||
|
|
7c8e5e8b71 | ||
|
|
f87751abbf | ||
|
|
2ed8afefeb | ||
|
|
20fc08460b | ||
|
|
3e928dd227 | ||
|
|
dacc35634d | ||
|
|
4b84fe43b3 | ||
|
|
c46e041092 | ||
|
|
678555f65b | ||
|
|
3e3251da34 | ||
|
|
dd3d4cb902 | ||
|
|
f4fe0d59ea | ||
|
|
c040d89fcb | ||
|
|
1998e5d367 | ||
|
|
135e550fd0 | ||
|
|
054db53350 | ||
|
|
0f3ae50cf4 | ||
|
|
3d1446595f | ||
|
|
42761b0ed4 | ||
|
|
e21e59b7e7 | ||
|
|
2e63a0d136 | ||
|
|
4cdf591d8d | ||
|
|
39c9c60c3e | ||
|
|
178695770d | ||
|
|
843e5625f6 | ||
|
|
909297fe93 | ||
|
|
e30706368a | ||
|
|
34bf681ca2 | ||
|
|
8d2a651e78 | ||
|
|
fd63487abf | ||
|
|
68f7f867ba | ||
|
|
c67e42e27c | ||
|
|
86570eb559 | ||
|
|
25839b6484 | ||
|
|
c83ccfeb86 | ||
|
|
859e32b514 | ||
|
|
cd37596050 | ||
|
|
1f3e7143d9 | ||
|
|
9e326ebed9 | ||
|
|
922a306e47 | ||
|
|
2be7591527 | ||
|
|
d707076e63 | ||
|
|
afb5895f80 | ||
|
|
f42f2ce8fa | ||
|
|
ff4a61d6e6 | ||
|
|
e073bd0f5c | ||
|
|
4a60710ed8 | ||
|
|
1ff3075b60 | ||
|
|
0f748361ca | ||
|
|
340520239a | ||
|
|
6ab633fc85 | ||
|
|
d762af42b1 | ||
|
|
64b5546de2 | ||
|
|
d7fbe33efc | ||
|
|
978947f128 | ||
|
|
e1c6d326f6 | ||
|
|
88638bee9c | ||
|
|
0998332e74 | ||
|
|
17a40c6f88 | ||
|
|
f3034ae9cb | ||
|
|
7839c10085 | ||
|
|
9b81ea6973 | ||
|
|
bbcfdc3c11 | ||
|
|
629028e2c7 | ||
|
|
89e9040de8 | ||
|
|
e87392bdf6 | ||
|
|
b4427f4656 | ||
|
|
e759f84286 | ||
|
|
b12911431e | ||
|
|
fb41e19ae3 | ||
|
|
83e296b04b | ||
|
|
511fd3c7f0 | ||
|
|
d4fcccfce3 | ||
|
|
aece89f750 | ||
|
|
0c4d1a08d8 | ||
|
|
103918ffd4 | ||
|
|
aa6abb83bc | ||
|
|
ab76965574 | ||
|
|
2f1ba39e7a | ||
|
|
d947000745 | ||
|
|
f2edb47f42 | ||
|
|
1e8091c415 | ||
|
|
9c0df0382a | ||
|
|
8ebd5a4380 | ||
|
|
7d0144b782 | ||
|
|
8272dac7aa | ||
|
|
e1a9194714 | ||
|
|
27a476c863 | ||
|
|
b3f939aca5 | ||
|
|
6c6e91ca40 | ||
|
|
5320dad1f6 | ||
|
|
9bdd511a9c | ||
|
|
5b7824cab2 | ||
|
|
aff01f2a9b | ||
|
|
fb137f92c9 | ||
|
|
2e7f9ec792 | ||
|
|
23439b739d | ||
|
|
fce2fb6943 | ||
|
|
323784ef1b | ||
|
|
d86fe94d33 | ||
|
|
b4fe875dd5 | ||
|
|
21a0d0809e | ||
|
|
0d25c1a7c7 | ||
|
|
1e15924c00 | ||
|
|
88c8fa114c | ||
|
|
c18c46d0d7 | ||
|
|
c255d852d7 | ||
|
|
44305b1b8e | ||
|
|
d669e98c70 | ||
|
|
7c319969e2 | ||
|
|
01a89c6f36 | ||
|
|
1d3904e27f | ||
|
|
42989ab5d5 | ||
|
|
f068537b11 | ||
|
|
ea0443cf17 | ||
|
|
da260886a4 | ||
|
|
adaee86b7e | ||
|
|
7fc1598ba7 | ||
|
|
774b16e376 | ||
|
|
cd82d33c7f | ||
|
|
60dbcfaf03 | ||
|
|
0dad365f18 | ||
|
|
3ffa7f2739 | ||
|
|
33b4920ca9 | ||
|
|
fd38c5b044 | ||
|
|
371ee17811 | ||
|
|
ff569e9dad | ||
|
|
2060212363 | ||
|
|
5007f9947f | ||
|
|
d75bd29020 | ||
|
|
7c09cf84df | ||
|
|
3259508554 | ||
|
|
c2e2e5c8e4 | ||
|
|
02967188df | ||
|
|
aefdada430 | ||
|
|
9a68c4d04b | ||
|
|
77c1aa945b | ||
|
|
87b953d7aa | ||
|
|
295ac10273 | ||
|
|
4ad3be85ad | ||
|
|
13cf7b2ba9 | ||
|
|
8417cffc2e | ||
|
|
cc6b259f50 | ||
|
|
548630134d | ||
|
|
634be340e7 | ||
|
|
5e615649da | ||
|
|
36cc091a25 | ||
|
|
af5524e1c3 | ||
|
|
d6e55aff39 | ||
|
|
27ad55f054 | ||
|
|
019ccc051d | ||
|
|
e51482ff63 | ||
|
|
419f3acf2e | ||
|
|
c3f47d0aa9 | ||
|
|
232a105d2d | ||
|
|
8c0ea93975 | ||
|
|
e042060788 | ||
|
|
7b7cc03629 | ||
|
|
5eedbfb0f0 | ||
|
|
dd95d78c93 | ||
|
|
78aedbbd3e | ||
|
|
56233b6236 | ||
|
|
4c556aab0a |
8
.github/dependabot.yml
vendored
8
.github/dependabot.yml
vendored
@@ -4,3 +4,11 @@ updates:
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
groups:
|
||||
github-actions:
|
||||
patterns:
|
||||
- "*" # Group all Actions updates into a single larger pull request
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
|
||||
50
.github/workflows/CI.yml
vendored
50
.github/workflows/CI.yml
vendored
@@ -21,11 +21,11 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Setup Node.js 16.x
|
||||
uses: actions/setup-node@v3
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 16.x
|
||||
node-version: 18.x
|
||||
cache: npm
|
||||
|
||||
- name: npm install
|
||||
@@ -37,8 +37,8 @@ jobs:
|
||||
- name: Build & Test
|
||||
run: npm run test
|
||||
|
||||
test_v0_3_3:
|
||||
name: Test version 0.3.3
|
||||
test:
|
||||
name: Test version
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
@@ -46,15 +46,18 @@ jobs:
|
||||
- ubuntu-latest
|
||||
- windows-latest
|
||||
- macos-latest
|
||||
version:
|
||||
- ""
|
||||
- v0.4.0
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set Node.js 16.x
|
||||
uses: actions/setup-node@v3
|
||||
- name: Set Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 16.x
|
||||
node-version: 18.x
|
||||
cache: npm
|
||||
|
||||
- name: npm install
|
||||
@@ -63,7 +66,32 @@ jobs:
|
||||
- name: Run sccache-cache
|
||||
uses: ./
|
||||
with:
|
||||
version: "v0.3.3"
|
||||
version: ${{ matrix.version }}
|
||||
|
||||
- name: Run sccache for check
|
||||
shell: bash
|
||||
run: ${SCCACHE_PATH} --start-server
|
||||
|
||||
test_disable_annotations:
|
||||
name: Test disable_annotations version
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 18.x
|
||||
cache: npm
|
||||
|
||||
- name: npm install
|
||||
run: npm install
|
||||
|
||||
- name: Run sccache-cache
|
||||
uses: ./
|
||||
with:
|
||||
disable_annotations: true
|
||||
|
||||
- name: Run sccache for check
|
||||
shell: bash
|
||||
|
||||
107
README.md
107
README.md
@@ -3,22 +3,123 @@
|
||||
The [sccache](https://github.com/mozilla/sccache/
|
||||
) action can be used in GitHub Actions workflows to integrate sccache into the build process. The sccache action is a step in a workflow that can be used to cache compilation results for subsequent builds, reducing the build time and speeding up the overall development process.
|
||||
|
||||
sccache can easily use GitHub actions cache with almost no configuration.
|
||||
|
||||
This action is available on:
|
||||
https://github.com/marketplace/actions/sccache-action
|
||||
|
||||
## Usage
|
||||
|
||||
Just copy and paste the following in your GitHub action:
|
||||
|
||||
### Use the latest version of sccache if no version is specified
|
||||
|
||||
```
|
||||
- name: Run sccache-cache
|
||||
uses: mozilla/sccache-action@v0.0.1
|
||||
with:
|
||||
version: "v0.3.3"
|
||||
uses: mozilla-actions/sccache-action@v0.0.9
|
||||
```
|
||||
|
||||
### Conditionally run cache and enable it
|
||||
|
||||
```
|
||||
- name: Run sccache-cache only on non-release runs
|
||||
if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
|
||||
uses: mozilla-actions/sccache-action@v0.0.9
|
||||
- name: Set Rust caching env vars only on non-release runs
|
||||
if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
|
||||
run: |
|
||||
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
|
||||
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
|
||||
```
|
||||
|
||||
### Specify a given version of sccache
|
||||
|
||||
Versions prior to sccache v0.10.0 probably will not work.
|
||||
|
||||
```
|
||||
- name: Run sccache-cache
|
||||
uses: mozilla-actions/sccache-action@v0.0.9
|
||||
with:
|
||||
version: "v0.10.0"
|
||||
```
|
||||
|
||||
### To get the execution stats
|
||||
|
||||
Note that using the previous declaration will automatically create a
|
||||
`Post Run sccache-cache` task.
|
||||
|
||||
```
|
||||
- name: Run sccache stat for check
|
||||
shell: bash
|
||||
run: ${SCCACHE_PATH} --show-stats
|
||||
```
|
||||
|
||||
### disable stats report
|
||||
|
||||
```
|
||||
- name: Run sccache-cache
|
||||
uses: mozilla-actions/sccache-action
|
||||
with:
|
||||
disable_annotations: true
|
||||
```
|
||||
|
||||
### Rust code
|
||||
|
||||
For Rust code, the following environment variables should be set:
|
||||
|
||||
```
|
||||
env:
|
||||
SCCACHE_GHA_ENABLED: "true"
|
||||
RUSTC_WRAPPER: "sccache"
|
||||
```
|
||||
|
||||
### C/C++ code
|
||||
|
||||
For C/C++ code, the following environment variables should be set:
|
||||
|
||||
```
|
||||
env:
|
||||
SCCACHE_GHA_ENABLED: "true"
|
||||
```
|
||||
|
||||
With cmake, add the following argument:
|
||||
|
||||
```
|
||||
-DCMAKE_C_COMPILER_LAUNCHER=sccache
|
||||
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache
|
||||
```
|
||||
|
||||
With configure, call it with:
|
||||
```
|
||||
# With gcc
|
||||
./configure CC="sccache gcc" CXX="sccache gcc"
|
||||
# With clang
|
||||
./configure CC="sccache clang" CXX="sccache clang"
|
||||
```
|
||||
|
||||
## Using on GitHub Enterprise Server (GHES)
|
||||
|
||||
When using the action on GitHub Enterprise Server installations a valid GitHub.com token must be provided.
|
||||
|
||||
```
|
||||
- name: Run sccache-cache
|
||||
uses: mozilla-actions/sccache-action@v0.0.9
|
||||
with:
|
||||
token: ${{ secrets.MY_GITHUB_TOKEN }}
|
||||
```
|
||||
|
||||
Note that using https://github.com/actions/create-github-app-token is a better option than storing a fixed token in the repo secrets.
|
||||
|
||||
## Prepare a new release
|
||||
|
||||
1. Update the example in README.md
|
||||
1. Update version in `package.json`
|
||||
1. Run `npm i --package-lock-only`
|
||||
1. Run `npm run build`
|
||||
1. Commit and push the local changes
|
||||
1. Tag a new release (vX.X.X)
|
||||
1. Create a new release in github
|
||||
|
||||
## License
|
||||
|
||||
Apache-2.0 (just like sccache)
|
||||
|
||||
11
action.yml
11
action.yml
@@ -4,10 +4,15 @@ description: "Setup sccache action"
|
||||
author: "mozilla"
|
||||
inputs:
|
||||
version:
|
||||
description: "The installed sccache version."
|
||||
required: true
|
||||
description: "The installed sccache version. Use the latest version of sccache if not specified."
|
||||
token:
|
||||
description: "Used to pull the latest release from sccache. When running this action outside of github.com, you have to pass a personal access token for github.com."
|
||||
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
|
||||
disable_annotations:
|
||||
description: "Disable annotation generation in post-run."
|
||||
default: 'false'
|
||||
runs:
|
||||
using: "node16"
|
||||
using: "node20"
|
||||
main: "dist/setup/index.js"
|
||||
post: "dist/show_stats/index.js"
|
||||
branding:
|
||||
|
||||
4
dist/setup/index.js
vendored
4
dist/setup/index.js
vendored
File diff suppressed because one or more lines are too long
4
dist/show_stats/index.js
vendored
4
dist/show_stats/index.js
vendored
File diff suppressed because one or more lines are too long
12880
package-lock.json
generated
12880
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
46
package.json
46
package.json
@@ -1,8 +1,11 @@
|
||||
{
|
||||
"name": "sccache-action",
|
||||
"version": "0.0.1",
|
||||
"version": "0.0.9",
|
||||
"description": "Github Action for Sccache",
|
||||
"main": "dist/setup/index.js",
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
},
|
||||
"scripts": {
|
||||
"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",
|
||||
@@ -13,7 +16,7 @@
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/mozilla/sccache-action.git"
|
||||
"url": "git+https://github.com/mozilla-actions/sccache-action.git"
|
||||
},
|
||||
"keywords": [
|
||||
"sccache"
|
||||
@@ -21,28 +24,29 @@
|
||||
"author": "",
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/mozilla/sccache-action/issues"
|
||||
"url": "https://github.com/mozilla-actions/sccache-action/issues"
|
||||
},
|
||||
"homepage": "https://github.com/mozilla/sccache-action#readme",
|
||||
"homepage": "https://github.com/mozilla-actions/sccache-action#readme",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/io": "^1.1.2",
|
||||
"@actions/tool-cache": "^2.0.1"
|
||||
"@actions/core": "^1.11.1",
|
||||
"@actions/github": "^6.0.0",
|
||||
"@actions/io": "^1.1.3",
|
||||
"@actions/tool-cache": "^2.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^27.4.1",
|
||||
"@types/node": "^18.14.6",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"jest": "^27.5.1",
|
||||
"jest-circus": "^29.5.0",
|
||||
"prettier": "^2.8.4",
|
||||
"ts-jest": "^27.1.4",
|
||||
"typescript": "^4.9.5",
|
||||
"@typescript-eslint/eslint-plugin": "^5.54.1",
|
||||
"@typescript-eslint/parser": "^5.54.1",
|
||||
"eslint-config-prettier": "^8.7.0",
|
||||
"eslint-plugin-import": "^2.27.5",
|
||||
"eslint-plugin-jest": "^27.2.1",
|
||||
"eslint-plugin-prettier": "^4.2.1"
|
||||
"@types/jest": "^29.5.14",
|
||||
"@types/node": "^22.13.0",
|
||||
"@typescript-eslint/eslint-plugin": "^7.16.1",
|
||||
"@typescript-eslint/parser": "^7.11.0",
|
||||
"@vercel/ncc": "^0.38.3",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-plugin-import": "^2.31.0",
|
||||
"eslint-plugin-jest": "^28.11.0",
|
||||
"eslint-plugin-prettier": "^5.2.3",
|
||||
"jest": "^29.7.0",
|
||||
"jest-circus": "^29.7.0",
|
||||
"prettier": "^3.5.3",
|
||||
"ts-jest": "^29.2.6",
|
||||
"typescript": "^5.7.2"
|
||||
}
|
||||
}
|
||||
|
||||
122
src/setup.ts
122
src/setup.ts
@@ -17,23 +17,99 @@ import {
|
||||
downloadTool,
|
||||
extractTar,
|
||||
extractZip,
|
||||
cacheDir
|
||||
cacheDir,
|
||||
find
|
||||
} from '@actions/tool-cache';
|
||||
import {getOctokit} from '@actions/github';
|
||||
|
||||
import * as fs from 'fs';
|
||||
|
||||
import * as crypto from 'crypto';
|
||||
|
||||
async function setup() {
|
||||
// TODO: we can support install latest version by default if version
|
||||
// is not input.
|
||||
const version = core.getInput('version');
|
||||
core.info(`try to setup sccache version: ${version}'`);
|
||||
let version = core.getInput('version');
|
||||
if (version.length === 0) {
|
||||
// If no version is specified, the latest version is used by default.
|
||||
const token = core.getInput('token', {required: true});
|
||||
const octokit = getOctokit(token, {baseUrl: 'https://api.github.com'});
|
||||
const release = await octokit.rest.repos.getLatestRelease({
|
||||
owner: 'mozilla',
|
||||
repo: 'sccache'
|
||||
});
|
||||
version = release.data.tag_name;
|
||||
}
|
||||
core.info(`try to setup sccache version: ${version}`);
|
||||
|
||||
// Search local file system cache for sccache.
|
||||
// This is useful when actions run on a self-hosted runner.
|
||||
let sccacheHome = find('sccache', version);
|
||||
if (sccacheHome === '') {
|
||||
const sccachePath = await downloadSCCache(version);
|
||||
if (sccachePath instanceof Error) {
|
||||
core.setFailed(sccachePath.message);
|
||||
return;
|
||||
} else {
|
||||
const dirname = getDirname(version);
|
||||
// Cache sccache.
|
||||
sccacheHome = await cacheDir(
|
||||
`${sccachePath}/${dirname}`,
|
||||
'sccache',
|
||||
version
|
||||
);
|
||||
core.info(`sccache cached to: ${sccacheHome}`);
|
||||
}
|
||||
} else {
|
||||
core.info(`find sccache at: ${sccacheHome}`);
|
||||
}
|
||||
// Add sccache into path.
|
||||
core.addPath(`${sccacheHome}`);
|
||||
// Expose the sccache path as env.
|
||||
core.exportVariable('SCCACHE_PATH', `${sccacheHome}/sccache`);
|
||||
|
||||
// Force the github action v2
|
||||
core.exportVariable('ACTIONS_CACHE_SERVICE_V2', `on`);
|
||||
|
||||
// Expose the gha cache related variable to make it easier for users to
|
||||
// integrate with gha support.
|
||||
core.exportVariable(
|
||||
'ACTIONS_RESULTS_URL',
|
||||
process.env.ACTIONS_RESULTS_URL || ''
|
||||
);
|
||||
core.exportVariable(
|
||||
'ACTIONS_RUNTIME_TOKEN',
|
||||
process.env.ACTIONS_RUNTIME_TOKEN || ''
|
||||
);
|
||||
}
|
||||
/**
|
||||
* @param version sccache version
|
||||
* @returns Path to sccache on success. Error on checksum verification failure. */
|
||||
async function downloadSCCache(version: string): Promise<Error | string> {
|
||||
const filename = getFilename(version);
|
||||
const dirname = getDirname(version);
|
||||
|
||||
const downloadUrl = `https://github.com/mozilla/sccache/releases/download/${version}/${filename}`;
|
||||
const sha256Url = `${downloadUrl}.sha256`;
|
||||
core.info(`sccache download from url: ${downloadUrl}`);
|
||||
|
||||
// Download and extract.
|
||||
const sccachePackage = await downloadTool(downloadUrl);
|
||||
const sha256File = await downloadTool(sha256Url);
|
||||
|
||||
// Calculate the SHA256 checksum of the downloaded file.
|
||||
const fileBuffer = await fs.promises.readFile(sccachePackage);
|
||||
const hash = crypto.createHash('sha256');
|
||||
hash.update(fileBuffer);
|
||||
const calculatedChecksum = hash.digest('hex');
|
||||
|
||||
// Read the provided checksum from the .sha256 file.
|
||||
const providedChecksum = (await fs.promises.readFile(sha256File))
|
||||
.toString()
|
||||
.trim();
|
||||
|
||||
// Compare the checksums.
|
||||
if (calculatedChecksum !== providedChecksum) {
|
||||
return Error('Checksum verification failed');
|
||||
}
|
||||
core.info(`Correct checksum: ${calculatedChecksum}`);
|
||||
|
||||
let sccachePath;
|
||||
if (getExtension() == 'zip') {
|
||||
@@ -42,27 +118,7 @@ async function setup() {
|
||||
sccachePath = await extractTar(sccachePackage);
|
||||
}
|
||||
core.info(`sccache extracted to: ${sccachePath}`);
|
||||
|
||||
// Cache sccache.
|
||||
const sccacheHome = await cacheDir(
|
||||
`${sccachePath}/${dirname}`,
|
||||
'sccache',
|
||||
version
|
||||
);
|
||||
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 easier 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 || ''
|
||||
);
|
||||
return sccachePath;
|
||||
}
|
||||
|
||||
function getFilename(version: string): Error | string {
|
||||
@@ -79,8 +135,10 @@ function getArch(): Error | string {
|
||||
return 'x86_64';
|
||||
case 'arm64':
|
||||
return 'aarch64';
|
||||
case 'arm':
|
||||
return 'armv7';
|
||||
default:
|
||||
return Error('Unsupported arch "${process.arch}"');
|
||||
return Error(`Unsupported arch "${process.arch}"`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,9 +149,13 @@ function getPlatform(): Error | string {
|
||||
case 'win32':
|
||||
return 'pc-windows-msvc';
|
||||
case 'linux':
|
||||
return 'unknown-linux-musl';
|
||||
if (process.arch == 'arm') {
|
||||
return 'unknown-linux-musleabi';
|
||||
} else {
|
||||
return 'unknown-linux-musl';
|
||||
}
|
||||
default:
|
||||
return Error('Unsupported platform "${process.platform}"');
|
||||
return Error(`Unsupported platform "${process.platform}"`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,24 +14,156 @@
|
||||
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import {SummaryTableRow} from '@actions/core/lib/summary';
|
||||
|
||||
async function get_output(command: string, args: string[]): Promise<string> {
|
||||
core.debug(`get_output: ${command} ${args.join(' ')}`);
|
||||
|
||||
const output = await exec.getExecOutput(command, args);
|
||||
// --stats-format=json does not emit a newline, which messes up group
|
||||
// processing. Here we add a newline if it's missing.
|
||||
if (!output.stdout.endsWith('\n')) {
|
||||
process.stdout.write('\n');
|
||||
}
|
||||
return output.stdout.toString();
|
||||
}
|
||||
|
||||
async function show_stats() {
|
||||
const disable_annotations = core.getBooleanInput('disable_annotations');
|
||||
if (disable_annotations) {
|
||||
core.debug('annotations generation disabled');
|
||||
return;
|
||||
}
|
||||
|
||||
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
|
||||
const human_stats = await core.group('Get human-readable stats', async () => {
|
||||
return get_output(`${process.env.SCCACHE_PATH}`, ['--show-stats']);
|
||||
});
|
||||
const json_stats = await core.group('Get JSON stats', async () => {
|
||||
return get_output(`${process.env.SCCACHE_PATH}`, [
|
||||
'--show-stats',
|
||||
'--stats-format=json'
|
||||
]);
|
||||
});
|
||||
|
||||
const stats: Stats = JSON.parse(json_stats);
|
||||
const formatted_stats = format_json_stats(stats);
|
||||
|
||||
core.notice(formatted_stats.notice, {
|
||||
title: 'sccache stats'
|
||||
});
|
||||
core.info('\nFull human-readable stats:');
|
||||
core.info(human_stats);
|
||||
|
||||
core.summary.addHeading('sccache stats', 2);
|
||||
core.summary.addTable(formatted_stats.table);
|
||||
core.summary.addDetails(
|
||||
'Full human-readable stats',
|
||||
'\n\n```\n' + human_stats + '\n```\n\n'
|
||||
);
|
||||
core.summary.addDetails(
|
||||
'Full JSON Stats',
|
||||
'\n\n```json\n' + JSON.stringify(stats, null, 2) + '\n```\n\n'
|
||||
);
|
||||
|
||||
await core.summary.write();
|
||||
}
|
||||
|
||||
show_stats().catch(err => {
|
||||
core.error(err);
|
||||
core.setFailed(err.message);
|
||||
});
|
||||
|
||||
interface Duration {
|
||||
secs: number;
|
||||
nanos: number;
|
||||
}
|
||||
|
||||
interface Counter {
|
||||
counts: {
|
||||
[key: string]: number;
|
||||
};
|
||||
adv_counts: {
|
||||
[key: string]: number;
|
||||
};
|
||||
}
|
||||
|
||||
interface Stats {
|
||||
stats: {
|
||||
compile_requests: number;
|
||||
requests_executed: number;
|
||||
|
||||
cache_errors: Counter;
|
||||
cache_hits: Counter;
|
||||
cache_misses: Counter;
|
||||
|
||||
cache_write_errors: number;
|
||||
cache_writes: number;
|
||||
|
||||
cache_write_duration: Duration;
|
||||
cache_read_hit_duration: Duration;
|
||||
compiler_write_duration: Duration;
|
||||
};
|
||||
}
|
||||
|
||||
function sum_stats(stats: Counter): number {
|
||||
return Object.values(stats.counts).reduce((acc, val) => acc + val, 0);
|
||||
}
|
||||
|
||||
function format_duration(duration: Duration): string {
|
||||
const ms = duration.nanos / 1e6;
|
||||
return `${duration.secs}s ${ms}ms`;
|
||||
}
|
||||
|
||||
function format_json_stats(stats: Stats): {
|
||||
table: SummaryTableRow[];
|
||||
notice: string;
|
||||
} {
|
||||
const cache_error_count = sum_stats(stats.stats.cache_errors);
|
||||
const cache_hit_count = sum_stats(stats.stats.cache_hits);
|
||||
const cache_miss_count = sum_stats(stats.stats.cache_misses);
|
||||
const total_hits = cache_hit_count + cache_miss_count + cache_error_count;
|
||||
const ratio = percentage(cache_hit_count, total_hits);
|
||||
|
||||
const write_duration = format_duration(stats.stats.cache_write_duration);
|
||||
const read_duration = format_duration(stats.stats.cache_read_hit_duration);
|
||||
const compiler_duration = format_duration(
|
||||
stats.stats.compiler_write_duration
|
||||
);
|
||||
|
||||
const notice = `${ratio}% - ${cache_hit_count} hits, ${cache_miss_count} misses, ${cache_error_count} errors`;
|
||||
|
||||
const table = [
|
||||
[{data: 'Cache hit %', header: true}, {data: `${ratio}%`}],
|
||||
[{data: 'Cache hits', header: true}, {data: cache_hit_count.toString()}],
|
||||
[{data: 'Cache misses', header: true}, {data: cache_miss_count.toString()}],
|
||||
[
|
||||
{data: 'Cache errors', header: true},
|
||||
{data: cache_error_count.toString()}
|
||||
],
|
||||
[
|
||||
{data: 'Compile requests', header: true},
|
||||
{data: stats.stats.compile_requests.toString()}
|
||||
],
|
||||
[
|
||||
{data: 'Requests executed', header: true},
|
||||
{data: stats.stats.requests_executed.toString()}
|
||||
],
|
||||
[
|
||||
{data: 'Cache writes', header: true},
|
||||
{data: stats.stats.cache_writes.toString()}
|
||||
],
|
||||
[
|
||||
{data: 'Cache write errors', header: true},
|
||||
{data: stats.stats.cache_write_errors.toString()}
|
||||
],
|
||||
[{data: 'Cache write duration', header: true}, {data: write_duration}],
|
||||
[{data: 'Cache read hit duration', header: true}, {data: read_duration}],
|
||||
[{data: 'Compiler write duration', header: true}, {data: compiler_duration}]
|
||||
];
|
||||
return {table, notice};
|
||||
}
|
||||
|
||||
function percentage(x: number, y: number): number {
|
||||
return Math.round((x / y) * 100 || 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user