Refine CD for gh-pages #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CD for gh-pages | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
container: debian:bookworm | |
runs-on: ubuntu-22.04 | |
permissions: | |
contents: write | |
pages: write | |
steps: | |
- name: Install dependencies | |
run: apt-get update && apt-get install -y wget git | |
- name: Fix broken dependencies | |
run: | | |
apt-get install -y --fix-missing | |
apt-get install -f -y | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 1 | |
- name: Download release of TeXmacs | |
run: | | |
wget http://www.texmacs.org/Download/ftp/tmftp/Linux/Debian_12/TeXmacs-2.1.4.amd64.deb -O /tmp/texmacs.deb | |
DEBIAN_FRONTEND=noninteractive apt install -y /tmp/texmacs.deb | |
- name: Run TeXmacs script with headless option | |
run: | | |
texmacs_bin=$(which texmacs) | |
$texmacs_bin -headless -x '(begin (load "notes-tools.scm") (notes-update) (quit))' | |
- name: Deploy to gh-pages | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
# set variable | |
TARGET_BRANCH="gh-pages" | |
BUILD_DIR="docs" | |
ROOT_INDEX_FILE="index.html" | |
REPO_URL="https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" | |
# set Git config | |
git config --global user.name "${{ github.actor }}" | |
git config --global user.email "${{ github.actor }}@users.noreply.github.com" | |
# init gh-pages branch | |
git clone --branch ${TARGET_BRANCH} --depth 1 ${REPO_URL} gh-pages || \ | |
(git init gh-pages && cd gh-pages && git checkout --orphan ${TARGET_BRANCH}) | |
cd gh-pages | |
# remove old file | |
rm -rf * | |
# copy 'docs' | |
cp -r ../${BUILD_DIR}/* . | |
# copy 'index.html' | |
cp ../${ROOT_INDEX_FILE} . | |
# commit & push | |
git add --all | |
git commit -m "Deploy to ${TARGET_BRANCH} branch" | |
git push --force ${REPO_URL} ${TARGET_BRANCH} |