Skip to content

chore: more fixes to gh action #33

chore: more fixes to gh action

chore: more fixes to gh action #33

Workflow file for this run

name: Docs to GitHub Pages
on:
push:
branches: [main]
workflow_dispatch:
jobs:
# --------------------------------------------------------- #
# 1. Pull extra docs from external repo
# --------------------------------------------------------- #
pull-docs:
if: github.actor != 'github-actions[bot]'
runs-on: ubuntu-latest
permissions: { contents: read }
steps:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- name: Make fetch_docs.sh executable
run: chmod +x ./src/scripts/fetch_docs.sh
- name: Fetch all docs
run: ./src/scripts/fetch_docs.sh
- name: Upload docs artifact
uses: actions/upload-artifact@v4
with:
name: docs-raw
path: ./docs/
# --------------------------------------------------------- #
# 2. Commit those docs back into the repo (if changed)
# --------------------------------------------------------- #
commit-docs:
needs: pull-docs
if: github.actor != 'github-actions[bot]'
runs-on: ubuntu-latest
permissions: { contents: write }
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0
- name: Download docs artifact
uses: actions/download-artifact@v4
with:
name: docs-raw
path: ./docs/dev/
- name: Commit & push if changed
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add docs/
git commit -m "Update pulled docs" || echo "No changes"
# ---- Auth for push ----
git remote set-url origin \
https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
git push origin HEAD:main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# --------------------------------------------------------- #
# 3. Build site + Tina, publish to gh-pages
# --------------------------------------------------------- #
deploy:
needs: commit-docs
runs-on: ubuntu-latest
permissions:
contents: read # checkout needs this
pages: write # let the action publish
id-token: write # ⭐ required by deploy-pages
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v4
- name: Install deps
run: npm ci
# ----- Build Tina admin (./admin) -----
- name: Build TinaCMS admin
env:
TINA_PUBLIC_CLIENT_ID: ${{ secrets.TINA_PUBLIC_CLIENT_ID }}
TINA_TOKEN: ${{ secrets.TINA_TOKEN }}
ENABLE_TINA_ADMIN: true
run: npx tinacms build
# ----- Build Docusaurus site (./build) -----
- name: Build docs site
env:
ENABLE_TINA_ADMIN: true
TINA_PUBLIC_CLIENT_ID: ${{ secrets.TINA_PUBLIC_CLIENT_ID }}
TINA_TOKEN: ${{ secrets.TINA_TOKEN }}
DOCS_BASEURL: ${{ secrets.DOCS_BASEURL }} # e.g. /Docusaurus-docs/
run: npm run build
# ----- Copy Tina into <baseUrl>/admin -----
- name: Relocate Tina admin inside baseUrl
run: |
set -euo pipefail
BASE="${DOCS_BASEURL#/}" # strip leading /
BASE="${BASE%/}" # strip trailing /
SRC="./public/admin" # <<— correct location from tinacms build
# If you still move it to static/cms-admin elsewhere, use that path instead
if [[ ! -d "$SRC" ]]; then
echo "Tina admin folder not found at $SRC"; exit 1;
fi
if [[ -z "$BASE" ]]; then
DEST="./build/admin"
else
DEST="./build/${BASE}/admin"
fi
echo "Copying $SRC → $DEST"
mkdir -p "$DEST"
cp -a "$SRC"/. "$DEST"/
ls -R "$DEST" | head
env:
DOCS_BASEURL: ${{ secrets.DOCS_BASEURL }}
# --- Upload static site as artifact ---
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./build # folder that holds index.html
# --- Deploy to GitHub Pages (official) ---
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4