Skip to content

chore: Fixes breaking change log with goreleaser #499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Dec 19, 2024
Merged
5 changes: 0 additions & 5 deletions .github/workflows/autoupdate-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ jobs:
git config --global user.name "github-actions[bot]"
git add .
git commit --allow-empty -m "fix: update OpenAPI spec"
- name: Set old commit for SDK API diff
run: echo "API_DIFF_OLD_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV
- name: Run generation
working-directory: ./tools
run: |
Expand All @@ -43,9 +41,6 @@ jobs:
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: |
git add . && git commit -m "fix: Generated SDK source code and docs"
- name: Set new commit for SDK API diff
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: echo "API_DIFF_NEW_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV
- name: Release updates
if: steps.verify-changed-files.outputs.files_changed == 'true'
working-directory: ./tools
Expand Down
6 changes: 3 additions & 3 deletions tools/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Templates are sourced from openapi generator:

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

## Go API Diff
## gorelease

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.
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.
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.
In [Generate SDK Github action](../.github/workflows/autoupdate-prod.yaml), the last release is used for comparison.
46 changes: 27 additions & 19 deletions tools/releaser/scripts/breaking-changes.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,45 @@
#!/bin/bash
set -eu
GOPATH=$(go env GOPATH)

# Inputs:
# API_DIFF_OLD_COMMIT: commit before the API changes to compare with. If not provided, script will fail with "unbound variable" error
# API_DIFF_NEW_COMMIT: commit with the new API changes. If not provided, script will fail with "unbound variable" error
# TARGET_BREAKING_CHANGES_FILE - file to save breaking changes
Comment on lines 4 to -8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does script do not have any inputs right now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no. The script now essentially uses the last release version (from extract-version.sh)

TARGET_BREAKING_CHANGES_FILE=${TARGET_BREAKING_CHANGES_FILE:-""}
script_path=$(dirname "$0")

echo "Installing go-apidiff"
go install github.com/joelanford/go-apidiff@latest > /dev/null
# shellcheck source=/dev/null
source "$script_path/extract-version.sh"
BASE_VERSION="github.com/mongodb/atlas-sdk-go/$SDK_MAJOR_VERSION@$SDK_VERSION"

echo "Running breaking changes check comparing commits ${API_DIFF_OLD_COMMIT} and ${API_DIFF_NEW_COMMIT}"
echo "Installing gorelease"
go install golang.org/x/exp/cmd/gorelease@latest >/dev/null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:FYI: Latest golang does have tools directive that allows us to define tools direclty in the go.mod.
See: golang/go#48429 (comment)


pushd "$script_path/../../../" || exit ## workaround for --repo-path="../" not working
echo "Changed directory to $(pwd)"
set +e
BREAKING_CHANGES=$("$GOPATH/bin/go-apidiff" "${API_DIFF_OLD_COMMIT}" "${API_DIFF_NEW_COMMIT}" --compare-imports="false" --print-compatible="false")

RAW_CHANGES=$(gorelease -base "$BASE_VERSION")
echo "Changes detected from BASE_VERSION $BASE_VERSION:"
echo "$RAW_CHANGES"

BREAKING_CHANGES=$(echo "$RAW_CHANGES" | awk '
/## incompatible changes/ {print "### incompatible changes"; collecting=1; next}
collecting && /^#/ {collecting=0}
collecting && NF {print "- "$0}
')

set -e
popd || exit

if [ -z "$BREAKING_CHANGES" ]; then
echo "No major breaking changes detected"
echo "No major breaking changes detected"
else
echo "Detected major breaking changes in the release"
if [ -z "$TARGET_BREAKING_CHANGES_FILE" ]; then
echo "Breaking changes for the major release"
echo "$BREAKING_CHANGES"
else
echo "Creating the breaking changes file with following breaking changes:"
echo "$BREAKING_CHANGES"
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" \
> "$script_path/../breaking_changes/${TARGET_BREAKING_CHANGES_FILE}.md"
fi
echo "Detected major breaking changes in the release"
if [ -z "$TARGET_BREAKING_CHANGES_FILE" ]; then
echo "Breaking changes for the major release"
echo "$BREAKING_CHANGES"
else
echo "Creating the breaking changes file with following breaking changes:"
echo "$BREAKING_CHANGES"
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" \
>"$script_path/../breaking_changes/${TARGET_BREAKING_CHANGES_FILE}.md"
fi
fi
Loading