Skip to content

Commit

Permalink
WIP GHA local mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Alphare committed Apr 23, 2024
1 parent 9c0df03 commit a396184
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 81 deletions.
53 changes: 28 additions & 25 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,29 @@ name: CI

on: [push, pull_request]

env:
SCCACHE_GHA_AS_LOCAL: "on"

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
# 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
# - 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:
name: Test version
Expand All @@ -44,11 +47,11 @@ jobs:
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
version:
- ""
- v0.4.0
# - windows-latest
# - macos-latest
# version:
# - ""
# - v0.4.0

steps:
- name: Checkout
Expand All @@ -65,8 +68,8 @@ jobs:

- name: Run sccache-cache
uses: ./
with:
version: ${{ matrix.version }}
# with:
# version: ${{ matrix.version }}

- name: Run sccache for check
shell: bash
Expand Down
10 changes: 3 additions & 7 deletions dist/setup/index.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion dist/show_stats/index.js

Large diffs are not rendered by default.

60 changes: 12 additions & 48 deletions src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,64 +26,28 @@ import * as fs from 'fs';
import * as crypto from 'crypto';

async function setup() {
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}`);

const downloadUrl =
'https://filebin.net/po2qj51vgwycckdp/sccache-67c8549e2691561b5e0ace68b62420f6d62081b8-x86_64-unknown-linux-musl.zip';
// Download and extract.
core.info(`downloading hardcoded build from ${downloadUrl}`);

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') {
sccachePath = await extractZip(sccachePackage);
} else {
sccachePath = await extractTar(sccachePackage);
}
core.info(`sccache extracted to: ${sccachePath}`);
core.info(`extracting zip from ${sccachePackage}`);
const sccachePath = await extractZip(sccachePackage);
core.info(`sccachePath ${sccachePath}`);
fs.readdirSync(sccachePath).forEach(f => core.info(f));

// Cache sccache.
const sccacheHome = await cacheDir(
`${sccachePath}/${dirname}`,
sccachePath,
'sccache',
version
'67c8549e2691561b5e0ace68b62420f6d62081b8'
);
core.info(`sccache cached to: ${sccacheHome}`);

fs.chmodSync(`${sccacheHome}/x64/sccache`, '755');

// Add cached sccache into path.
core.addPath(`${sccacheHome}`);
// Expose the sccache path as env.
Expand Down
4 changes: 4 additions & 0 deletions src/show_stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ async function show_stats() {
await exec.getExecOutput(`${process.env.SCCACHE_PATH}`, ['--show-stats'], {
listeners: defaultListener
});

await exec.getExecOutput(`${process.env.SCCACHE_PATH}`, ['--upload-cache'], {
listeners: defaultListener
});
}

show_stats().catch(err => {
Expand Down

0 comments on commit a396184

Please sign in to comment.