Skip to content

Commit 4e7f490

Browse files
committed
Attempt to fix commit message for bump downstreams
1 parent d893ac8 commit 4e7f490

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

.github/bin/bump_dependency.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ def main() -> int:
140140
default="{repo_url}/compare/{old_version}...{new_version}",
141141
help="Template for diff URLs",
142142
)
143+
parser.add_argument(
144+
"--commit-message-fd",
145+
type=int,
146+
help="File descriptor to write commit message to",
147+
)
143148

144149
args = parser.parse_args()
145150

@@ -154,8 +159,9 @@ def main() -> int:
154159

155160
if current_version == latest_version:
156161
print(f"{args.name}: No update needed (current: {current_version})")
157-
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
158-
f.write("HAS_UPDATES=false\n")
162+
if not args.commit_message_fd:
163+
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
164+
f.write("HAS_UPDATES=false\n")
159165
return 0
160166

161167
print(
@@ -181,11 +187,15 @@ def main() -> int:
181187
args.diff_url_template,
182188
)
183189

184-
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
185-
f.write("COMMIT_MSG<<EOF\n")
186-
f.write(commit_msg)
187-
f.write("\nEOF\n")
188-
f.write("HAS_UPDATES=true\n")
190+
if args.commit_message_fd:
191+
with os.fdopen(args.commit_message_fd, 'w') as f:
192+
f.write(commit_msg)
193+
else:
194+
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
195+
f.write("COMMIT_MSG<<EOF\n")
196+
f.write(commit_msg)
197+
f.write("\nEOF\n")
198+
f.write("HAS_UPDATES=true\n")
189199

190200
return 0
191201

.github/bin/bump_downstreams.sh

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ while IFS=: read -r downstream repo ref; do
3838
ref_pattern="REF: ($ref)"
3939
replacement_pattern="REF: {new_version}"
4040

41-
# Run bump_dependency.py
41+
# Create a temporary file for this downstream's commit message
42+
TEMP_MSG_FILE=$(mktemp)
43+
44+
# Run bump_dependency.py with commit-message-fd redirected to the temp file
4245
python3 .github/bin/bump_dependency.py \
4346
--name "$downstream" \
4447
--repo-url "$repo_url" \
@@ -47,21 +50,22 @@ while IFS=: read -r downstream repo ref; do
4750
--current-version-pattern "$ref_pattern" \
4851
--update-pattern "$replacement_pattern" \
4952
--comment-pattern "$comment_pattern" \
50-
$tag_args
53+
--commit-message-fd 3 \
54+
$tag_args 3<"$TEMP_MSG_FILE"
5155

52-
# Check if this downstream had updates
53-
if [ -f "$GITHUB_OUTPUT" ]; then
54-
if grep -q "HAS_UPDATES=true" "$GITHUB_OUTPUT"; then
55-
HAS_ANY_UPDATES=true
56-
# Extract commit message for this downstream
57-
DOWNSTREAM_MSG=$(sed -n '/COMMIT_MSG<<EOF/,/^EOF$/p' "$GITHUB_OUTPUT" | sed '1d;$d')
58-
if [ -n "$COMBINED_COMMIT_MSG" ]; then
59-
COMBINED_COMMIT_MSG="$COMBINED_COMMIT_MSG"$'\n\n'"$DOWNSTREAM_MSG"
60-
else
61-
COMBINED_COMMIT_MSG="$DOWNSTREAM_MSG"
62-
fi
56+
# Check if this downstream had updates (commit message file has content)
57+
if [ -s "$TEMP_MSG_FILE" ]; then
58+
HAS_ANY_UPDATES=true
59+
DOWNSTREAM_MSG=$(cat "$TEMP_MSG_FILE")
60+
if [ -n "$COMBINED_COMMIT_MSG" ]; then
61+
COMBINED_COMMIT_MSG="$COMBINED_COMMIT_MSG"$'\n\n'"$DOWNSTREAM_MSG"
62+
else
63+
COMBINED_COMMIT_MSG="$DOWNSTREAM_MSG"
6364
fi
6465
fi
66+
67+
# Clean up temp file
68+
rm -f "$TEMP_MSG_FILE"
6569
done <<< "$DOWNSTREAMS"
6670

6771
# Set final outputs

0 commit comments

Comments
 (0)