Skip to content

Commit 46e9a7b

Browse files
authored
chore: Fixes breaking change log with goreleaser (#499)
1 parent e79e169 commit 46e9a7b

File tree

3 files changed

+30
-27
lines changed

3 files changed

+30
-27
lines changed

.github/workflows/autoupdate-prod.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ jobs:
2323
git config --global user.name "github-actions[bot]"
2424
git add .
2525
git commit --allow-empty -m "fix: update OpenAPI spec"
26-
- name: Set old commit for SDK API diff
27-
run: echo "API_DIFF_OLD_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV
2826
- name: Run generation
2927
working-directory: ./tools
3028
run: |
@@ -43,9 +41,6 @@ jobs:
4341
if: steps.verify-changed-files.outputs.files_changed == 'true'
4442
run: |
4543
git add . && git commit -m "fix: Generated SDK source code and docs"
46-
- name: Set new commit for SDK API diff
47-
if: steps.verify-changed-files.outputs.files_changed == 'true'
48-
run: echo "API_DIFF_NEW_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV
4944
- name: Release updates
5045
if: steps.verify-changed-files.outputs.files_changed == 'true'
5146
working-directory: ./tools

tools/CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Templates are sourced from openapi generator:
4646

4747
https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources/go
4848

49-
## Go API Diff
49+
## gorelease
5050

51-
We use [go-apidiff](https://github.com/joelanford/go-apidiff) to detect if there are breaking changes and a new major version release is needed.
52-
In [Generate SDK Github action](../.github/workflows/autoupdate-prod.yaml), `API_DIFF_OLD_COMMIT` and `API_DIFF_NEW_COMMIT` are used to do the comparison.
51+
We use [gorelease](https://pkg.go.dev/golang.org/x/exp/cmd/gorelease) to detect if there are breaking changes and a new major version release is needed.
52+
In [Generate SDK Github action](../.github/workflows/autoupdate-prod.yaml), the last release is used for comparison.
Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,45 @@
11
#!/bin/bash
22
set -eu
3-
GOPATH=$(go env GOPATH)
43

54
# 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
95
TARGET_BREAKING_CHANGES_FILE=${TARGET_BREAKING_CHANGES_FILE:-""}
106
script_path=$(dirname "$0")
117

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"
1411

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
1614

1715
pushd "$script_path/../../../" || exit ## workaround for --repo-path="../" not working
1816
echo "Changed directory to $(pwd)"
1917
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+
2129
set -e
2230
popd || exit
2331

2432
if [ -z "$BREAKING_CHANGES" ]; then
25-
echo "No major breaking changes detected"
33+
echo "No major breaking changes detected"
2634
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
3745
fi

0 commit comments

Comments
 (0)