Skip to content

Commit 8ce1814

Browse files
ci: add pages site deployment jobs
1 parent cb21cce commit 8ce1814

1 file changed

Lines changed: 86 additions & 0 deletions

File tree

.github/workflows/doc_update.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ jobs:
1818
build_website:
1919
name: Build website
2020
runs-on: "ubuntu-24.04"
21+
outputs:
22+
diff_status: ${{ steps.diff-generated.outputs.diff_status }}
23+
# Note upload-pages-artifact output name is artifact_id (with underscore).
24+
pages_artifact_id: ${{ steps.upload-pages-package.outputs.artifact_id }}
25+
# Note upload-artifact output name is artifact-id (with dash).
26+
branch_content_artifact_id: ${{ steps.upload-full-archive.outputs.artifact-id }}
27+
git_tree_hash: ${{ steps.diff-generated.outputs.git_tree_hash }}
2128
steps:
2229
- uses: actions/checkout@v6
2330
- name: Setup Pages
@@ -67,13 +74,92 @@ jobs:
6774
cd "$WORKDIR"/work
6875
git diff --cached --stat
6976
git diff --cached
77+
TREE_SHA1=$(git write-tree)
78+
echo "git_tree_hash=$TREE_SHA1" >> "$GITHUB_OUTPUT"
7079
if git diff-index --quiet HEAD; then
7180
echo "diff_status=clean" >> "$GITHUB_OUTPUT"
7281
else
7382
echo "diff_status=changed" >> "$GITHUB_OUTPUT"
7483
fi
84+
git archive --format=tar -o ../gh-pages-content.tar "$TREE_SHA1"
85+
- name: Upload full archive
86+
id: upload-full-archive
87+
if: ${{ steps.diff-generated.outputs.diff_status == 'changed' }}
88+
uses: actions/upload-artifact@v4
89+
with:
90+
path: ${{ steps.make-output-dir.outputs.doc_output_dir }}/gh-pages-content.tar
91+
name: full-gh-pages-content
92+
if-no-files-found: "error"
93+
retention-days: 4
94+
include-hidden-files: true
7595
- name: Upload Pages package
96+
id: upload-pages-package
7697
if: ${{ steps.diff-generated.outputs.diff_status == 'changed' }}
7798
uses: actions/upload-pages-artifact@v4
7899
with:
79100
path: ${{ steps.make-output-dir.outputs.doc_output_dir }}/work/
101+
102+
push_pages_branch:
103+
name: Update gh-pages branch
104+
needs: build_website
105+
if: ${{ needs.build_website.outputs.diff_status == 'changed' }}
106+
permissions:
107+
contents: write
108+
environment:
109+
name: pages-via-branch-push
110+
runs-on: "ubuntu-24.04"
111+
steps:
112+
- uses: actions/checkout@v6
113+
with:
114+
ref: gh-pages
115+
path: repo
116+
- uses: actions/download-artifact@v7
117+
with:
118+
artifact-ids: ${{ needs.build_website.outputs.branch_content_artifact_id }}
119+
path: built
120+
- name: Extract and push
121+
env:
122+
TREE_SHA1: ${{ needs.build_website.outputs.git_tree_hash }}
123+
GIT_AUTHOR_NAME: "github-actions[bot]"
124+
GIT_AUTHOR_EMAIL: "41898282+github-actions[bot]@users.noreply.github.com"
125+
GIT_COMMITTER_NAME: "github-actions[bot]"
126+
GIT_COMMITTER_EMAIL: "41898282+github-actions[bot]@users.noreply.github.com"
127+
run: |
128+
[[ ! -z "$TREE_SHA1" ]] || {
129+
>&2 echo "did not get valid sha1 hash for expected git tree from builder job"
130+
exit 1
131+
}
132+
cd repo
133+
rm --one-file-system -r -- $(git ls-tree --name-only HEAD)
134+
echo "Cleared working dir. Content is now:"
135+
ls -R "$GITHUB_WORKSPACE"
136+
echo "Unpacking artifact from builder job."
137+
tar -xf ../built/gh-pages-content.tar
138+
git add .
139+
git diff --cached --stat
140+
git diff --cached
141+
UNPACKED_TREE_SHA1=$(git write-tree)
142+
echo "Unpacked tree SHA1: $UNPACKED_TREE_SHA1"
143+
[[ "$TREE_SHA1" = "$UNPACKED_TREE_SHA1" ]] || {
144+
>&2 echo "builder-produced tree differs from extracted tree"
145+
exit 1
146+
}
147+
git commit -m 'Update docs.'
148+
git log -n1
149+
git push
150+
151+
publish_pages:
152+
name: Direct publish pages
153+
needs: build_website
154+
if: ${{ false && needs.build_website.outputs.diff_status == 'changed' }}
155+
permissions:
156+
pages: write
157+
id-token: write
158+
environment:
159+
name: github-pages
160+
url: ${{ steps.deployment.outputs.page_url }}
161+
runs-on: "ubuntu-24.04"
162+
steps:
163+
- name: Deploy to GitHub Pages
164+
id: deployment
165+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)