Skip to content

Deploy mdBook Site to Pages #25

Deploy mdBook Site to Pages

Deploy mdBook Site to Pages #25

Workflow file for this run

name: Deploy mdBook Site to Pages
on:
push:
branches:
- "*"
workflow_dispatch:
permissions:
contents: read
id-token: write
pages: write
packages: write
concurrency:
group: pages
cancel-in-progress: true
jobs:
build-docker:
runs-on: ubuntu-latest
outputs:
image_built: ${{ steps.check_image.outputs.image_built }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Check if Docker Image Exists
id: check_image
run: |
IMAGE="ghcr.io/${{ github.repository }}:latest"
if docker pull $IMAGE > /dev/null 2>&1; then
echo "Image exists."
echo "image_built=false" >> $GITHUB_OUTPUT
else
echo "Image does not exist."
echo "image_built=true" >> $GITHUB_OUTPUT
fi
- name: Build and Push Docker Image
if: steps.check_image.outputs.image_built == 'true'
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ghcr.io/${{ github.repository }}:latest
load: false
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/mdbook:latest
cache-to: type=inline
deploy-mdbook:
needs: build-docker
runs-on: ubuntu-latest
container:
image: ghcr.io/${{ github.repository }}:latest
options: --user root
steps:
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout Source
uses: actions/checkout@v4
- name: Install Dependencies
run: apk add --no-cache curl
- name: Prepare Assets Directories
run: mkdir -p src/fonts src/assets
- name: Download Additional Assets
run: |
# Devicon Fonts and CSS
curl -sSf -o devicon.min.css https://raw.githubusercontent.com/devicons/devicon/master/devicon.min.css
curl -sSf -o src/fonts/devicon.eot https://raw.githubusercontent.com/devicons/devicon/master/fonts/devicon.eot
curl -sSf -o src/fonts/devicon.svg https://raw.githubusercontent.com/devicons/devicon/master/fonts/devicon.svg
curl -sSf -o src/fonts/devicon.ttf https://raw.githubusercontent.com/devicons/devicon/master/fonts/devicon.ttf
curl -sSf -o src/fonts/devicon.woff https://raw.githubusercontent.com/devicons/devicon/master/fonts/devicon.woff
# WhichLang Assets
curl -sSf -o src/assets/whichlang.css https://raw.githubusercontent.com/phoenixr-codes/mdbook-whichlang/master/src/whichlang.css
curl -sSf -o src/assets/whichlang.js https://raw.githubusercontent.com/phoenixr-codes/mdbook-whichlang/master/dist/whichlang.js
- name: Install Catppuccin Theme
run: mdbook-catppuccin install
- name: Build the mdBook Site
run: mdbook build
- name: Turn off Jekyll
run: touch book/.nojekyll
- name: Upload Artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./book
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
if: ${{ github.ref == 'refs/heads/main' }}