Ver código fonte

chore: Tweak Publish & Install CI to try to make more resilient

Michael Bromley 5 anos atrás
pai
commit
b86da59632
2 arquivos alterados com 25 adições e 15 exclusões
  1. 10 4
      .github/workflows/verdaccio/config.yaml
  2. 15 11
      packages/create/src/helpers.ts

+ 10 - 4
.github/workflows/verdaccio/config.yaml

@@ -1,7 +1,4 @@
 #
-# This is the default config file. It allows all users to do anything,
-# so don't use it on production systems.
-#
 # Look here for more config file examples:
 # https://github.com/verdaccio/verdaccio/tree/master/conf
 #
@@ -28,8 +25,17 @@ uplinks:
   npmjs:
     url: https://registry.npmjs.org/
     timeout: 10m
-    max_fails: 20
+    fail_timeout: 10m
     cache: false
+    max_fails: 40
+    maxage: 30m
+    # See https://github.com/verdaccio/verdaccio/issues/1329
+    # Attempting to make install from Verdaccio more resilient in CI
+    agent_options:
+      keepAlive: true
+      maxSockets: 40
+      maxFreeSockets: 10
+
 
 packages:
   '@*/*':

+ 15 - 11
packages/create/src/helpers.ts

@@ -42,11 +42,11 @@ export function isSafeToCreateProjectIn(root: string, name: string) {
 
     const conflicts = fs
         .readdirSync(root)
-        .filter(file => !validFiles.includes(file))
+        .filter((file) => !validFiles.includes(file))
         // IntelliJ IDEA creates module files before CRA is launched
-        .filter(file => !/\.iml$/.test(file))
+        .filter((file) => !/\.iml$/.test(file))
         // Don't treat log files from previous installation as conflicts
-        .filter(file => !errorLogFilePatterns.some(pattern => file.indexOf(pattern) === 0));
+        .filter((file) => !errorLogFilePatterns.some((pattern) => file.indexOf(pattern) === 0));
 
     if (conflicts.length > 0) {
         console.log(`The directory ${chalk.green(name)} contains files that could conflict:`);
@@ -62,8 +62,8 @@ export function isSafeToCreateProjectIn(root: string, name: string) {
 
     // Remove any remnant files from a previous installation
     const currentFiles = fs.readdirSync(path.join(root));
-    currentFiles.forEach(file => {
-        errorLogFilePatterns.forEach(errorLogFilePattern => {
+    currentFiles.forEach((file) => {
+        errorLogFilePatterns.forEach((errorLogFilePattern) => {
             // This will catch `(npm-debug|yarn-error|yarn-debug).log*` files
             if (file.indexOf(errorLogFilePattern) === 0) {
                 fs.removeSync(path.join(root, file));
@@ -121,7 +121,7 @@ export function checkThatNpmCanReadCwd() {
     // "; cwd = C:\path\to\current\dir" (unquoted)
     // I couldn't find an easier way to get it.
     const prefix = '; cwd = ';
-    const line = lines.find(l => l.indexOf(prefix) === 0);
+    const line = lines.find((l) => l.indexOf(prefix) === 0);
     if (typeof line !== 'string') {
         // Fail gracefully. They could remove it.
         return true;
@@ -207,11 +207,14 @@ export function installPackages(
         }
 
         const child = spawn(command, args, { stdio: logLevel === 'silent' ? 'ignore' : 'inherit' });
-        child.on('close', code => {
+        child.on('close', (code) => {
             if (code !== 0) {
+                let message = 'An error occurred when installing dependencies.';
+                if (logLevel === 'silent') {
+                    message += ' Try running with `--log-level info` or `--log-level verbose` to diagnose.';
+                }
                 reject({
-                    message:
-                        'An error occurred when installing dependencies. Try running with `--log-level info` to diagnose.',
+                    message,
                     command: `${command} ${args.join(' ')}`,
                 });
                 return;
@@ -340,8 +343,9 @@ async function checkPostgresDbExists(options: any, root: string): Promise<true>
 function throwConnectionError(err: any) {
     throw new Error(
         `Could not connect to the database. ` +
-            `Please check the connection settings in your Vendure config.\n[${err.message ||
-                err.toString()}]`,
+            `Please check the connection settings in your Vendure config.\n[${
+                err.message || err.toString()
+            }]`,
     );
 }