Skip to content

Commit b6b37bc

Browse files
committed
fix @ProtonMail web clients building script
* Workaround "yarn install" error during building https://github.com/ProtonMail/WebClients on CI env. * Reduce the number of times the building setup flow runs (the "installing modules => patching => etc" execution flow).
1 parent d9a6dfc commit b6b37bc

File tree

2 files changed

+64
-29
lines changed

2 files changed

+64
-29
lines changed

.github/workflows/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ jobs:
2424
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
2525
key: "yarn-cache-dir-${{ matrix.os }}-${{ hashFiles('./yarn.lock', './patch-package/*.patch') }}-${{ secrets.YARN_CACHE_DIR_CACHE_VERSION }}"
2626
- { name: install node-gyp, if: runner.os == 'Windows', run: ./scripts/ci/github/install-node-gyp.ps1 }
27+
- { uses: actions/setup-python@v2, with: { python-version: "3.9" } }
28+
- { name: envinfo, run: npx envinfo }
2729
- { name: install node modules, run: "yarn --pure-lockfile --network-timeout 60000" }
2830
# </common>
2931
- name: cache artifact
@@ -55,6 +57,8 @@ jobs:
5557
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
5658
key: "yarn-cache-dir-${{ matrix.os }}-${{ hashFiles('./yarn.lock', './patch-package/*.patch') }}-${{ secrets.YARN_CACHE_DIR_CACHE_VERSION }}"
5759
- { name: install node-gyp, if: runner.os == 'Windows', run: ./scripts/ci/github/install-node-gyp.ps1 }
60+
- { uses: actions/setup-python@v2, with: { python-version: "3.9" } }
61+
- { name: envinfo, run: npx envinfo }
5862
- { name: install node modules, run: "yarn --pure-lockfile --network-timeout 60000" }
5963
# </common>
6064
- { name: build, run: 'npm exec --package=npm-run-all -- npm-run-all lint build' }
@@ -79,6 +83,8 @@ jobs:
7983
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
8084
key: "yarn-cache-dir-${{ matrix.os }}-${{ hashFiles('./yarn.lock', './patch-package/*.patch') }}-${{ secrets.YARN_CACHE_DIR_CACHE_VERSION }}"
8185
- { name: install node-gyp, if: runner.os == 'Windows', run: ./scripts/ci/github/install-node-gyp.ps1 }
86+
- { uses: actions/setup-python@v2, with: { python-version: "3.9" } }
87+
- { name: envinfo, run: npx envinfo }
8288
- { name: install node modules, run: "yarn --pure-lockfile --network-timeout 60000" }
8389
# </common>
8490
- { name: download proton clients artifact, uses: actions/download-artifact@v2, with: { name: proton-clients-artifact } }

