2024-05-23 12:16:39 +00:00
|
|
|
name: Jekyll
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
pull_request:
|
|
|
|
|
|
|
|
env:
|
|
|
|
_UID: 1000
|
|
|
|
_GID: 1000
|
2024-05-24 08:12:27 +00:00
|
|
|
WEB_DOMAIN: lafs.eval.latfa.net
|
|
|
|
WEB_USER: www
|
|
|
|
WEB_DIR: /var/www
|
2024-05-23 12:16:39 +00:00
|
|
|
jobs:
|
|
|
|
jekyll:
|
|
|
|
runs-on: ubuntu-22.04
|
|
|
|
steps:
|
|
|
|
- name: Check out repository
|
|
|
|
id: checkout
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Change file ownership
|
|
|
|
id: file_ownership
|
|
|
|
run: |
|
|
|
|
chown -R ${_UID}:${_GID} .
|
2024-05-23 19:33:32 +00:00
|
|
|
- name: Install requirements
|
|
|
|
id: install_requirements
|
2024-05-23 12:16:39 +00:00
|
|
|
run: |
|
|
|
|
apt-get -q update
|
2024-05-23 19:33:32 +00:00
|
|
|
apt-get -q install -y docker-compose rsync
|
2024-05-23 12:16:39 +00:00
|
|
|
apt-get -q clean
|
|
|
|
- name: Verify docker
|
|
|
|
id: verify_docker
|
|
|
|
run: |
|
|
|
|
docker run --rm hello-world:latest > /dev/null
|
|
|
|
docker rmi hello-world:latest > /dev/null
|
|
|
|
docker version
|
|
|
|
docker-compose version
|
|
|
|
docker volume ls
|
|
|
|
- name: Build Jekyll image
|
|
|
|
id: build_image
|
|
|
|
run: |
|
|
|
|
# The environment variables _UID and _GID can impact this image
|
|
|
|
docker-compose build jekyll
|
|
|
|
- name: Build Jekyll site
|
|
|
|
id: build_site
|
|
|
|
run: |
|
2024-05-24 10:27:23 +00:00
|
|
|
# Overwrite the baseurl for previewonly
|
2024-05-24 10:33:19 +00:00
|
|
|
if [ "${{ gitea.event_name }}" = 'pull_request' ]; then
|
2024-05-24 10:30:47 +00:00
|
|
|
echo "Overwriting baseurl for pull_request ${{ gitea.event.pull_request.number }}"
|
2024-05-24 10:27:23 +00:00
|
|
|
sed -i -r -e 's/^baseurl:\s*"([^"]*)"/baseurl: "\1\/${{ gitea.event.pull_request.number }}"/' _config.yml
|
2024-05-24 10:34:27 +00:00
|
|
|
grep "^baseurl:" _config.yml
|
2024-05-24 10:27:23 +00:00
|
|
|
fi
|
2024-05-23 12:16:39 +00:00
|
|
|
docker-compose run --rm -v "${JOB_CONTAINER_NAME}:/site" -w /site \
|
|
|
|
jekyll build --verbose
|
2024-05-23 20:14:09 +00:00
|
|
|
continue-on-error: true
|
|
|
|
- name: Deploy Jekyll site
|
|
|
|
id: deploy_site
|
2024-05-23 19:33:32 +00:00
|
|
|
run: |
|
2024-05-24 08:12:27 +00:00
|
|
|
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}"
|
2024-05-24 08:24:26 +00:00
|
|
|
WEB_CONTEXT='/${{ gitea.event.pull_request.number }}/'
|
2024-05-24 08:26:35 +00:00
|
|
|
fi
|
2024-05-24 08:12:27 +00:00
|
|
|
# Save those variabes in the environment for the next steps
|
2024-05-24 08:35:11 +00:00
|
|
|
echo "WEB_HOST=${WEB_HOST}" >> $GITHUB_ENV
|
|
|
|
echo "WEB_CONTEXT=${WEB_CONTEXT}" >> $GITHUB_ENV
|
2024-05-24 08:59:19 +00:00
|
|
|
# Prepare ssh key
|
|
|
|
echo "${{ secrets.WWW_DEPLOY_KEY }}" > ~/.ssh/id_ed25519
|
|
|
|
chmod 600 ~/.ssh/id_ed25519
|
2024-05-24 08:12:27 +00:00
|
|
|
# Synchronize the local and the remote site
|
2024-05-24 08:54:36 +00:00
|
|
|
rsync -halvi --delete \
|
2024-05-23 19:33:32 +00:00
|
|
|
-e "ssh -a -x -o StrictHostKeyChecking=no" \
|
2024-05-24 08:54:36 +00:00
|
|
|
./_site/ "${WEB_USER}@${WEB_DOMAIN}:${WEB_ROOT}${WEB_CONTEXT}"
|
2024-05-24 08:45:48 +00:00
|
|
|
continue-on-error: true
|
2024-05-23 20:14:09 +00:00
|
|
|
- name: Comment pull request
|
|
|
|
id: comment_pull_request
|
|
|
|
if: gitea.event_name == 'pull_request'
|
2024-05-23 20:28:44 +00:00
|
|
|
uses: exercism/pr-commenter-action@v1.5.1
|
2024-05-23 20:14:09 +00:00
|
|
|
with:
|
|
|
|
template-variables: |
|
|
|
|
{
|
2024-05-23 20:28:44 +00:00
|
|
|
"imageOutcome": "${{ steps.build_image.outcome }}",
|
|
|
|
"buildOutcome": "${{ steps.build_site.outcome }}",
|
|
|
|
"buildOutputsResult": ${{ toJSON(steps.build_site.outputs.result) }},
|
|
|
|
"deployOutcome": "${{ steps.deploy_site.outcome }}",
|
2024-05-24 08:12:27 +00:00
|
|
|
"deployWebHost": "${{ env.WEB_HOST }}",
|
|
|
|
"deployWebContext": "${{ env.WEB_CONTEXT }}",
|
2024-05-23 20:28:44 +00:00
|
|
|
"gitActor": "${{ gitea.actor }}",
|
|
|
|
"gitEventName": "${{ gitea.event_name }}",
|
|
|
|
"gitWorkflow": "${{ gitea.workflow }}",
|
|
|
|
"gitRunNumber": "${{ gitea.run_number }}",
|
|
|
|
"gitRunAttempt": "${{ gitea.run_attempt }}"
|
2024-05-23 20:14:09 +00:00
|
|
|
}
|
2024-05-23 20:28:44 +00:00
|
|
|
config-file: ".gitea/pr-commenter.yml"
|
2024-05-23 20:14:09 +00:00
|
|
|
- name: Fail on error
|
|
|
|
id: fail-on-error
|
|
|
|
if: |
|
|
|
|
steps.build_site.outcome != 'success'
|
2024-05-24 10:33:19 +00:00
|
|
|
|| steps.deploy_site.outcome != 'success'
|
2024-05-23 20:14:09 +00:00
|
|
|
run: exit 1
|