-
Notifications
You must be signed in to change notification settings - Fork 19.6k
75 lines (65 loc) · 2.59 KB
/
pr-preview.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
name: Deploy PR Preview
on:
workflow_run:
workflows: ['Node CI']
types: [completed]
jobs:
on-success:
if: ${{ github.repository_owner == 'apache' }}
runs-on: ubuntu-latest
steps:
- name: Determine if workflow build job is successful
id: check-build-success
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const jobsRes = await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id
});
return jobsRes.data.jobs.some((job) => job.name.includes('build') && job.conclusion === 'success');
outputs:
SHOULD_DEPLOY: ${{ steps.check-build-success.outputs.result }}
deploy:
needs: [on-success]
if: ${{ needs.on-success.outputs.SHOULD_DEPLOY == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Install action dependencies
run: |
mkdir .actions
cd .actions
git clone --depth=1 https://github.com/dawidd6/action-download-artifact.git
git clone --depth=1 https://github.com/plainheart/maintain-one-comment.git
- name: Fetch PR dist files
uses: ./.actions/action-download-artifact
with:
workflow: ${{ github.event.workflow.id }}
run_id: ${{ github.event.workflow_run.id }}
name: pr_preview
if_no_artifact_found: fail
- name: Output PR metadata
id: pr-metadata
run: |
echo "NUMBER=$(cat pr_number)" >> $GITHUB_OUTPUT
echo "COMMIT_SHA=$(cat pr_commit_sha)" >> $GITHUB_OUTPUT
echo "COMMIT_SHA_SHORT=$(cat pr_commit_sha | cut -c 1-7)" >> $GITHUB_OUTPUT
- name: Deploy dist files
env:
PR_NUMBER: ${{ steps.pr-metadata.outputs.NUMBER }}
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
run: |
export SURGE_DOMAIN=https://echarts-pr-$PR_NUMBER.surge.sh
npx surge --project ./package --domain $SURGE_DOMAIN --token $SURGE_TOKEN
- name: Create comment for PR preview
uses: ./.actions/maintain-one-comment
env:
PR_NUMBER: ${{ steps.pr-metadata.outputs.NUMBER }}
COMMIT_SHA_SHORT: ${{ steps.pr-metadata.outputs.COMMIT_SHA_SHORT }}
with:
body: |
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 }}
body-include: '<!-- ECHARTS_PR_PREVIEW -->'
number: ${{ env.PR_NUMBER }}