Skip to content

Commit

Permalink
verify the checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed Mar 21, 2023
1 parent 019ccc0 commit 1bd82e3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dist/setup/index.js

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import {
cacheDir
} from '@actions/tool-cache';

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.
Expand All @@ -30,10 +34,31 @@ async function setup() {
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;
} else {
core.info(`checksum correct: ${calculatedChecksum}`);
}

let sccachePath;
if (getExtension() == 'zip') {
Expand Down

0 comments on commit 1bd82e3

Please sign in to comment.