Skip to content

Commit 7dd9b37

Browse files
committed
chore: merge
2 parents 01df82a + fd9e62d commit 7dd9b37

File tree

103 files changed

+19749
-15057
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+19749
-15057
lines changed

.github/workflows/ci.yml

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ name: Node CI
22

33
on:
44
pull_request:
5-
types: [opened, synchronize]
5+
types: [opened, reopened, synchronize]
6+
7+
concurrency:
8+
# Note that the `teardown-pr-preview` workflow needs the same group name
9+
# to cancel the running `ci` workflows
10+
group: ${{ github.workflow }}-${{ github.event.number }}
11+
cancel-in-progress: true
612

713
jobs:
814
lint:
@@ -81,11 +87,43 @@ jobs:
8187
if: steps.cache-dep.outputs.cache-hit != 'true'
8288
run: npm ci
8389

90+
- name: Unit Test
91+
run: npm run test
92+
8493
- name: Build release
8594
run: npm run release
8695

8796
- name: Test generated DTS
8897
run: npm run test:dts
8998

90-
- name: Unit Test
91-
run: npm run test
99+
- name: Pack npm tarball
100+
if: ${{ github.repository_owner == 'apache' }}
101+
id: pack-tarball
102+
run: |
103+
export PR_PREVIEW_DIR='echarts-pr-preview'
104+
mkdir -p $PR_PREVIEW_DIR
105+
npm pack -pack-destination $PR_PREVIEW_DIR
106+
echo "PR_PREVIEW_DIR=$PR_PREVIEW_DIR" >> $GITHUB_ENV
107+
108+
- name: Save PR metadata and dist files
109+
if: ${{ steps.pack-tarball.outcome == 'success' }}
110+
id: save-pr-data
111+
env:
112+
PR_NUMBER: ${{ github.event.number }}
113+
PR_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
114+
PR_PREVIEW_DIR: ${{ env.PR_PREVIEW_DIR }}
115+
run: |
116+
cd $PR_PREVIEW_DIR
117+
echo $PR_NUMBER > ./pr_number
118+
echo $PR_COMMIT_SHA > ./pr_commit_sha
119+
find . -type f -regex ".*\.tgz" -exec tar xvzf {} \;
120+
rm -f *.tgz
121+
echo -e "Dist files: \n$(ls -l)"
122+
123+
- uses: actions/upload-artifact@v3
124+
if: ${{ steps.save-pr-data.outcome == 'success' }}
125+
with:
126+
name: pr_preview
127+
path: ${{ env.PR_PREVIEW_DIR }}
128+
retention-days: 1
129+
if-no-files-found: error

.github/workflows/pr-preview.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Deploy PR Preview
2+
3+
on:
4+
workflow_run:
5+
workflows: ['Node CI']
6+
types: [completed]
7+
8+
jobs:
9+
on-success:
10+
if: ${{ github.repository_owner == 'apache' }}
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Determine if workflow build job is successful
15+
id: check-build-success
16+
uses: actions/github-script@v6
17+
with:
18+
result-encoding: string
19+
script: |
20+
const jobsRes = await github.rest.actions.listJobsForWorkflowRun({
21+
owner: context.repo.owner,
22+
repo: context.repo.repo,
23+
run_id: context.payload.workflow_run.id
24+
});
25+
return jobsRes.data.jobs.some((job) => job.name.includes('build') && job.conclusion === 'success');
26+
27+
outputs:
28+
SHOULD_DEPOLY: ${{ steps.check-build-success.outputs.result }}
29+
30+
deploy:
31+
needs: [on-success]
32+
if: ${{ needs.on-success.outputs.SHOULD_DEPOLY == 'true' }}
33+
runs-on: ubuntu-latest
34+
35+
steps:
36+
- name: Install action dependencies
37+
run: |
38+
mkdir .actions
39+
cd .actions
40+
git clone --depth=1 https://github.com/dawidd6/action-download-artifact.git
41+
git clone --depth=1 https://github.com/actions-cool/maintain-one-comment.git
42+
43+
- name: Fetch PR dist files
44+
uses: ./.actions/action-download-artifact
45+
with:
46+
workflow: ${{ github.event.workflow.id }}
47+
run_id: ${{ github.event.workflow_run.id }}
48+
name: pr_preview
49+
if_no_artifact_found: fail
50+
51+
- name: Output PR metadata
52+
id: pr-metadata
53+
run: |
54+
echo "NUMBER=$(cat pr_number)" >> $GITHUB_OUTPUT
55+
echo "COMMIT_SHA=$(cat pr_commit_sha)" >> $GITHUB_OUTPUT
56+
echo "COMMIT_SHA_SHORT=$(cat pr_commit_sha | cut -c 1-7)" >> $GITHUB_OUTPUT
57+
58+
- name: Deploy dist files
59+
env:
60+
PR_NUMBER: ${{ steps.pr-metadata.outputs.NUMBER }}
61+
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
62+
run: |
63+
export SURGE_DOMAIN=https://echarts-pr-$PR_NUMBER.surge.sh
64+
npx surge --project ./package --domain $SURGE_DOMAIN --token $SURGE_TOKEN
65+
66+
- name: Create comment for PR preview
67+
uses: ./.actions/maintain-one-comment
68+
env:
69+
PR_NUMBER: ${{ steps.pr-metadata.outputs.NUMBER }}
70+
COMMIT_SHA_SHORT: ${{ steps.pr-metadata.outputs.COMMIT_SHA_SHORT }}
71+
with:
72+
body: |
73+
<!-- ECHARTS_PR_PREVIEW -->
74+
The changes brought by this PR can be previewed at: https://echarts.apache.org/examples/editor?version=PR-${{ env.PR_NUMBER }}@${{ env.COMMIT_SHA_SHORT }}
75+
body-include: '<!-- ECHARTS_PR_PREVIEW -->'
76+
number: ${{ env.PR_NUMBER }}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Teardown PR Preview
2+
3+
on:
4+
pull_request_target:
5+
types: [closed]
6+
7+
jobs:
8+
teardown-pr-preview:
9+
if: ${{ github.repository_owner == 'apache' && github.event.action == 'closed' && github.event.pull_request.merged != true }}
10+
concurrency:
11+
# to cancel running `ci` workflows in current PR
12+
group: 'Node CI-${{ github.event.number }}'
13+
cancel-in-progress: true
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Install action dependencies
17+
run: git clone --depth=1 https://github.com/actions-cool/maintain-one-comment.git
18+
19+
- name: Delete PR preview comment
20+
uses: ./maintain-one-comment
21+
with:
22+
body-include: '<!-- ECHARTS_PR_PREVIEW -->'
23+
delete: true
24+
number: ${{ github.event.number }}
25+
26+
- name: Teardown closed PR preview
27+
continue-on-error: true
28+
run: |
29+
export SURGE_DOMAIN='https://echarts-pr-${{ github.event.number }}.surge.sh'
30+
npx surge teardown $SURGE_DOMAIN --token ${{ secrets.SURGE_TOKEN }}

.husky/pre-commit

100644100755
File mode changed.

0 commit comments

Comments
 (0)