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

refactor: simplify electron mirror management #2749

Merged
merged 6 commits into from
Jun 1, 2020
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
37 changes: 27 additions & 10 deletions pipeline/scripts/download-electron-mirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,27 @@ const path = require('path');

/*
This script replaces existing electron & chromedriver modules
with mirror dependencies specified by ELECTRON_MIRROR_VAR
and ELECTRON_CUSTOM_DIR_VAR (see @electron/get). We use this
to avoid bundling non-freely-redistributable media codecs
in our release builds. The version of Electron published to npm
includes these as part of Chromium; our release builds use a
with mirror dependencies specified by `assetNumber` and pipeline
build variables. We use this to avoid bundling non-freely-redistributable
media codecs in our release builds. The version of Electron published to
npm includes these as part of Chromium; our release builds use a
Microsoft-maintained build of Electron that removes those codecs.
*/

if (
process.env.ELECTRON_MIRROR_VAR === undefined ||
process.env.ELECTRON_CUSTOM_DIR_VAR === undefined
process.env.ELECTRON_MIRROR_BASE_VAR === undefined ||
process.env.ELECTRON_MIRROR_CUSTOM_DIR_VAR === undefined
) {
console.error('ELECTRON_MIRROR_VAR and ELECTRON_CUSTOM_DIR_VAR must be defined');
console.error(
`Mirror variables are not set. Please ensure that
ELECTRON_MIRROR_BASE_VAR and ELECTRON_MIRROR_CUSTOM_DIR_VAR
are both set as variables in the pipeline`,
);
process.exit(1);
}

const assetNumber = '4658637';

const downloadMirrors = async () => {
await downloadElectronArtifact('electron', 'node_modules/electron/dist');
await downloadElectronArtifact('chromedriver', 'node_modules/electron-chromedriver/bin');
Expand All @@ -36,8 +41,9 @@ const downloadElectronArtifact = async (artifactName, destinationPath) => {
version: `${pkg.dependencies.electron}`,
artifactName,
mirrorOptions: {
mirror: process.env.ELECTRON_MIRROR_VAR,
customDir: process.env.ELECTRON_CUSTOM_DIR_VAR,
mirror: process.env.ELECTRON_MIRROR_BASE_VAR,
customDir: process.env.ELECTRON_MIRROR_CUSTOM_DIR_VAR,
resolveAssetURL: resolveCustomAssetURL,
},
force: true,
});
Expand All @@ -49,6 +55,17 @@ const downloadElectronArtifact = async (artifactName, destinationPath) => {
await extract(zipFilePath, { dir: destinationPath });
};

const resolveCustomAssetURL = details => {
const opts = details.mirrorOptions;
const file = details.artifactName.startsWith('SHASUMS256')
? details.artifactName
: `${[details.artifactName, details.version, details.platform, details.arch].join(
'-',
)}.zip`;
const strippedVer = details.version.replace(/^v/, '');
return `${opts.mirror}/${strippedVer}/${opts.customDir}/${assetNumber}/${file}`;
};

downloadMirrors().catch(err => {
console.error(err);
process.exit(1);
Expand Down
3 changes: 0 additions & 3 deletions pipeline/unified/download-electron-mirror.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@
steps:
- script: yarn download:electron-mirror
displayName: download custom electron build
env:
ELECTRON_MIRROR_VAR: $(ELECTRON_822_MIRROR_VAR)
ELECTRON_CUSTOM_DIR_VAR: $(ELECTRON_822_CUSTOM_DIR_VAR)