|
1 | 1 | #!/bin/bash |
2 | 2 | set -eu |
3 | | -GOPATH=$(go env GOPATH) |
4 | 3 |
|
5 | 4 | # Inputs: |
6 | | -# API_DIFF_OLD_COMMIT: commit before the API changes to compare with. If not provided, script will fail with "unbound variable" error |
7 | | -# API_DIFF_NEW_COMMIT: commit with the new API changes. If not provided, script will fail with "unbound variable" error |
8 | | -# TARGET_BREAKING_CHANGES_FILE - file to save breaking changes |
9 | 5 | TARGET_BREAKING_CHANGES_FILE=${TARGET_BREAKING_CHANGES_FILE:-""} |
10 | 6 | script_path=$(dirname "$0") |
11 | 7 |
|
12 | | -echo "Installing go-apidiff" |
13 | | -go install github.com/joelanford/go-apidiff@latest > /dev/null |
| 8 | +# shellcheck source=/dev/null |
| 9 | +source "$script_path/extract-version.sh" |
| 10 | +BASE_VERSION="github.com/mongodb/atlas-sdk-go/$SDK_MAJOR_VERSION@$SDK_VERSION" |
14 | 11 |
|
15 | | -echo "Running breaking changes check comparing commits ${API_DIFF_OLD_COMMIT} and ${API_DIFF_NEW_COMMIT}" |
| 12 | +echo "Installing gorelease" |
| 13 | +go install golang.org/x/exp/cmd/gorelease@latest >/dev/null |
16 | 14 |
|
17 | 15 | pushd "$script_path/../../../" || exit ## workaround for --repo-path="../" not working |
18 | 16 | echo "Changed directory to $(pwd)" |
19 | 17 | set +e |
20 | | -BREAKING_CHANGES=$("$GOPATH/bin/go-apidiff" "${API_DIFF_OLD_COMMIT}" "${API_DIFF_NEW_COMMIT}" --compare-imports="false" --print-compatible="false") |
| 18 | + |
| 19 | +RAW_CHANGES=$(gorelease -base "$BASE_VERSION") |
| 20 | +echo "Changes detected from BASE_VERSION $BASE_VERSION:" |
| 21 | +echo "$RAW_CHANGES" |
| 22 | + |
| 23 | +BREAKING_CHANGES=$(echo "$RAW_CHANGES" | awk ' |
| 24 | + /## incompatible changes/ {print "### incompatible changes"; collecting=1; next} |
| 25 | + collecting && /^#/ {collecting=0} |
| 26 | + collecting && NF {print "- "$0} |
| 27 | +') |
| 28 | + |
21 | 29 | set -e |
22 | 30 | popd || exit |
23 | 31 |
|
24 | 32 | if [ -z "$BREAKING_CHANGES" ]; then |
25 | | - echo "No major breaking changes detected" |
| 33 | + echo "No major breaking changes detected" |
26 | 34 | else |
27 | | - echo "Detected major breaking changes in the release" |
28 | | - if [ -z "$TARGET_BREAKING_CHANGES_FILE" ]; then |
29 | | - echo "Breaking changes for the major release" |
30 | | - echo "$BREAKING_CHANGES" |
31 | | - else |
32 | | - echo "Creating the breaking changes file with following breaking changes:" |
33 | | - echo "$BREAKING_CHANGES" |
34 | | - echo -e "# Breaking Changes\n## SDK changes\n$BREAKING_CHANGES\n## API Changelog\n https://www.mongodb.com/docs/atlas/reference/api-resources-spec/changelog" \ |
35 | | - > "$script_path/../breaking_changes/${TARGET_BREAKING_CHANGES_FILE}.md" |
36 | | - fi |
| 35 | + echo "Detected major breaking changes in the release" |
| 36 | + if [ -z "$TARGET_BREAKING_CHANGES_FILE" ]; then |
| 37 | + echo "Breaking changes for the major release" |
| 38 | + echo "$BREAKING_CHANGES" |
| 39 | + else |
| 40 | + echo "Creating the breaking changes file with following breaking changes:" |
| 41 | + echo "$BREAKING_CHANGES" |
| 42 | + echo -e "# Breaking Changes\n## SDK changes\n$BREAKING_CHANGES\n## API Changelog\n https://www.mongodb.com/docs/atlas/reference/api-resources-spec/changelog" \ |
| 43 | + >"$script_path/../breaking_changes/${TARGET_BREAKING_CHANGES_FILE}.md" |
| 44 | + fi |
37 | 45 | fi |
0 commit comments