77
88permissions :
99 contents : write
10- pages : write
11- id-token : write
1210
1311jobs :
1412 publish :
@@ -25,79 +23,11 @@ jobs:
2523 - name : Generate OpenAPI Doc
2624 run : make upgrade docs
2725
28- - name : Determine doc version
29- id : version
26+ - name : Push to gh-pages branch
3027 run : |
31- set -euo pipefail
32- version=$(yq e '.info.version' ./spec/openapi.yaml)
33- if [[ -z "${version}" || "${version}" == "null" ]]; then
34- echo "Could not read .info.version from ./spec/openapi.yaml" >&2
35- exit 1
36- fi
37- echo "version=${version}" >> "$GITHUB_OUTPUT"
38-
39- - name : Publish docs to gh-pages with history
40- env :
41- DOC_VERSION : ${{ steps.version.outputs.version }}
42- run : |
43- set -euo pipefail
44-
4528 git config --global user.name "github-actions"
4629 git config --global user.email "github-actions@github.com"
47-
48- # Keep the generated docs from main branch checkout
49- rm -rf /tmp/generated-docs
50- mkdir -p /tmp/generated-docs
51- cp -R ./docs/. /tmp/generated-docs/
52-
53- # Check if gh-pages exists, if not create it
54- if git ls-remote --exit-code --heads origin gh-pages > /dev/null 2>&1; then
55- git fetch origin gh-pages:gh-pages
56- git checkout gh-pages
57- else
58- git checkout --orphan gh-pages
59- git rm -rf . || true
60- mkdir -p docs
61- echo "<html><body><p>Initializing gh-pages</p></body></html>" > docs/index.html
62- git add docs/index.html
63- git commit -m "Initialize gh-pages"
64- fi
65-
66- mkdir -p docs/releases/${DOC_VERSION}
67-
68- # Copy the generated HTML and any assets into the versioned folder
69- rm -rf docs/releases/${DOC_VERSION}/*
70- cp -R /tmp/generated-docs/. docs/releases/${DOC_VERSION}/
71-
72- # Render the docs index as a simple link list
73- mkdir -p docs
74- {
75- echo '<!doctype html>'
76- echo '<html>'
77- echo '<head><meta charset="utf-8"><title>CF API Spec Docs</title></head>'
78- echo '<body>'
79- echo '<h1>CF API Spec Docs</h1>'
80- echo '<ul>'
81- for d in $(ls -1 docs/releases 2>/dev/null | sort -Vr); do
82- # Prefer an html entry point if present
83- if ls "docs/releases/${d}"/*.html > /dev/null 2>&1; then
84- first_html=$(ls -1 "docs/releases/${d}"/*.html | head -n 1)
85- rel_path=${first_html#docs/}
86- echo "<li><a href=\"/${rel_path}\">${d}</a></li>"
87- else
88- echo "<li>${d}</li>"
89- fi
90- done
91- echo '</ul>'
92- echo '</body>'
93- echo '</html>'
94- } > docs/index.html
95-
96- git add -A
97- if git diff --cached --quiet; then
98- echo "No changes to publish"
99- exit 0
100- fi
101-
102- git commit -m "Publish docs ${DOC_VERSION}"
103- git push origin gh-pages
30+ git checkout --orphan gh-pages
31+ git add -f ./docs # Force add the docs folder to the gh-pages branch even if it's in .gitignore file
32+ git commit -m "Publish GitHub Pages"
33+ git push origin gh-pages --force
0 commit comments