-
Notifications
You must be signed in to change notification settings - Fork 128
64 lines (58 loc) · 2.16 KB
/
Deploy Documentation 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
# Inspiration: https://github.com/ACCESS-Hive/access-hive.github.io/pull/126
# For security, we do not want to checkout and run code from forks (could lead to secrets being leaked)
# So split documentation build/preview into discrete steps
name: Deploy documentation preview
# If the documentation build completed successfully, then download the generated artifact
# and upload it to github pages
on:
workflow_run:
workflows: ["Build Documentation preview"]
types:
- completed
concurrency:
group: preview-${{ github.ref }}
cancel-in-progress: true
jobs:
deploy-preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Will download all artifacts
# If artifact name == preview_site, then we have a site to reply
# If artifact name == closed_pr_number, then we need to cleanup an old deployment
- name: Download artifacts
uses: dawidd6/action-download-artifact@v5
with:
run_id: ${{github.event.workflow_run.id }}
path: ./artifacts
- name: Check artifact name
run: |
if [ -d "./artifacts/preview_site" ]; then
echo "mode=deploy" >> "$GITHUB_ENV"
elif [ -d "./artifacts/closed_pr_number" ]; then
echo "mode=clean" >> "$GITHUB_ENV"
else
echo "Failed to find artifact"
exit 1
fi
# Get PR number
- if: ${{ env.mode == 'deploy' }}
name: Get PR number (deploy)
run: echo "pr_number=$(cat ./artifacts/preview_site/pr_number)" >> "$GITHUB_ENV"
- if: ${{ env.mode == 'clean' }}
name: Get PR number (clean)
run: echo "pr_number=$(cat ./artifacts/closed_pr_number/pr_number)" >> "$GITHUB_ENV"
# Run deployment
- if: ${{ env.mode == 'deploy' }}
name: Deploy preview
uses: access-nri/pr-preview-action@v2
with:
source-dir: ./artifacts/preview_site
action: deploy
pr-number: ${{ env.pr_number }}
- if: ${{ env.mode == 'clean' }}
name: Clean preview
uses: access-nri/pr-preview-action@v2
with:
action: remove
pr-number: ${{ env.pr_number }}