You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by wa...@apache.org on 2021/09/21 17:41:21 UTC
[echarts-website] branch asf-site updated: add workflow to purge
changed files after push
This is an automated email from the ASF dual-hosted git repository.
wangzx pushed a commit to branch asf-site
in repository https://gitbox.apache.org/repos/asf/echarts-website.git
The following commit(s) were added to refs/heads/asf-site by this push:
new 28fe584 add workflow to purge changed files after push
28fe584 is described below
commit 28fe584a3403ca4167809d38f2f084902cdcf906
Author: plainheart <yh...@all-my-life.cn>
AuthorDate: Wed Sep 22 01:38:53 2021 +0800
add workflow to purge changed files after push
---
.github/workflows/check-links.yml | 2 +-
.github/workflows/purge-cdn.yml | 32 +++++++++++++++++++++++
.scripts/package.json | 3 ++-
.scripts/purgeCDN.js | 53 +++++++++++++++++++++++++++++++++++++++
4 files changed, 88 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/check-links.yml b/.github/workflows/check-links.yml
index a3236ea..bb33517 100644
--- a/.github/workflows/check-links.yml
+++ b/.github/workflows/check-links.yml
@@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
- uses: actions/setup-node@v1
+ uses: actions/setup-node@v2
with:
registry-url: https://registry.npmjs.org/
- name: Check links
diff --git a/.github/workflows/purge-cdn.yml b/.github/workflows/purge-cdn.yml
new file mode 100644
index 0000000..a39a081
--- /dev/null
+++ b/.github/workflows/purge-cdn.yml
@@ -0,0 +1,32 @@
+name: Check Changed Files & Purge CDN
+
+on:
+ push:
+ branches: [ asf-site ]
+
+ workflow_dispatch:
+
+jobs:
+ 'Check-Changed-Files-Purge-CDN':
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v2
+ with:
+ fetch-depth: 2
+
+ - name: Get changed files
+ id: changed-files
+ uses: tj-actions/changed-files@v1.1.2
+ with:
+ separator: ","
+ files: |
+ ^[^\.]
+
+ - name: Purge changed files
+ run: |
+ npm i
+ node purgeCDN.js --files ${{ steps.changed-files.outputs.all_modified_files }}
+ working-directory: .scripts
+
+
diff --git a/.scripts/package.json b/.scripts/package.json
index befa8b9..818aa3a 100644
--- a/.scripts/package.json
+++ b/.scripts/package.json
@@ -5,6 +5,7 @@
"globby": "^11.0.3"
},
"devDependencies": {
- "node-fetch": "^2.6.1"
+ "node-fetch": "^2.6.1",
+ "minimist": "^1.2.5"
}
}
diff --git a/.scripts/purgeCDN.js b/.scripts/purgeCDN.js
new file mode 100644
index 0000000..8af4d8f
--- /dev/null
+++ b/.scripts/purgeCDN.js
@@ -0,0 +1,53 @@
+const {runTasks} = require('./task');
+const fetch = require('node-fetch').default;
+const argv = require('minimist')(process.argv.slice(2));
+
+const files = typeof argv.files === 'string' && argv.files.split(',');
+
+if (!files || !files.length) {
+ return console.log('No files to be purged');
+}
+
+function getCdnUrl(fileUrl) {
+ return `https://cdn.jsdelivr.net/gh/apache/echarts-website@asf-site/${fileUrl}`;
+}
+
+function getPurgeUrl(fileUrl) {
+ return `https://purge.jsdelivr.net/gh/apache/echarts-website@asf-site/${fileUrl}`;
+}
+
+function purge(url) {
+ return fetch(encodeURI(url))
+ .then(res => res.json())
+ .then(res => {
+ if (res.status === 'finished') {
+ console.log('Purged', url);
+ }
+ else {
+ console.error('failed to purge', url, res);
+ }
+ });
+}
+
+async function run() {
+ console.log(`Purging ${files.length} changed files...`);
+
+ const totalLen = files.length;
+ let finished = 0;
+ let purged = 0;
+ await runTasks(files, async(filePath) => {
+ try {
+ await purge(getPurgeUrl(filePath));
+ purged++;
+ }
+ catch (e) {
+ console.error('failed to purge', filePath);
+ console.error(e);
+ }
+ finished++;
+ console.log(`${finished} / ${totalLen} (${(finished / totalLen * 100).toFixed(0)}%)`)
+ }, 10);
+ console.log(`Purged ${purged} successfully`);
+}
+
+run();
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org