Build Pelican static website using GitHub actions


GitHub enables the delivery of static contents using GitHub Pages. That is, you create a GitHub repository and serve it as a regular static website. For most use cases I need, this is more than enough.

I use Pelican to create a static website from .md files. This content resides within the master branch of my repository and consists of theme folder, content (where my blog posts are saved), Makefile and some configuration files. Since I'm serving my website to a custom domain (and not just, I also have a ./content/extra/CNAME entry with for the re-routing to work.

To get the GitHub workflow running, I created a .github/workflows/build-blog.yml file with the following content:

name: Deploy biolitika blog
      - master
    name: Deploy blog
    runs-on: ubuntu-latest
      - name: Install Python
        uses: actions/setup-python@v2
          python-version: 3.7
      - name: Checkout website source
        id: checkout-master
        uses: actions/checkout@v2
      - name: Cache dependencies
        uses: actions/cache@v2
          path: ~/.cache/pip
          key: pelican-4.2.0-${{ hashFiles('requirements.txt') }}
          restore-keys: |
      - name: Install Pelican
        run: |
          pip install -r requirements.txt
      - name: Run Pelican
        id: run-pelican
        run: |
          pelican content --output docs --settings
      - name: Push to GitHub pages
        id: push-to-gh-pages
        run: |
          git config --global "my username"
          git config --global ""

          git add docs/
          git commit --amend --no-edit

          git push origin master:deploy --force

Once you commit this file, a new Workflow should appear in GitHub Actions tab.

The detail important for this case is that once Pelican creates a docs/ folder, new changes are pushed to a new branch called deploy. I have configured this repository so that the static content is served from deploy branch, docs/ folder.

Every time I submit new commit(s), workflow is triggered (on push) and new contents delivered.

1995 style links