Deploy a Pelican site with GitHub Actions to GitHub Pages

This blog is powered by Pelian. It is a static site generator that requires no database or server-side logic and generates your website based on the content which is written in reStructuredText or Markdown.

I host this site with GitHub Pages. So I though its the best choice to automatically deploy my changes (e.g. content or theme/template) and update my site as well on GitHub Pages by using GitHub Actions.

My deployment workflow based on the following GitHub Actions:

In the first step I checkout my GitHub repository with actions/checkout which holds my content and theme data of this site. Afterwards I prepare the python environment to install the needed python dependencies (e.g. pelican) to build my site based on the content and the templates. Finally I use the Github action JamesIves/github-pages-deploy-action to deploy the build results to GitHub Pages. This Actions takes the build results of pelican. In my case from the directory build and commit/push these to the corresponding branch (e.g. gh-pages).

This results in the following GitHub Actions workflow.


name: Deployment

env:
  PELICAN_CONTENT_DIR: content
  PELICAN_BUILD_DIR: build
  PELICAN_CONFIG_FILE: pelicanconf.py

on:
  push:
    branches:
      - main

permissions:
  contents: write

jobs:
  build:
    concurrency: ci-${{ github.ref }}
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup python
        uses: actions/setup-python@v4
        with:
          python-version: "3.11"

      - name: Install dependencies
        run: |
          pip install --upgrade pip
          pip install -r requirements.txt

      - name: Build with pelican
        run: pelican $PELICAN_CONTENT_DIR -o $PELICAN_BUILD_DIR -s $PELICAN_CONFIG_FILE

      - name: Deploy
        uses: JamesIves/github-pages-deploy-action@v4
        with:
          folder: ${{ env.PELICAN_BUILD_DIR }}
          branch: gh-pages

Update (21.11.2023): With version 4.9.0 Pelikan comes with a custom GitHub Actions workflow.

#GitHub #GithubActions #GitHubPages #Pelican