Skip to content

Commit 00da951

Browse files
committed
👷 split ci and cd due to security reason
1 parent 5e0a923 commit 00da951

File tree

3 files changed

+147
-45
lines changed

3 files changed

+147
-45
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
2+
name: Site Deploy (Preview CD)
3+
4+
on:
5+
workflow_run:
6+
workflows: ["Site Deploy (Preview CI)"]
7+
types:
8+
- completed
9+
10+
jobs:
11+
preview-cd:
12+
runs-on: ubuntu-latest
13+
concurrency:
14+
group: pull-request-preview-${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}
15+
cancel-in-progress: true
16+
17+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
18+
19+
environment: pull request
20+
21+
permissions:
22+
actions: read
23+
statuses: write
24+
pull-requests: write
25+
26+
steps:
27+
- name: Set Commit Status
28+
uses: actions/github-script@v8
29+
with:
30+
script: |
31+
github.rest.repos.createCommitStatus({
32+
owner: context.repo.owner,
33+
repo: context.repo.repo,
34+
sha: context.payload.workflow_run.head_sha,
35+
context: 'Website Preview',
36+
description: 'Deploying...',
37+
state: 'pending',
38+
})
39+
40+
- name: Download Artifact
41+
uses: actions/download-artifact@v7
42+
with:
43+
name: website-preview
44+
github-token: ${{ secrets.GITHUB_TOKEN }}
45+
run-id: ${{ github.event.workflow_run.id }}
46+
47+
- name: Restore Context
48+
run: |
49+
PR_NUMBER=$(cat ./pr-number)
50+
if ! [[ "${PR_NUMBER}" =~ ^[0-9]+$ ]]; then
51+
echo "Invalid PR number: ${PR_NUMBER}"
52+
exit 1
53+
fi
54+
echo "PR_NUMBER=${PR_NUMBER}" >> "${GITHUB_ENV}"
55+
56+
- name: Set Deploy Name
57+
run: |
58+
echo "DEPLOY_NAME=deploy-preview-${PR_NUMBER}" >> "${GITHUB_ENV}"
59+
60+
- name: Deploy to Netlify
61+
id: deploy
62+
uses: nwtgck/actions-netlify@v3
63+
with:
64+
publish-dir: ./website/build
65+
production-deploy: false
66+
deploy-message: "Deploy ${{ env.DEPLOY_NAME }}@${{ github.event.workflow_run.head_sha }}"
67+
alias: ${{ env.DEPLOY_NAME }}
68+
env:
69+
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
70+
NETLIFY_SITE_ID: ${{ secrets.SITE_ID }}
71+
72+
# action netlify has no pull request context, so we need to comment by ourselves
73+
- name: Comment on Pull Request
74+
uses: marocchino/sticky-pull-request-comment@v2
75+
with:
76+
header: website
77+
number: ${{ env.PR_NUMBER }}
78+
message: |
79+
:rocket: Deployed to ${{ steps.deploy.outputs.deploy-url }}
80+
81+
- name: Set Commit Status
82+
uses: actions/github-script@v8
83+
if: always()
84+
with:
85+
script: |
86+
if (`${{ job.status }}` === 'success') {
87+
github.rest.repos.createCommitStatus({
88+
owner: context.repo.owner,
89+
repo: context.repo.repo,
90+
sha: context.payload.workflow_run.head_sha,
91+
context: 'Website Preview',
92+
description: `Deployed to ${{ steps.deploy.outputs.deploy-url }}`,
93+
state: 'success',
94+
target_url: `${{ steps.deploy.outputs.deploy-url }}`,
95+
})
96+
} else {
97+
github.rest.repos.createCommitStatus({
98+
owner: context.repo.owner,
99+
repo: context.repo.repo,
100+
sha: context.payload.workflow_run.head_sha,
101+
context: 'Website Preview',
102+
description: `Deploy ${{ job.status }}`,
103+
state: 'failure',
104+
})
105+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Site Deploy (Preview CI)
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
preview-ci:
8+
runs-on: ubuntu-latest
9+
concurrency:
10+
group: pull-request-preview-${{ github.event.number }}
11+
cancel-in-progress: true
12+
13+
steps:
14+
- uses: actions/checkout@v6
15+
with:
16+
ref: ${{ github.event.pull_request.head.sha }}
17+
fetch-depth: 0
18+
19+
- name: Setup Python Environment
20+
uses: ./.github/actions/setup-python
21+
22+
- name: Setup Node Environment
23+
uses: ./.github/actions/setup-node
24+
25+
- name: Build API Doc
26+
uses: ./.github/actions/build-api-doc
27+
28+
- name: Build Doc
29+
run: yarn build
30+
31+
- name: Export Context
32+
run: |
33+
echo "${{ github.event.pull_request.number }}" > ./pr-number
34+
35+
- name: Upload Artifact
36+
uses: actions/upload-artifact@v6
37+
with:
38+
name: website-preview
39+
path: |
40+
./website/build
41+
./pr-number
42+
retention-days: 1

.github/workflows/website-preview.yml

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)