scripts/prepare-webclient/webclients.ts

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -266,38 +266,65 @@ async function executeBuildFlow<T extends FolderAsDomainEntry[]>(
266266
const {tag} = PROVIDER_REPO_MAP[repoType];
267267
const legacyProtonPacking = repoType === "proton-calendar";
268268

269-
// TODO move block to "folderAsDomainEntry" loop if "node_modules" gets patched
270-
if (
271-
!fsExtra.pathExistsSync(path.join(repoDir, ".git"))
272-
||
273-
!(await execShell(["git", ["tag"], {cwd: repoDir}], {printStdOut: false})).stdout.trim().includes(tag)
274-
) { // cloning
275-
await execShell(["npx", ["--no", "rimraf", repoDir]]);
276-
fsExtra.ensureDirSync(repoDir);
277-
await execShell(["git", ["clone", "https://github.com/ProtonMail/WebClients.git", repoDir]]);
278-
await execShell(["git", ["show", "--summary"], {cwd: repoDir}]);
279-
} else {
280-
await execShell(["git", ["reset", "--hard", "origin/main"], {cwd: repoDir}]);
281-
await execShell(["git", ["clean", "-fdx", "--exclude", ".yarn/cache"], {cwd: repoDir}]);
282-
}
269+
const state: { buildingSetup: () => Promise<void> } = {
270+
async buildingSetup() {
271+
state.buildingSetup = async () => Promise.resolve(); // one run per "repo type" only needed
272+
273+
// TODO move block to "folderAsDomainEntry" loop if "node_modules" gets patched
274+
if (
275+
!fsExtra.pathExistsSync(path.join(repoDir, ".git"))
276+
||
277+
!(await execShell(["git", ["tag"], {cwd: repoDir}], {printStdOut: false})).stdout.trim().includes(tag)
278+
) { // cloning
279+
await execShell(["npx", ["--no", "rimraf", repoDir]]);
280+
fsExtra.ensureDirSync(repoDir);
281+
await execShell(["git", ["clone", "https://github.com/ProtonMail/WebClients.git", repoDir]]);
282+
await execShell(["git", ["show", "--summary"], {cwd: repoDir}]);
283+
} else {
284+
await execShell(["git", ["reset", "--hard", "origin/main"], {cwd: repoDir}]);
285+
await execShell(["git", ["clean", "-fdx"], {cwd: repoDir}]);
286+
}
283287

284-
await execShell(["git", ["reset", "--hard", tag], {cwd: repoDir}]);
285-
await execShell(["yarn", ["install"], {cwd: repoDir}], {printStdOut: false});
288+
await execShell(["git", ["reset", "--hard", tag], {cwd: repoDir}]);
289+
290+
// TODO "drop yarn install" hacks when executed on CI env
291+
if (process.env.CI) {
292+
// hacks applied to avoid the following error:
293+
// eslint-disable-next-line max-len
294+
// YN0018: │ sieve.js@https://github.com/ProtonMail/sieve.js.git#commit=a09ab52092164af74278e77612a091e730e9b7e9: The remote archive doesn't match the expected checksum
295+
// see https://github.com/yarnpkg/berry/issues/1142 and https://github.com/yarnpkg/berry/issues/1989 for details
296+
await execShell(["yarn", ["cache", "clean", "--all"], {cwd: repoDir}]);
297+
await execShell([
298+
"yarn", ["install"],
299+
{
300+
cwd: repoDir,
301+
env: {
302+
...process.env,
303+
YARN_CHECKSUM_BEHAVIOR: "update",
304+
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: "1",
305+
},
306+
},
307+
]);
308+
} else {
309+
await execShell(["yarn", ["install"], {cwd: repoDir}], {printStdOut: false});
310+
}
286311

287-
{ // patching
288-
const resolvePatchFile = (file: string): string => path.join(CWD_ABSOLUTE_DIR, `./patches/protonmail/${file}`);
289-
const repoTypePatchFile = resolvePatchFile(`${repoType}.patch`);
312+
{ // patching
313+
const resolvePatchFile = (file: string): string => path.join(CWD_ABSOLUTE_DIR, `./patches/protonmail/${file}`);
314+
const repoTypePatchFile = resolvePatchFile(`${repoType}.patch`);
290315

291-
await applyPatch({patchFile: resolvePatchFile("common.patch"), cwd: repoDir});
316+
await applyPatch({patchFile: resolvePatchFile("common.patch"), cwd: repoDir});
292317

293-
if (!legacyProtonPacking) {
294-
await applyPatch({patchFile: resolvePatchFile("except-calendar.patch"), cwd: repoDir});
295-
}
318+
if (!legacyProtonPacking) {
319+
await applyPatch({patchFile: resolvePatchFile("except-calendar.patch"), cwd: repoDir});
320+
}
296321

297-
if (fsExtra.pathExistsSync(repoTypePatchFile)) {
298-
await applyPatch({patchFile: repoTypePatchFile, cwd: repoDir});
299-
}
300-
}
322+
if (fsExtra.pathExistsSync(repoTypePatchFile)) {
323+
await applyPatch({patchFile: repoTypePatchFile, cwd: repoDir});
324+
}
325+
}
326+
},
327+
};
301328

302329
for (const folderAsDomainEntry of folderAsDomainEntries) {
303330
const targetDistDir = path.resolve(destDir, folderAsDomainEntry.folderNameAsDomain, destSubFolder);
@@ -307,8 +334,8 @@ async function executeBuildFlow<T extends FolderAsDomainEntry[]>(
307334
JSON.stringify({...folderAsDomainEntry, resolvedDistDir: targetDistDir}),
308335
);
309336

310-
if (fsExtra.pathExistsSync(path.join(targetDistDir, "index.html"))) {
311-
CONSOLE_LOG("Skip building as directory already exists:", targetDistDir);
337+
if (fsExtra.pathExistsSync(path.join(targetDistDir, WEB_CLIENTS_BLANK_HTML_FILE_NAME))) {
338+
CONSOLE_LOG("Skip building as bundle already exists:", targetDistDir);
312339
continue;
313340
}
314341

@@ -324,6 +351,8 @@ async function executeBuildFlow<T extends FolderAsDomainEntry[]>(
324351
if (shouldFailOnBuild) {
325352
throw new Error(`Halting since "${shouldFailOnBuildEnvVarName}" env var has been enabled`);
326353
} else { // building
354+
await state.buildingSetup();
355+
327356
const {configApiParam} = await configure({cwd: appDir, repoType}, folderAsDomainEntry);
328357
const publicPath: string | undefined = repoType !== "proton-mail"
329358
? `/${PROVIDER_REPO_MAP[repoType].baseDirName}/`

0 commit comments

Comments
 (0)