Skip to content

Commit 37b8235

Browse files
authored
Merge pull request #267 from samuelkarp/documentation
ci: make documentation sync smarter by filtering changes
2 parents 29a6fca + 9e475d1 commit 37b8235

2 files changed

Lines changed: 104 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: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
3+
# Copyright The containerd Authors.
4+
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
set -e
19+
20+
COMMAND=$1
21+
22+
case "$COMMAND" in
23+
record)
24+
while read -r line; do
25+
hash=$(echo "$line" | grep -oE '[0-9a-f]{40}')
26+
path=$(echo "$line" | awk '{print $2}')
27+
if [ -n "$hash" ] && [ -n "$path" ]; then
28+
echo "$path $hash"
29+
fi
30+
done < <(git submodule status)
31+
;;
32+
check)
33+
STATE_FILE=$2
34+
REPORT_FILE=$3
35+
if [ ! -f "$STATE_FILE" ]; then
36+
echo "Error: State file $STATE_FILE not found" >&2
37+
exit 2
38+
fi
39+
40+
[ -n "$REPORT_FILE" ] && rm -f "$REPORT_FILE"
41+
42+
declare -A old_hashes
43+
while read -r line; do
44+
path=$(echo "$line" | awk '{print $1}')
45+
hash=$(echo "$line" | awk '{print $2}')
46+
old_hashes["$path"]="$hash"
47+
done < "$STATE_FILE"
48+
49+
has_relevant_changes=false
50+
51+
while read -r line; do
52+
new_hash=$(echo "$line" | grep -oE '[0-9a-f]{40}')
53+
path=$(echo "$line" | awk '{print $2}')
54+
old_hash=${old_hashes["$path"]}
55+
56+
if [ -n "$old_hash" ] && [ "$new_hash" != "$old_hash" ]; then
57+
echo "Submodule $path updated: $old_hash -> $new_hash"
58+
diff_output=$(git -C "$path" diff "$old_hash" "$new_hash" --name-only 2>/dev/null | grep -E "^(docs/|README\.md)" || true)
59+
if [ -n "$diff_output" ]; then
60+
echo "--> Relevant changes found in $path"
61+
has_relevant_changes=true
62+
if [ -n "$REPORT_FILE" ]; then
63+
echo "#### $path" >> "$REPORT_FILE"
64+
echo "$diff_output" | sed 's/^/- /' >> "$REPORT_FILE"
65+
echo "" >> "$REPORT_FILE"
66+
fi
67+
fi
68+
fi
69+
done < <(git submodule status)
70+
71+
if [ "$has_relevant_changes" = true ]; then
72+
echo "Result: Relevant changes detected."
73+
exit 0
74+
else
75+
echo "Result: No relevant changes."
76+
exit 1
77+
fi
78+
;;
79+
*)
80+
echo "Usage: $0 {record|check [state_file]}" >&2
81+
exit 3
82+
;;
83+
esac

0 commit comments

Comments
 (0)