Skip to content

Deploy Hugo site to Pages #324

Deploy Hugo site to Pages

Deploy Hugo site to Pages #324

Workflow file for this run

name: Deploy Hugo site to Pages
on:
push:
branches:
- main
schedule:
- cron: "0 1 * * *" # Runs daily at 1 AM UTC
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
defaults:
run:
shell: bash
jobs:
build:
runs-on: ubuntu-latest
environment: hugo
env:
HUGO_VERSION: 0.141.0
steps:
- name: Trigger Events JSON Workflow in ical2json
run: |
set -euo pipefail
echo "Triggering workflow dispatch in codersonlych/ical2json"
RESPONSE=$(mktemp)
STATUS_CODE=$(curl -s -o "$RESPONSE" -w "%{http_code}" \
-X POST \
-H "Authorization: Bearer ${{ secrets.REPO_PAT }}" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/codersonlych/ical2json/actions/workflows/update-events.yaml/dispatches \
-d '{"ref":"main"}')
if [ "$STATUS_CODE" -ne 204 ]; then
echo "::error ::Workflow dispatch failed with status code $STATUS_CODE"
cat "$RESPONSE"
exit 1
else
echo "Workflow dispatch succeeded"
fi
- name: Install Hugo CLI
run: |
wget -O ${{ runner.temp }}/hugo.deb \
https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Download Latest Events JSON Artifact
run: |
RUN_ID=$(curl -s \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/codersonlych/ical2json/actions/runs?branch=main&status=completed&per_page=1" \
| jq -r '.workflow_runs[0].id')
echo "Run ID: $RUN_ID"
ARTIFACT_ID=$(curl -s \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/codersonlych/ical2json/actions/runs/${RUN_ID}/artifacts" \
| jq -r '.artifacts[] | select(.name=="events-json") | .id')
echo "Artifact ID: $ARTIFACT_ID"
curl -s \
-L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-o artifact.zip \
"https://api.github.com/repos/codersonlych/ical2json/actions/artifacts/${ARTIFACT_ID}/zip"
if file artifact.zip | grep -q 'Zip archive data'; then
unzip -o artifact.zip -d assets/
ls -lah assets/
else
echo "Downloaded artifact is not a valid zip file."
cat artifact.zip
exit 1
fi
- name: Setup Pages
id: pages
uses: actions/configure-pages@v5
- name: Build with Hugo
env:
HUGO_CACHEDIR: ${{ runner.temp }}/hugo_cache
HUGO_ENVIRONMENT: production
TZ: Europe/Zurich
run: |
hugo \
--gc \
--minify \
--baseURL "${{ steps.pages.outputs.base_url }}/"
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./public
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4