Deploy preview site to review pull requests #5

Merged
btlogy merged 32 commits from 1.site-preview into main 2024-05-24 11:08:07 +00:00
2 changed files with 24 additions and 11 deletions
Showing only changes of commit a0d865d21b - Show all commits

View File

@ -6,13 +6,13 @@ comment:
files:
- '**'
body: |
#### :hammer: Docker image `{{ imageOutcome }}`
#### :hammer: Docker build `{{ imageOutcome }}`
- id: build-{{ buildOutcome }}
files:
- '**'
body: |
#### :mag: Jekyll build `{{ buildOutcome }}`
#### :wrench: Jekyll build `{{ buildOutcome }}`
<details><summary>Build Output</summary>
```
@ -26,7 +26,7 @@ comment:
- '**'
body: |
#### :rocket: Jekyll deploy `{{ deployOutcome }}`
#### :link: Preview documentation [here](https://www.lafs.eval.latfa.net/{{ deployPrefix}}/{{ deploySuffix }})
#### :link: Preview site [here](https://{{ deployWebHost }}{{ deployWebContext }})
- id: pusher-{{ gitActor }}-{{ gitEventName }}-{{ gitRunNumber }}
files:

View File

@ -8,8 +8,9 @@ on:
env:
_UID: 1000
_GID: 1000
PREFIX: site
SUFFIX: preview
WEB_DOMAIN: lafs.eval.latfa.net
WEB_USER: www
WEB_DIR: /var/www
jobs:
jekyll:
runs-on: ubuntu-22.04
@ -54,11 +55,23 @@ jobs:
chmod 600 ~/.ssh/id_ed25519
- name: Deploy Jekyll site
id: deploy_site
if: ${{ gitea.ref == 'refs/heads/main' }}
run: |
rsync -halvi \
if [ "${{ gitea.ref }}" = 'refs/heads/main' ]; then
WEB_ROOT="${WEB_DIR}/site"
WEB_HOST="www.${WEB_DOMAIN}"
WEB_CONTEXT='/'
else
WEB_ROOT="${WEB_DIR}/preview"
WEB_HOST="preview.${WEB_DOMAIN}"
WEB_CONTEXT='/{{ gitea.event.pull_request.number }}/'
end
# Save those variabes in the environment for the next steps
echo "WEB_HOST=${WEB_HOST}" >> $GITEA_ENV
echo "WEB_CONTEXT=${WEB_CONTEXT}" >> $GITEA_ENV
# Synchronize the local and the remote site
rsync -halvi --delete \
-e "ssh -a -x -o StrictHostKeyChecking=no" \
./_site/ www@lafs.eval.latfa.net:/var/www/site/
"./_site/${WEB_USER}@${WEB_DOMAIN}:${WEB_ROOT}${WEB_CONTEXT}"
- name: Comment pull request
id: comment_pull_request
if: gitea.event_name == 'pull_request'
@ -70,8 +83,8 @@ jobs:
"buildOutcome": "${{ steps.build_site.outcome }}",
"buildOutputsResult": ${{ toJSON(steps.build_site.outputs.result) }},
"deployOutcome": "${{ steps.deploy_site.outcome }}",
"deployPrefix": "${{ env.PREFIX }}",
"deploySuffix": "${{ env.SUFFIX }}",
"deployWebHost": "${{ env.WEB_HOST }}",
"deployWebContext": "${{ env.WEB_CONTEXT }}",
"gitActor": "${{ gitea.actor }}",
"gitEventName": "${{ gitea.event_name }}",
"gitWorkflow": "${{ gitea.workflow }}",
@ -83,5 +96,5 @@ jobs:
id: fail-on-error
if: |
steps.build_site.outcome != 'success'
|| (github.event_name == 'pull_request' && steps.deploy_site.outcome != 'success')
|| (gittea.event_name == 'pull_request' && steps.deploy_site.outcome != 'success')
run: exit 1