Skip to content

Commit

Permalink
feat: also sync zrender nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
plainheart committed Jul 5, 2024
1 parent 1c5f294 commit 8120d79
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 39 deletions.
80 changes: 43 additions & 37 deletions .github/workflows/.scripts/sync-nightly-mirror.js
Original file line number Diff line number Diff line change
@@ -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);
10 changes: 8 additions & 2 deletions .github/workflows/sync-nightly-mirror.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8120d79

Please sign in to comment.