GitHub Actions Workflow: Build Pages
This document explains the structure and functionality of a GitHub Actions workflow designed to build static pages using Jekyll. The workflow is triggered by specific events and includes steps to install dependencies, process Markdown files, build the site, and upload artifacts.
Workflow Triggers
The workflow is triggered under the following conditions:
- Push Events:
- Activates when changes are pushed to the
mainbranch. - Only triggers if changes are made to
.markdownfiles or within thepages/**directory.
- Activates when changes are pushed to the
- Manual Trigger (
workflow_dispatch):- Allows manual execution of the workflow via the GitHub UI.
Jobs in the Workflow
1. Build Pages Job (build_pages)
Conditions:
- Runs only if the trigger is from the
mainbranch (github.ref == 'refs/heads/main').
Environment:
- Runs on:
ubuntu-latest.
Steps:
- Checkout Repository:
- Clones the repository into the workspace using
actions/checkout@v4.
- Clones the repository into the workspace using
- Setup Pages:
- Configures the environment for GitHub Pages using
actions/configure-pages@v5.
- Configures the environment for GitHub Pages using
- Install Ruby and Bundler:
- Sets up Ruby version
3.0and installs Bundler with caching enabled usingruby/setup-ruby@v1.
- Sets up Ruby version
- Install Dependencies:
- Navigates to the
pagesdirectory and installs dependencies usingbundle install.
- Navigates to the
- Copy Markdown Files:
- Copies
.markdownfiles from theextraandownSoftwaredirectories to thepagesdirectory while preserving their folder structure. - Creates necessary subdirectories in
pagesto maintain the relative paths of the copied files.
- Copies
- Build with Jekyll:
- Builds the Jekyll site using
actions/jekyll-build-pages@v1. - Specifies the source directory (
./pages) and the destination directory (./output_dir).
- Builds the Jekyll site using
- Upload Artifact:
- Uploads the built site (located in
./output_dir) as a GitHub artifact namedpages_artifact-$usingactions/upload-artifact@v4.
- Uploads the built site (located in
- Job ID and Package Hash:
- Logs the workflow run ID and artifact hash (
pages_artifact-$) for reference.
- Logs the workflow run ID and artifact hash (
Key Features
- Selective Building:
- Detects changes in
.markdownfiles and thepagesdirectory to ensure only relevant updates trigger the workflow.
- Detects changes in
- Markdown File Processing:
- Automatically copies
.markdownfiles fromextraandownSoftwaredirectories into thepagesdirectory, preserving their folder structure for organization.
- Automatically copies
- Jekyll Integration:
- Uses Jekyll to generate static HTML pages from Markdown content, making it suitable for documentation or blog sites.
- Artifact Management:
- Uploads the generated site as an artifact for reuse in downstream workflows, such as deployment to GitHub Pages.
- Efficient Dependency Management:
- Leverages Bundler caching to speed up dependency installation during subsequent runs.
Example Use Case
This workflow is ideal for automating the generation of a Jekyll-based static site hosted on GitHub Pages. By copying Markdown files from multiple directories and building them into a unified site, it ensures that your documentation or content remains organized and up-to-date. This setup is particularly useful for projects that manage content across different sections (e.g., extra and ownSoftware) but want to present it as a cohesive site.