Skip to content

Merge pull request #73 from PyAmsterdam/upgrade-pelican-4-11 #30

Merge pull request #73 from PyAmsterdam/upgrade-pelican-4-11

Merge pull request #73 from PyAmsterdam/upgrade-pelican-4-11 #30

name: Deploy to GitHub Pages
on:
push:
branches: [master]
pull_request:
branches: [master]
workflow_dispatch:
concurrency:
group: pages-${{ github.head_ref || github.ref }}
cancel-in-progress: true
permissions:
contents: read
env:
PYTHON_VERSION: '3.11'
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v5
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Cache pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
- name: Build site for production
run: |
make prod
- name: Remove custom domain for PR previews
if: github.event_name == 'pull_request'
run: rm -f output/CNAME
- name: Upload preview artifact
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
with:
name: site-preview
path: output
- name: Comment preview link
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
env:
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
with:
script: |
const body = `Preview build ready: [download site-preview artifact](${process.env.RUN_URL})`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body
});
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v4
with:
path: output
deploy:
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
permissions:
contents: read
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
deploy_preview:
needs: build
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false
runs-on: ubuntu-latest
permissions:
contents: read
pages: write
id-token: write
environment:
name: pr-${{ github.event.number }}
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy PR preview to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
with:
preview: true
- name: Publish preview URL
run: |
echo "Preview URL: ${{ steps.deployment.outputs.page_url }}" >> $GITHUB_STEP_SUMMARY