Skip to content

Merge pull request #232 from SamBarker/feat/future-deploy-warning #185

Merge pull request #232 from SamBarker/feat/future-deploy-warning

Merge pull request #232 from SamBarker/feat/future-deploy-warning #185

# Sample workflow for building and deploying a Jekyll site to GitHub Pages
name: Deploy site with Jekyll
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
branch:
description: 'The branch to checkout'
required: true
default: 'main'
type: string
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
# Build job
build:
runs-on: ubuntu-latest
services:
# we spin up a registry to share the image built by build-push-action with the later docker run step
registry:
image: registry:2
ports:
- 5000:5000
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.branch || github.ref_name }}
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
# this is required for the subsequent build to be able to push to the registry on localhost:5000
driver-opts: network=host
- name: Build Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: localhost:5000/kroxy-jekyll:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Load Jekyll configuration overrides
# this is to enable forks to override the url and baseurl
run: echo "${{ vars.JEKYLL_CONFIG_OVERRIDES }}" > _config-overrides.yml
- name: Build with Jekyll
# Outputs to the './_site' directory
run: |
./build.sh
env:
CONTAINER_ENGINE: docker
CONFIG_OVERRIDES: _config-overrides.yml
BUILD_IMAGE_SPEC: localhost:5000/kroxy-jekyll:latest
- name: Warn about future-dated posts
run: |
today=$(date -u +%Y-%m-%d)
future_posts=()
for post in _posts/*.md; do
filename=$(basename "$post")
file_date=$(echo "$filename" | grep -oP '^\d{4}-\d{2}-\d{2}')
# Extract the full front matter date value (may include time and timezone offset)
# and convert to a UTC date so that e.g. "2026-03-05 00:00:00 +1300" is
# correctly treated as 2026-03-04 in UTC (matching Jekyll's behaviour).
front_matter_raw=$(grep -oP '^date:\s*\K.+' "$post" | xargs 2>/dev/null || true)
if [[ -n "$front_matter_raw" ]]; then
post_date=$(date -u -d "$front_matter_raw" +%Y-%m-%d 2>/dev/null || echo "$file_date")
else
post_date="$file_date"
fi
if [[ -n "$post_date" && "$post_date" > "$today" ]]; then
future_posts+=("$filename (publishes $post_date)")
fi
done
if [[ ${#future_posts[@]} -gt 0 ]]; then
echo "## ⚠️ Future-dated posts detected" >> "$GITHUB_STEP_SUMMARY"
echo "The following posts will not appear until the site is rebuilt on or after their publish date:" >> "$GITHUB_STEP_SUMMARY"
for post in "${future_posts[@]}"; do
echo "- $post" >> "$GITHUB_STEP_SUMMARY"
done
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "Re-run this workflow manually on the publish date to make them live." >> "$GITHUB_STEP_SUMMARY"
fi
- name: Upload artifact
# Automatically uploads an artifact from the './_site' directory by default
uses: actions/upload-pages-artifact@v3
# Deployment job
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