Skip to content

Build and Deploy to Cloudflare Pages #507

Build and Deploy to Cloudflare Pages

Build and Deploy to Cloudflare Pages #507

---
name: Build and Deploy to Cloudflare Pages
on:
workflow_dispatch:
push:
branches:
- main
paths-ignore:
- ".github/**"
- "_drafts/**"
- ".gitattributes"
- ".gitignore"
- "Gemfile"
- "LICENSE"
- "README.md"
schedule:
- cron: "0 0 * * *"
# 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: "cf-pages"
cancel-in-progress: false
jobs:
# Build job
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Theme
uses: actions/checkout@v6
with:
repository: groveld/jekyll-theme
ref: main
- name: Checkout Content
uses: actions/checkout@v6
with:
ref: main
path: .content
- name: Merge Content with Theme
run: |
rm -rf "${GITHUB_WORKSPACE}/_posts/"
rsync -av --exclude ".git*" --exclude "LICENSE" --exclude "README.md" "${GITHUB_WORKSPACE}/.content/" "${GITHUB_WORKSPACE}/"
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3" # Not needed with a .ruby-version file
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
cache-version: 0 # Increment this number if you need to re-download cached gems
- name: Setup Node
uses: actions/setup-node@v6
with:
node-version: "20"
- name: Build Jekyll
run: bundle exec jekyll build
env:
JEKYLL_ENV: production
- name: Install PurgeCSS and remove unused CSS
run: |
npm i -g purgecss
purgecss --css "${GITHUB_WORKSPACE}/_site/**/*.css" --content "${GITHUB_WORKSPACE}/_site/**/*.html"
- name: Validate Jekyll
run: bundle exec htmlproofer "${GITHUB_WORKSPACE}/_site/" --checks Images,Scripts,Favicon --disable-external
- name: Upload artifact
uses: actions/upload-artifact@v7
with:
name: cloudflare-pages
path: _site
retention-days: "1"
# Deployment job
deploy:
needs: build
permissions:
contents: read
deployments: write
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v8
with:
name: cloudflare-pages
- name: Deploy to Cloudflare Pages
uses: cloudflare/wrangler-action@v4
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy . --project-name=groveld