-
Notifications
You must be signed in to change notification settings - Fork 11
134 lines (113 loc) · 3.66 KB
/
deploy_to_github_pages.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: Deploy to GitHub Pages
on:
pull_request:
types:
- opened
- reopened
- synchronize
- closed
jobs:
pr-preview-setup:
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref != 'development' }}
runs-on: ubuntu-latest
steps:
- name: Get date
run: echo "DATE=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV
- name: Setup pr-preview
if: ${{ github.event.action != 'closed' }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-preview
number: ${{ github.event.number }}
message: "\
PR Preview
:---:
🛫 Deployment still ongoing.<br>
Preview URL will be available at the end of the deployment.
For more information, please check the [Actions](https://github.com/ACCESS-Hive/access-hive.github.io/actions) tab.
${{ env.DATE }}
"
- name: Remove pr-preview URL
if: ${{github.event.action == 'closed'}}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-preview
number: ${{ github.event.number }}
message: "\
PR Preview
:---:
🛬 Preview removed because the pull request was closed.
${{ env.DATE }}
"
build:
concurrency:
group: github-pages-deploy
cancel-in-progress: true
runs-on: ubuntu-latest
outputs:
pr_nums: ${{ steps.build.outputs.pr_nums }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: main
- name: Build full website # main, development and PRs
id: build
shell: bash
run: |
retry() {
command="$1"
n_tries="$2"
wait="$3"
exit_msg="$4"
eval "$command"
until [ $? == 0 ]; do
if [ $i -eq $((n_tries - 1)) ]; then
echo "$exit_msg"
exit 1
else
((i++))
fi
sleep $wait
eval "$command"
done
}
git fetch --all
echo "Build PR websites"
command="pr_list=\$(curl -s https://api.github.com/repos/ACCESS-Hive/access-hive.github.io/pulls?state=opened | jq '.[] | select(.head.label!=\"ACCESS-Hive:development\")')"
retry "$command" 5 1 "Failed to fetch opened PRs."
pr_nums=($(jq '.number' <<< $pr_list))
echo "pr_nums=$(sed 's/\s/,/g' <<< [${pr_nums[@]}])" >> "$GITHUB_OUTPUT"
echo ${pr_nums[@]}
deploy:
needs: build
runs-on: ubuntu-latest
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
steps:
- name: Deploy to GitHub Pages
shell: bash
run: ls -la
pr-preview:
needs: [build,deploy]
runs-on: ubuntu-latest
strategy:
matrix:
pr_nums: ${{fromJson(needs.build.outputs.pr_nums)}}
steps:
- name: Get date
run: echo "DATE=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV
- name: Set pr-preview URL
if: ${{github.event.action != 'closed'}}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-preview
number: ${{ matrix.pr_nums }}
message: "\
PR Preview
:---:
🚀 Deployed preview to
https://access-hive.org.au/pr-preview/pr-${{ matrix.pr_nums }}
${{ env.DATE }}
"