mirror of
https://github.com/Mozilla-Actions/sccache-action.git
synced 2026-04-09 17:51:47 +08:00
Compare commits
68 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 |
9
.github/workflows/CI.yml
vendored
9
.github/workflows/CI.yml
vendored
@@ -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,6 +46,9 @@ jobs:
|
||||
- ubuntu-latest
|
||||
- windows-latest
|
||||
- macos-latest
|
||||
version:
|
||||
- ""
|
||||
- v0.4.0
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
@@ -63,7 +66,7 @@ jobs:
|
||||
- name: Run sccache-cache
|
||||
uses: ./
|
||||
with:
|
||||
version: "v0.3.3"
|
||||
version: ${{ matrix.version }}
|
||||
|
||||
- name: Run sccache for check
|
||||
shell: bash
|
||||
|
||||
80
README.md
80
README.md
@@ -3,22 +3,96 @@
|
||||
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.3
|
||||
```
|
||||
|
||||
### 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.3
|
||||
- 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
|
||||
|
||||
```
|
||||
- name: Run sccache-cache
|
||||
uses: mozilla-actions/sccache-action@v0.0.3
|
||||
with:
|
||||
version: "v0.7.4"
|
||||
```
|
||||
|
||||
### 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
|
||||
```
|
||||
|
||||
### 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"
|
||||
```
|
||||
|
||||
## 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. Tag a new release
|
||||
|
||||
## License
|
||||
|
||||
Apache-2.0 (just like sccache)
|
||||
|
||||
@@ -4,10 +4,12 @@ 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 || '' }}
|
||||
runs:
|
||||
using: "node16"
|
||||
using: "node20"
|
||||
main: "dist/setup/index.js"
|
||||
post: "dist/show_stats/index.js"
|
||||
branding:
|
||||
|
||||
8
dist/setup/index.js
vendored
8
dist/setup/index.js
vendored
File diff suppressed because one or more lines are too long
2
dist/show_stats/index.js
vendored
2
dist/show_stats/index.js
vendored
File diff suppressed because one or more lines are too long
3773
package-lock.json
generated
3773
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
33
package.json
33
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sccache-action",
|
||||
"version": "0.0.1",
|
||||
"version": "0.0.3",
|
||||
"description": "Github Action for Sccache",
|
||||
"main": "dist/setup/index.js",
|
||||
"scripts": {
|
||||
@@ -13,7 +13,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 +21,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/github": "^5.1.1",
|
||||
"@actions/io": "^1.1.3",
|
||||
"@actions/tool-cache": "^2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^27.4.1",
|
||||
"@types/node": "^18.14.6",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"@types/node": "^20.10.6",
|
||||
"@typescript-eslint/eslint-plugin": "^5.59.9",
|
||||
"@typescript-eslint/parser": "^5.59.9",
|
||||
"@vercel/ncc": "^0.38.1",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-plugin-import": "^2.29.1",
|
||||
"eslint-plugin-jest": "^27.6.0",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"jest": "^27.5.1",
|
||||
"jest-circus": "^29.5.0",
|
||||
"prettier": "^2.8.4",
|
||||
"jest-circus": "^29.7.0",
|
||||
"prettier": "^2.8.8",
|
||||
"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"
|
||||
"typescript": "^4.9.5"
|
||||
}
|
||||
}
|
||||
|
||||
41
src/setup.ts
41
src/setup.ts
@@ -19,21 +19,54 @@ import {
|
||||
extractZip,
|
||||
cacheDir
|
||||
} 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);
|
||||
const release = await octokit.rest.repos.getLatestRelease({
|
||||
owner: 'mozilla',
|
||||
repo: 'sccache'
|
||||
});
|
||||
version = release.data.tag_name;
|
||||
}
|
||||
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}`;
|
||||
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) {
|
||||
core.setFailed('Checksum verification failed');
|
||||
return;
|
||||
}
|
||||
core.info(`Correct checksum: ${calculatedChecksum}`);
|
||||
|
||||
let sccachePath;
|
||||
if (getExtension() == 'zip') {
|
||||
|
||||
Reference in New Issue
Block a user