Skip to content

Commit c737032

Browse files
committed
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 4c8f3e1 commit c737032

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

.github/workflows/docs.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ jobs:
4747
west build -t rustdoc -b qemu_cortex_m3 docgen
4848
mkdir rustdocs
4949
mv build/rust/target/thumbv7m-none-eabi/doc rustdocs/nostd
50-
cp docs/top-index.html rustdocs/index.html
5150
5251
- name: Build build documentation
5352
working-directory: zephyr-lang-rust
@@ -56,6 +55,26 @@ jobs:
5655
cargo doc
5756
mv target/doc ../rustdocs/std
5857
58+
- name: Debug SHA values
59+
run: |
60+
echo "GITHUB_SHA: $GITHUB_SHA"
61+
echo "Pull request head: ${{ github.event.pull_request.head.sha }}"
62+
echo "Pull request ref: ${{ github.event.pull_request.head.ref }}"
63+
64+
- name: Determine commit SHA
65+
run: |
66+
if [[ "${{ github.event_name }} == "pull_request" ]]; then
67+
echo "COMMIT_SHA=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
68+
else
69+
echo "COMMIT_SHA=${{ github.sha }}" >> $GITHUB_ENV
70+
fi
71+
72+
- name: Inect commit details into top-level commit.
73+
working-directory: zephyr-lang-rust
74+
env:
75+
COMMIT_SHA: "${{ env.COMMIT_SHA }}"
76+
run: python3 etc/add-hash.py
77+
5978
- name: Upload docs artifact
6079
uses: actions/upload-artifact@v4
6180
with:

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", "HEAD"], 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)