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

cache installer in the toolcache #147

Merged
merged 2 commits into from
Jul 6, 2021
Merged
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
14 changes: 8 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const crypto = require('crypto');
const assert = require('assert').strict;
const { hashElement } = require('folder-hash');

const inst_url = 'https://github.com/msys2/msys2-installer/releases/download/2021-06-04/msys2-base-x86_64-20210604.sfx.exe';
const inst_version = '2021-06-04';
const inst_url = `https://github.com/msys2/msys2-installer/releases/download/${inst_version}/msys2-base-x86_64-${inst_version.replace(/-/g, '')}.sfx.exe`;
const checksum = '2d7bdb926239ec2afaca8f9b506b34638c3cd5d18ee0f5d8cd6525bf80fcab5d';
// see https://github.com/msys2/setup-msys2/issues/61
const INSTALL_CACHE_ENABLED = false;
Expand Down Expand Up @@ -44,13 +45,15 @@ function parseInput() {
}
}

async function downloadInstaller(destination) {
await tc.downloadTool(inst_url, destination);
async function downloadInstaller() {
const inst_path = tc.find('msys2-installer', inst_version, 'x64');
const destination = inst_path ? path.join(inst_path, 'base.exe') : await tc.downloadTool(inst_url);
let computedChecksum = '';
await exec.exec(`powershell.exe`, [`(Get-FileHash ${destination} -Algorithm SHA256)[0].Hash`], {listeners: {stdout: (data) => { computedChecksum += data.toString(); }}});
if (computedChecksum.slice(0, -2).toUpperCase() !== checksum.toUpperCase()) {
throw new Error(`The SHA256 of the installer does not match! expected ${checksum} got ${computedChecksum}`);
}
return path.join(inst_path || await tc.cacheFile(destination, 'base.exe', 'msys2-installer', inst_version, 'x64'), 'base.exe');
}

async function disableKeyRefresh(msysRootDir) {
Expand Down Expand Up @@ -175,7 +178,7 @@ async function writeWrapper(msysRootDir, pathtype, destDir, name) {

async function runMsys(args, opts) {
assert.ok(cmd);
const quotedArgs = args.map((arg) => {return `'${arg.replace(/'/g, `'\\''`)}'`});
const quotedArgs = args.map((arg) => {return `'${arg.replace(/'/g, `'\\''`)}'`}); // fix confused vim syntax highlighting with: `
await exec.exec('cmd', ['/D', '/S', '/C', cmd].concat(['-c', quotedArgs.join(' ')]), opts);
}

Expand Down Expand Up @@ -217,8 +220,7 @@ async function run() {

if (!cachedInstall) {
core.startGroup('Downloading MSYS2...');
let inst_dest = path.join(tmp_dir, 'base.exe');
await downloadInstaller(inst_dest);
let inst_dest = await downloadInstaller();

changeGroup('Extracting MSYS2...');
await exec.exec(inst_dest, ['-y'], {cwd: dest});
Expand Down