1
- name : Docs to Github Pages
1
+ name : Docs to GitHub Pages
2
2
3
3
on :
4
4
push :
5
5
branches : [main]
6
6
workflow_dispatch :
7
7
8
8
jobs :
9
+ # --------------------------------------------------------- #
10
+ # 1. Pull extra docs from external repo
11
+ # --------------------------------------------------------- #
9
12
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]'
11
14
runs-on : ubuntu-latest
12
- permissions :
13
- contents : read
15
+ permissions : { contents: read }
14
16
steps :
15
17
- uses : actions/checkout@v4
16
18
with :
17
19
submodules : true
18
20
fetch-depth : 0
19
21
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
22
24
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
25
27
26
- - name : Debug
27
- run : |
28
- ls -R ${{ github.workspace }}/docs
29
- ls
30
-
31
- - name : Upload Docs Artifact
28
+ - name : Upload docs artifact
32
29
uses : actions/upload-artifact@v4
33
30
with :
34
31
name : docs-raw
35
- path : ${{ github.workspace }} /docs/
32
+ path : . /docs/
36
33
34
+ # --------------------------------------------------------- #
35
+ # 2. Commit those docs back into the repo (if changed)
36
+ # --------------------------------------------------------- #
37
37
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
42
38
needs : pull-docs
39
+ if : github.actor != 'github-actions[bot]'
40
+ runs-on : ubuntu-latest
41
+ permissions : { contents: write }
43
42
steps :
44
43
- uses : actions/checkout@v4
45
44
with :
46
45
persist-credentials : false
47
46
fetch-depth : 0
48
47
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
55
49
uses : actions/download-artifact@v4
56
50
with :
57
51
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/
64
53
65
- - name : Add & Commit Changes
54
+ - name : Commit & push if changed
66
55
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
78
61
env :
79
62
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
80
63
64
+ # --------------------------------------------------------- #
65
+ # 3. Build site + Tina, publish to gh-pages
66
+ # --------------------------------------------------------- #
81
67
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
84
68
needs : commit-docs
69
+ runs-on : ubuntu-latest
85
70
steps :
86
71
- uses : actions/checkout@v4
87
- with :
88
- persist-credentials : false
89
- fetch-depth : 0
90
72
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
99
75
100
- - name : Build TinaCMS + Docusaurus Site
76
+ # ----- Build Tina admin (./admin) -----
77
+ - name : Build TinaCMS admin
101
78
env :
102
79
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/
105
87
run : npm run build
106
88
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 -----
107
109
- name : Deploy to GitHub Pages
108
110
uses : peaceiris/actions-gh-pages@v3
109
111
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