Skip to content

Commit dd4c47d

Browse files
committed
github: workflow: docs: Push 'main' docs to gh-pages
Distinguish between pull requests, and pushes to 'main'. The pull request docs are published on s3, with a mechanism to retire those after a time. Pushes to 'main' (happens when code merges) replace the documentation on gh-pages. These are available for anyone wanting to see "the latest docs". Signed-off-by: David Brown <[email protected]> docs: Add latest commit to top of index Insert `git show --stat HEAD` into the template for the top-level docs, to make it easy to see what a build was generated for. Signed-off-by: David Brown <[email protected]>
1 parent 49c6712 commit dd4c47d

File tree

3 files changed

+59
-11
lines changed

3 files changed

+59
-11
lines changed

.github/workflows/docs.yml

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
uses: actions/checkout@v4
2222
with:
2323
path: zephyr-lang-rust
24+
fetch-depth: 0 # Ensure full history is available
2425

2526
- name: Set up Python
2627
uses: actions/setup-python@v5
@@ -47,7 +48,6 @@ jobs:
4748
west build -t rustdoc -b qemu_cortex_m3 docgen
4849
mkdir rustdocs
4950
mv build/rust/target/thumbv7m-none-eabi/doc rustdocs/nostd
50-
cp docs/top-index.html rustdocs/index.html
5151
5252
- name: Build build documentation
5353
working-directory: zephyr-lang-rust
@@ -56,12 +56,25 @@ jobs:
5656
cargo doc
5757
mv target/doc ../rustdocs/std
5858
59+
- name: Inject commit details into top-level commit.
60+
working-directory: zephyr-lang-rust
61+
env:
62+
COMMIT_SHA: "${{ github.event.pull_request.head.sha || github.sha }}"
63+
run: python3 etc/add-hash.py
64+
5965
- name: Upload docs artifact
66+
if: github.event_name == 'pull_request'
6067
uses: actions/upload-artifact@v4
6168
with:
6269
name: rustdocs
6370
path: zephyr-lang-rust/rustdocs
6471

72+
- name: Upload pages artifact
73+
if: github.event_name == 'push'
74+
uses: actions/upload-pages-artifact@v3
75+
with:
76+
path: zephyr-lang-rust/rustdocs
77+
6578
doc-publish:
6679
name: Publish Rust Documentation
6780
needs: generate-docs
@@ -71,21 +84,11 @@ jobs:
7184
github.repository == 'zephyrproject-rtos/zephyr-lang-rust'
7285
7386
steps:
74-
# - name: Show github context
75-
# env:
76-
# GITHUB_CONTEXT: ${{ toJson(github) }}
77-
# run: |
78-
# echo "$GITHUB_CONTEXT" | jq .
79-
8087
- name: Download documentation artifact
8188
uses: actions/download-artifact@v4
8289
with:
8390
name: rustdocs
8491

85-
# - name: Show our tree
86-
# run: |
87-
# find . -ls
88-
8992
- name: Publish to S3
9093
env:
9194
AWS_ACCESS_KEY_ID: ${{ vars.AWS_BUILDS_ZEPHYR_LANG_RUST_PR_ACCESS_KEY_ID }}
@@ -94,3 +97,20 @@ jobs:
9497
run: |
9598
PR_NUM=${{ github.event.number || 'not-a-pr' }}
9699
aws s3 sync --only-show-errors . s3://builds.zephyrproject.org/zephyr-lang-rust/pr/$PR_NUM/
100+
101+
gh-publish:
102+
name: Publish main to gh-pages
103+
needs: generate-docs
104+
permissions:
105+
pages: write
106+
id-token: write
107+
108+
runs-on: ubuntu-24.04
109+
if: |
110+
github.event_name == 'push' &&
111+
github.repository == 'zephyrproject-rtos/zephyr-lang-rust'
112+
113+
steps:
114+
- name: Deploy to GitHub Pages
115+
id: deployment
116+
uses: actions/deploy-pages@v4

docs/top-index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@ <h1>Documentation Index</h1>
1010
<li><a href="nostd/zephyr/index.html">zephyr crate Documentation</a></li>
1111
<li><a href="std/zephyr_build/index.html">zephyr_build support Documentation</a></li>
1212
</ul>
13+
<pre>
14+
{{COMMIT}}
15+
</pre>
1316
</body>
1417
</html>

etc/add-hash.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#! /usr/bin/env python
2+
3+
import os
4+
import subprocess
5+
6+
input = "./docs/top-index.html"
7+
output = "rustdocs/index.html"
8+
9+
# Get the commit from github (otherwise, we are likely to just see a merge commit. Default to HEAD
10+
# if not provided.)
11+
commit_sha = os.getenv("COMMIT_SHA", "HEAD")
12+
13+
try:
14+
commit_info = subprocess.check_output(["git", "show", "--stat", commit_sha], text=True)
15+
except subprocess.CalledProcessError as e:
16+
print(f"Error getting commit info: {e}")
17+
commit_info = "Error retrieving commit details.\n"
18+
19+
with open(output, "w") as outfile:
20+
with open(input, "r") as file:
21+
for line in file:
22+
if "{{COMMIT}}" in line:
23+
outfile.write(commit_info)
24+
else:
25+
outfile.write(line)

0 commit comments

Comments
 (0)