This is an automated email from the ASF dual-hosted git repository.

wangzx pushed a commit to branch gh-pages
in repository https://gitbox.apache.org/repos/asf/echarts-examples.git


The following commit(s) were added to refs/heads/gh-pages by this push:
     new 8120d791 feat: also sync zrender nightly
8120d791 is described below

commit 8120d79117a7569e7cc3ece2c75190842c520855
Author: plainheart <y...@all-my-life.cn>
AuthorDate: Fri Jul 5 11:43:45 2024 +0800

    feat: also sync zrender nightly
---
 .github/workflows/.scripts/sync-nightly-mirror.js | 80 ++++++++++++-----------
 .github/workflows/sync-nightly-mirror.yaml        | 10 ++-
 2 files changed, 51 insertions(+), 39 deletions(-)

diff --git a/.github/workflows/.scripts/sync-nightly-mirror.js 
b/.github/workflows/.scripts/sync-nightly-mirror.js
index e93e31f7..f6c5edc0 100644
--- a/.github/workflows/.scripts/sync-nightly-mirror.js
+++ b/.github/workflows/.scripts/sync-nightly-mirror.js
@@ -1,55 +1,61 @@
-const SYNC_URL = 'https://registry-direct.npmmirror.com/echarts-nightly/sync';
-
-let timer;
-
-async function getSyncLog(id) {
-  const data = await (await fetch(SYNC_URL + '/log/' + id)).json();
-  if (!data.ok) {
-    return;
-  }
-
-  const log = data.log || '';
-  console.log('Sync log:', log);
-  if (log.includes('Fail: [')) {
-    const failInfo = log.match(/Fail: \[ (.*?) \]/);
-    if (failInfo && failInfo[1]) {
-      throw new Error('Sync failed!');
-    }
-  }
-  if (data.syncDone) {
-    clearInterval(timer);
-    console.log('Sync successfully!');
-    try {
-      const fullLog = await (await fetch(data.logUrl)).text();
-      console.log('Sync full log:\n', fullLog);
-    } catch {}
-  }
-}
-
-async function sync(retryCount = 0) {
-  console.log(`Start to sync nightly mirror...`);
+/**
+ * @param {string} pkgName
+ * @param {number} [retryCount=3]
+ */
+async function sync(pkgName, retryCount = 3) {
+  const tag = `[${pkgName}]`;
+  const action = 'sync mirror';
+  const syncUrl = `https://registry-direct.npmmirror.com/${pkgName}/sync`;
+  console.log(tag, `Start to ${action}...`);
   try {
     const data = await (
-      await fetch(SYNC_URL, {
+      await fetch(syncUrl, {
         method: 'PUT',
         query: {
           sync_upstream: true
         }
       })
     ).json();
-    console.log('Sync request data', data);
+    console.log(tag, 'Sync request data', data);
     if (!data.ok) {
-      throw new Error('Sync request error!');
+      throw new Error(tag + ' Sync request error!');
     }
-    timer = setInterval(() => getSyncLog(data.logId), 2e3);
+    const timer = setInterval(async () => {
+      const logData = await (
+        await fetch(syncUrl + '/log/' + data.logId)
+      ).json();
+      if (!logData.ok) {
+        return;
+      }
+      const log = logData.log || '';
+      console.log(tag, 'Sync log:', log);
+      if (log.includes('Fail: [')) {
+        const failInfo = log.match(/Fail: \[ (.*?) \]/);
+        if (failInfo && failInfo[1]) {
+          throw new Error(tag + ' Sync failed!');
+        }
+      }
+      if (logData.syncDone) {
+        clearInterval(timer);
+        console.log(tag, 'Sync successfully!');
+        try {
+          const fullLog = await (await fetch(logData.logUrl)).text();
+          console.log(tag, 'Sync full log:\n', fullLog);
+        } catch {}
+      }
+    }, 2e3);
   } catch (e) {
-    console.error('failed to sync nightly mirror', e);
+    console.error(tag, `failed to ${action}`, e);
     if (!retryCount) {
       throw e;
     }
-    console.log('Retry to sync nightly mirror...', retryCount);
+    console.log(tag, `Retry to ${action}...`, retryCount);
     sync(--retryCount);
   }
 }
 
-sync(3);
+const pkgName = process.argv[2];
+if (!pkgName) {
+  throw new Error('No package to sync');
+}
+sync(pkgName);
diff --git a/.github/workflows/sync-nightly-mirror.yaml 
b/.github/workflows/sync-nightly-mirror.yaml
index 9cd4e4a0..5a54cbca 100644
--- a/.github/workflows/sync-nightly-mirror.yaml
+++ b/.github/workflows/sync-nightly-mirror.yaml
@@ -22,5 +22,11 @@ jobs:
           node-version: latest
           registry-url: https://registry.npmjs.org/
 
-      - name: Sync
-        run: node --unhandled-rejections=strict 
${{env.WORKFLOW_SCRIPTS_DIR}}/sync-nightly-mirror.js
+      - name: Sync zrender-nightly
+        working-directory: ${{env.WORKFLOW_SCRIPTS_DIR}}
+        run: node --unhandled-rejections=strict sync-nightly-mirror.js 
zrender-nightly
+        continue-on-error: true
+
+      - name: Sync echarts-nightly
+        working-directory: ${{env.WORKFLOW_SCRIPTS_DIR}}
+        run: node --unhandled-rejections=strict sync-nightly-mirror.js 
echarts-nightly


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org
For additional commands, e-mail: commits-h...@echarts.apache.org

Reply via email to