mirror of
https://github.com/Mozilla-Actions/sccache-action.git
synced 2026-04-18 19:22:35 +08:00
2
dist/setup/index.js
vendored
2
dist/setup/index.js
vendored
File diff suppressed because one or more lines are too long
25
src/setup.ts
25
src/setup.ts
@@ -20,6 +20,10 @@ import {
|
|||||||
cacheDir
|
cacheDir
|
||||||
} from '@actions/tool-cache';
|
} from '@actions/tool-cache';
|
||||||
|
|
||||||
|
import * as fs from 'fs';
|
||||||
|
|
||||||
|
import * as crypto from 'crypto';
|
||||||
|
|
||||||
async function setup() {
|
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.
|
||||||
@@ -30,10 +34,31 @@ async function setup() {
|
|||||||
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}`;
|
||||||
|
const sha256Url = `${downloadUrl}.sha256`;
|
||||||
core.info(`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);
|
||||||
|
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;
|
||||||
|
} else {
|
||||||
|
core.info(`Correct checksum: ${calculatedChecksum}`);
|
||||||
|
}
|
||||||
|
|
||||||
let sccachePath;
|
let sccachePath;
|
||||||
if (getExtension() == 'zip') {
|
if (getExtension() == 'zip') {
|
||||||
|
|||||||
Reference in New Issue
Block a user