Skip to content

Commit 57245d1

Browse files
authored
Merge pull request #23785 from vvoland/moby-releasenotes
hack/moby-sync-release: Help create draft release if not found
2 parents 3fc1936 + 1f715ea commit 57245d1

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

hack/moby-sync-release.sh

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,28 @@ github_notes=$(mktemp -t old)
2020
# Get the release notes from the docs.
2121
grep -A 10000 "## ${version}" "content/manuals/engine/release-notes/${major_version}.md" | \
2222
grep -m 2 -A 0 -B 10000 '^## ' | \
23-
sed '$d' | `# remove the last line` \
23+
sed '$d' | \
2424
sed '/{{< release-date /{N;d;}' \
25-
> "$docs_notes"
25+
> "$docs_notes" || { echo "Release notes for ${version} not found" && exit 1; }
2626

27-
# Get the release notes from the Github.
28-
curl -s "https://api.github.com/repos/$moby/releases/tags/${moby_tag}" | jq -r '.body' | sed 's/\r$//' > "$github_notes"
27+
release_json=$(gh api repos/moby/moby/releases -q ".[] | select(.name==\"v${version}\" or .tag_name==\"$moby_tag\")")
28+
29+
if [ -z "$release_json" ]; then
30+
echo "Release not found"
31+
printf '\033[0;34mTo create the draft Github release run the following command:\033[0m\n\n'
32+
echo gh -R moby/moby release create --draft \
33+
--notes-file '"'$docs_notes'"' \
34+
--title '"'v${version}'"' \
35+
${moby_tag}
36+
exit 1
37+
fi
38+
39+
release_id=$(echo "$release_json" | jq -r '.id')
40+
echo "$release_json" | jq -r '.body' | sed 's/\r$//' > "$github_notes"
2941

3042
docs_notes_diff=$(mktemp -t diff)
31-
# Copy docs_notes content and ensure it has exactly 2 blank lines at the end
32-
# Because Github for some reason adds an extra newline at the end of the release notes.
33-
sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' "$docs_notes" > "$docs_notes_diff"
34-
printf '\n\n' >> "$docs_notes_diff"
43+
# Copy docs_notes content and ensure it has exactly 1 blank line at the end
44+
sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' "$docs_notes" | sed '$a\' > "$docs_notes_diff"
3545

3646
# Compare the release notes.
3747
if diff -u --color=auto "$github_notes" "$docs_notes_diff"; then
@@ -41,4 +51,4 @@ fi
4151

4252
echo '========================================'
4353
printf '\033[0;34mTo update the release notes run the following command:\033[0m\n\n'
44-
echo gh -R moby/moby release edit "$moby_tag" --notes-file "$docs_notes"
54+
echo gh api "repos/moby/moby/releases/$release_id" -X PATCH -f '"body=$(cat "'$docs_notes'")"'

0 commit comments

Comments
 (0)