Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verify the checksum #26

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(`Correct checksum: ${calculatedChecksum}`);
}

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