test_workflows1 #26
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} | |
" |