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 ce0ab246 chore: add workflow to sync echarts nightly packages from npm 
mirror
ce0ab246 is described below

commit ce0ab2469d14084c6e27dce794302b4d73e395d5
Author: plainheart <[email protected]>
AuthorDate: Mon Jun 17 11:32:31 2024 +0800

    chore: add workflow to sync echarts nightly packages from npm mirror
---
 .github/workflows/.scripts/sync-nightly-mirror.js | 55 +++++++++++++++++++++++
 .github/workflows/sync-nightly-mirror.yaml        | 26 +++++++++++
 2 files changed, 81 insertions(+)

diff --git a/.github/workflows/.scripts/sync-nightly-mirror.js 
b/.github/workflows/.scripts/sync-nightly-mirror.js
new file mode 100644
index 00000000..e93e31f7
--- /dev/null
+++ b/.github/workflows/.scripts/sync-nightly-mirror.js
@@ -0,0 +1,55 @@
+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...`);
+  try {
+    const data = await (
+      await fetch(SYNC_URL, {
+        method: 'PUT',
+        query: {
+          sync_upstream: true
+        }
+      })
+    ).json();
+    console.log('Sync request data', data);
+    if (!data.ok) {
+      throw new Error('Sync request error!');
+    }
+    timer = setInterval(() => getSyncLog(data.logId), 2e3);
+  } catch (e) {
+    console.error('failed to sync nightly mirror', e);
+    if (!retryCount) {
+      throw e;
+    }
+    console.log('Retry to sync nightly mirror...', retryCount);
+    sync(--retryCount);
+  }
+}
+
+sync(3);
diff --git a/.github/workflows/sync-nightly-mirror.yaml 
b/.github/workflows/sync-nightly-mirror.yaml
new file mode 100644
index 00000000..9cd4e4a0
--- /dev/null
+++ b/.github/workflows/sync-nightly-mirror.yaml
@@ -0,0 +1,26 @@
+name: Synchronize Nightly Mirror
+
+on:
+  schedule:
+    - cron: '30 9 * * *'
+  workflow_dispatch:
+
+jobs:
+  sync-nightly-mirror:
+    runs-on: ubuntu-latest
+
+    env:
+      WORKFLOW_SCRIPTS_DIR: .github/workflows/.scripts
+
+    steps:
+      - uses: actions/checkout@v4
+        with:
+          sparse-checkout: ${{env.WORKFLOW_SCRIPTS_DIR}}
+
+      - uses: actions/setup-node@v4
+        with:
+          node-version: latest
+          registry-url: https://registry.npmjs.org/
+
+      - name: Sync
+        run: node --unhandled-rejections=strict 
${{env.WORKFLOW_SCRIPTS_DIR}}/sync-nightly-mirror.js


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to