Skip to content

Add docs build and deploy workflow (#9) #11

Add docs build and deploy workflow (#9)

Add docs build and deploy workflow (#9) #11

name: build_and_deploy
on:
push:
branches-ignore:
- master
# Serialize runs (replaces the CircleCI eddiewebb/queue orb).
concurrency:
group: build_and_deploy
cancel-in-progress: false
env:
# Tag of edgcpp/compiler whose documentation is published at
# https://edgcpp.org/doc/. Bump this to publish a newer release's docs.
COMPILER_DOC_REF: '7.0'
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Build compiler documentation
run: |
# Fetch only doc/ at the tag; a full checkout of the tree is over 3 GB.
git -c advice.detachedHead=false clone --depth 1 \
--branch "$COMPILER_DOC_REF" --filter=blob:none --sparse \
https://github.com/edgcpp/compiler.git /tmp/compiler
git -C /tmp/compiler sparse-checkout set doc
docker run --rm \
-v /tmp/compiler:/work \
-w /work/doc \
edgcpp/sphinx-env:latest \
make dirhtml
mkdir -p doc
cp -a /tmp/compiler/doc/build/dirhtml/. doc/
- uses: ruby/setup-ruby@v1
with:
ruby-version: '4.0'
bundler-cache: true
- run: bundle exec jekyll build
deploy:
needs: test
if: github.ref == 'refs/heads/develop'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v5
- name: Build compiler documentation
run: |
# Fetch only doc/ at the tag; a full checkout of the tree is over 3 GB.
git -c advice.detachedHead=false clone --depth 1 \
--branch "$COMPILER_DOC_REF" --filter=blob:none --sparse \
https://github.com/edgcpp/compiler.git /tmp/compiler
git -C /tmp/compiler sparse-checkout set doc
docker run --rm \
-v /tmp/compiler:/work \
-w /work/doc \
edgcpp/sphinx-env:latest \
make dirhtml
mkdir -p doc
cp -a /tmp/compiler/doc/build/dirhtml/. doc/
- uses: ruby/setup-ruby@v1
with:
ruby-version: '4.0'
bundler-cache: true
- run: bundle exec jekyll build
- name: Deploy to master
run: |
COMMIT_MESSAGE="$(git log -1 --pretty=%B)"
# Unlike the old CircleCI deploy (which preserved .circleci/ so CI
# config stayed on master), .github/ is intentionally NOT kept:
# GITHUB_TOKEN is not allowed to push workflow files, and the
# workflow ignores master anyway.
find . -maxdepth 1 ! -name '_site' ! -name '.git' -exec rm -rf {} \;
mv _site/* .
rm -r _site/
# Serve master as-is. Without this, GitHub Pages runs Jekyll over it
# again, which drops the documentation's doc/_static/ and
# doc/_sources/ directories.
touch .nojekyll
git config --global user.name "GitHub Actions"
git config --global user.email "actions@edgcpp.org"
git add .
git commit --allow-empty -m "$COMMIT_MESSAGE"
git push -f origin HEAD:master