Skip to content

Commit 71af149

Browse files
committed
fix: yet another actions-try for ghpages w/tina
1 parent e1d943c commit 71af149

File tree

1 file changed

+64
-61
lines changed

1 file changed

+64
-61
lines changed

.github/workflows/deploypages.yml

Lines changed: 64 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,114 @@
1-
name: Docs to Github Pages
1+
name: Docs to GitHub Pages
22

33
on:
44
push:
55
branches: [main]
66
workflow_dispatch:
77

88
jobs:
9+
# --------------------------------------------------------- #
10+
# 1. Pull extra docs from external repo
11+
# --------------------------------------------------------- #
912
pull-docs:
10-
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.event.pusher.name != 'github-actions[bot]' && (!startsWith(github.event.head_commit.message, 'Merge pull request') || !contains(github.event.head_commit.message, 'release-please--branches--main'))
13+
if: github.actor != 'github-actions[bot]'
1114
runs-on: ubuntu-latest
12-
permissions:
13-
contents: read
15+
permissions: { contents: read }
1416
steps:
1517
- uses: actions/checkout@v4
1618
with:
1719
submodules: true
1820
fetch-depth: 0
1921

20-
- name: Make fetch_docs.sh Executable
21-
run: chmod +x ${{ github.workspace }}/src/scripts/fetch_docs.sh
22+
- name: Make fetch_docs.sh executable
23+
run: chmod +x ./src/scripts/fetch_docs.sh
2224

23-
- name: Fetch All Docs
24-
run: ${{ github.workspace }}/src/scripts/fetch_docs.sh
25+
- name: Fetch all docs
26+
run: ./src/scripts/fetch_docs.sh
2527

26-
- name: Debug
27-
run: |
28-
ls -R ${{ github.workspace }}/docs
29-
ls
30-
31-
- name: Upload Docs Artifact
28+
- name: Upload docs artifact
3229
uses: actions/upload-artifact@v4
3330
with:
3431
name: docs-raw
35-
path: ${{ github.workspace }}/docs/
32+
path: ./docs/
3633

34+
# --------------------------------------------------------- #
35+
# 2. Commit those docs back into the repo (if changed)
36+
# --------------------------------------------------------- #
3737
commit-docs:
38-
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.event.pusher.name != 'github-actions[bot]' && (!startsWith(github.event.head_commit.message, 'Merge pull request') || !contains(github.event.head_commit.message, 'release-please--branches--main'))
39-
runs-on: ubuntu-latest
40-
permissions:
41-
contents: write
4238
needs: pull-docs
39+
if: github.actor != 'github-actions[bot]'
40+
runs-on: ubuntu-latest
41+
permissions: { contents: write }
4342
steps:
4443
- uses: actions/checkout@v4
4544
with:
4645
persist-credentials: false
4746
fetch-depth: 0
4847

49-
- name: Configure Git
50-
run: |
51-
git config --global user.name "github-actions[bot]"
52-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
53-
54-
- name: Download Docs Artifact
48+
- name: Download docs artifact
5549
uses: actions/download-artifact@v4
5650
with:
5751
name: docs-raw
58-
path: ${{ github.workspace }}/docs/dev/
59-
60-
- name: Check for Changes
61-
run: |
62-
git status
63-
ls -R ${{ github.workspace }}/docs/dev
52+
path: ./docs/dev/
6453

65-
- name: Add & Commit Changes
54+
- name: Commit & push if changed
6655
run: |
67-
git add .
68-
git commit -m "Update Docusaurus docs" || echo "No changes to commit"
69-
70-
- name: Configure Git Remote
71-
run: git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
72-
73-
- name: Pull Latest Main
74-
run: git pull --rebase origin main
75-
76-
- name: Push Changes
77-
run: git push origin main
56+
git config user.name "github-actions[bot]"
57+
git config user.email "github-actions[bot]@users.noreply.github.com"
58+
git add docs/
59+
git commit -m "Update pulled docs" || echo "No changes"
60+
git push
7861
env:
7962
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8063

64+
# --------------------------------------------------------- #
65+
# 3. Build site + Tina, publish to gh-pages
66+
# --------------------------------------------------------- #
8167
deploy:
82-
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.event.pusher.name != 'github-actions[bot]' && (!startsWith(github.event.head_commit.message, 'Merge pull request') || !contains(github.event.head_commit.message, 'release-please--branches--main'))
83-
runs-on: ubuntu-latest
8468
needs: commit-docs
69+
runs-on: ubuntu-latest
8570
steps:
8671
- uses: actions/checkout@v4
87-
with:
88-
persist-credentials: false
89-
fetch-depth: 0
9072

91-
- name: Download Docs Artifact
92-
uses: actions/download-artifact@v4
93-
with:
94-
name: docs-raw
95-
path: ${{ github.workspace }}/docs/
96-
97-
- name: Install Dependencies
98-
run: npm install
73+
- name: Install deps
74+
run: npm ci
9975

100-
- name: Build TinaCMS + Docusaurus Site
76+
# ----- Build Tina admin (./admin) -----
77+
- name: Build TinaCMS admin
10178
env:
10279
TINA_PUBLIC_CLIENT_ID: ${{ secrets.TINA_PUBLIC_CLIENT_ID }}
103-
TINA_TOKEN: ${{ secrets.TINA_TOKEN }}
104-
DOCS_BASEURL: ${{ secrets.DOCS_BASEURL }}
80+
TINA_TOKEN: ${{ secrets.TINA_TOKEN }}
81+
run: npx tinacms build
82+
83+
# ----- Build Docusaurus site (./build) -----
84+
- name: Build docs site
85+
env:
86+
DOCS_BASEURL: ${{ secrets.DOCS_BASEURL }} # e.g. /Docusaurus-docs/
10587
run: npm run build
10688

89+
# ----- Copy Tina into <baseUrl>/admin -----
90+
- name: Relocate Tina admin inside baseUrl
91+
run: |
92+
set -euo pipefail
93+
BASE="${DOCS_BASEURL#/}" # strip leading /
94+
BASE="${BASE%/}" # strip trailing /
95+
if [[ -z "$BASE" ]]; then
96+
echo "Base URL is '/', nothing to move."
97+
exit 0
98+
fi
99+
SRC="./admin"
100+
DEST="./build/${BASE}/admin"
101+
echo "Copying $SRC → $DEST"
102+
mkdir -p "$DEST"
103+
cp -a "$SRC"/. "$DEST"/
104+
ls -R "$DEST" | head
105+
env:
106+
DOCS_BASEURL: ${{ secrets.DOCS_BASEURL }}
107+
108+
# ----- Publish to gh-pages -----
107109
- name: Deploy to GitHub Pages
108110
uses: peaceiris/actions-gh-pages@v3
109111
with:
110-
github_token: ${{ secrets.GITHUB_TOKEN }}
111-
publish_dir: ./build
112+
github_token: ${{ secrets.GITHUB_TOKEN }}
113+
publish_branch: gh-pages
114+
publish_dir: ./build

0 commit comments

Comments
 (0)