Skip to content

Commit 3318d08

Browse files
committed
ci: make documentation sync smarter by filtering changes
Optimizes the sync workflow to prevent creating empty Pull Requests by inspecting submodule diff history for documentation shifts (e.g., edits inside docs/ or modifications addressing README.md). Extends the automation to generate dynamic Pull Request descriptions listing the exact relevant files that triggered the synchronizer. Assisted-by: gemini-3.1-pro-high Signed-off-by: Samuel Karp <samuelkarp@google.com>
1 parent ad351f5 commit 3318d08

2 files changed

Lines changed: 88 additions & 2 deletions

File tree

.github/workflows/sync-documentation.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,37 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v4
14+
- name: Record submodule state
15+
run: ./tools/check-submodule-docs.sh record > /tmp/old_submodules.txt
1416
- name: Update documentation
1517
run: make refresh-docs
18+
- name: Check for documentation changes
19+
id: verify_changes
20+
run: |
21+
if ./tools/check-submodule-docs.sh check /tmp/old_submodules.txt /tmp/pr_body.txt; then
22+
echo "has_changes=true" >> $GITHUB_OUTPUT
23+
{
24+
echo 'pr_body<<EOF'
25+
echo "This is an auto-generated PR to sync updates in the main containerd project's documentation."
26+
echo ''
27+
echo '### Relevant changes detected:'
28+
cat /tmp/pr_body.txt
29+
echo 'EOF'
30+
} >> "$GITHUB_OUTPUT"
31+
else
32+
echo "has_changes=false" >> $GITHUB_OUTPUT
33+
fi
1634
- name: Create Pull Request
35+
if: steps.verify_changes.outputs.has_changes == 'true'
1736
uses: peter-evans/create-pull-request@v7
1837
with:
1938
token: ${{ secrets.GITHUB_TOKEN }}
2039
commit-message: |
21-
keep releases.md in sync with containerd/containerd
40+
keep documentation in sync with containerd/containerd
2241
2342
Signed-off-by: Samuel Karp <samuelkarp+automated@google.com>
2443
committer: Samuel Karp <samuelkarp@google.com>
2544
author: Samuel Karp <samuelkarp+automated@google.com>
2645
title: Automated documentation sync update
27-
body: This is an auto-generated PR to sync updates in the main containerd project's documentation.
46+
body: ${{ steps.verify_changes.outputs.pr_body }}
2847
branch: docs-updates

tools/check-submodule-docs.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
set -e
3+
4+
COMMAND=$1
5+
6+
case "$COMMAND" in
7+
record)
8+
while read -r line; do
9+
hash=$(echo "$line" | grep -oE '[0-9a-f]{40}')
10+
path=$(echo "$line" | awk '{print $2}')
11+
if [ -n "$hash" ] && [ -n "$path" ]; then
12+
echo "$path $hash"
13+
fi
14+
done < <(git submodule status)
15+
;;
16+
check)
17+
STATE_FILE=$2
18+
REPORT_FILE=$3
19+
if [ ! -f "$STATE_FILE" ]; then
20+
echo "Error: State file $STATE_FILE not found" >&2
21+
exit 2
22+
fi
23+
24+
[ -n "$REPORT_FILE" ] && rm -f "$REPORT_FILE"
25+
26+
declare -A old_hashes
27+
while read -r line; do
28+
path=$(echo "$line" | awk '{print $1}')
29+
hash=$(echo "$line" | awk '{print $2}')
30+
old_hashes["$path"]="$hash"
31+
done < "$STATE_FILE"
32+
33+
has_relevant_changes=false
34+
35+
while read -r line; do
36+
new_hash=$(echo "$line" | grep -oE '[0-9a-f]{40}')
37+
path=$(echo "$line" | awk '{print $2}')
38+
old_hash=${old_hashes["$path"]}
39+
40+
if [ -n "$old_hash" ] && [ "$new_hash" != "$old_hash" ]; then
41+
echo "Submodule $path updated: $old_hash -> $new_hash"
42+
diff_output=$(git -C "$path" diff "$old_hash" "$new_hash" --name-only 2>/dev/null | grep -E "^(docs/|README\.md)" || true)
43+
if [ -n "$diff_output" ]; then
44+
echo "--> Relevant changes found in $path"
45+
has_relevant_changes=true
46+
if [ -n "$REPORT_FILE" ]; then
47+
echo "#### $path" >> "$REPORT_FILE"
48+
echo "$diff_output" | sed 's/^/- /' >> "$REPORT_FILE"
49+
echo "" >> "$REPORT_FILE"
50+
fi
51+
fi
52+
fi
53+
done < <(git submodule status)
54+
55+
if [ "$has_relevant_changes" = true ]; then
56+
echo "Result: Relevant changes detected."
57+
exit 0
58+
else
59+
echo "Result: No relevant changes."
60+
exit 1
61+
fi
62+
;;
63+
*)
64+
echo "Usage: $0 {record|check [state_file]}" >&2
65+
exit 3
66+
;;
67+
esac

0 commit comments

Comments
 (0)