|
| 1 | +#!/bin/bash |
| 2 | +# Update the Github release notes to match the release notes from the docs. |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +version="${1:-}" |
| 6 | + |
| 7 | +if [ -z "$version" ]; then |
| 8 | + echo "Usage: $0 <version>" |
| 9 | + exit 1 |
| 10 | +fi |
| 11 | + |
| 12 | +moby="moby/moby" |
| 13 | +version="${version#v}" # remove the v prefix |
| 14 | +major_version="${version%%.*}" # get the major version (e.g. 29.0.3 -> 29) |
| 15 | +moby_tag="docker-v${version}" |
| 16 | + |
| 17 | +docs_notes=$(mktemp -t new) |
| 18 | +github_notes=$(mktemp -t old) |
| 19 | + |
| 20 | +# Get the release notes from the docs. |
| 21 | +grep -A 10000 "## ${version}" "content/manuals/engine/release-notes/${major_version}.md" | \ |
| 22 | + grep -m 2 -A 0 -B 10000 '^## ' | \ |
| 23 | + sed '$d' | `# remove the last line` \ |
| 24 | + sed '/{{< release-date /{N;d;}' \ |
| 25 | + > "$docs_notes" |
| 26 | + |
| 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" |
| 29 | + |
| 30 | +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" |
| 35 | + |
| 36 | +# Compare the release notes. |
| 37 | +if diff -u --color=auto "$github_notes" "$docs_notes_diff"; then |
| 38 | + printf '\033[0;32mThe release notes are already up to date.\033[0m\n' |
| 39 | + exit 0 |
| 40 | +fi |
| 41 | + |
| 42 | +echo '========================================' |
| 43 | +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" |
0 commit comments