Skip to content

Commit 922a5ad

Browse files
lantoliwtrocki
andauthored
CLOUDP-261727: Breaking changes engine improvements (#432)
Co-authored-by: Wojciech Trocki <[email protected]>
1 parent aac6212 commit 922a5ad

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

.github/workflows/autoupdate-prod.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ 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
2628
- name: Run generation
2729
working-directory: ./tools
2830
run: |
@@ -41,13 +43,13 @@ jobs:
4143
if: steps.verify-changed-files.outputs.files_changed == 'true'
4244
run: |
4345
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
4449
- name: Release updates
4550
if: steps.verify-changed-files.outputs.files_changed == 'true'
4651
working-directory: ./tools
47-
env:
48-
GIT_BASE_REF: ${{ github.sha }}
49-
run: |
50-
make new-release
52+
run: make new-release
5153
- name: Ensure all markdown code is formatted
5254
if: steps.verify-changed-files.outputs.files_changed == 'true'
5355
working-directory: ./tools

tools/CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,8 @@ This enables us to verify new templates changes.
4545
Templates are sourced from openapi generator:
4646

4747
https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources/go
48+
49+
## Go API Diff
50+
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.

tools/releaser/scripts/breaking-changes.sh

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,21 @@ set -eu
33
GOPATH=$(go env GOPATH)
44

55
# Inputs:
6-
# GIT_BASE_REF - The base REF of the git repository (git rev-parse origin/main)
7-
# Usually "${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}"
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
88
# TARGET_BREAKING_CHANGES_FILE - file to save breaking changes
9+
TARGET_BREAKING_CHANGES_FILE=${TARGET_BREAKING_CHANGES_FILE:-""}
910
script_path=$(dirname "$0")
1011

1112
echo "Installing go-apidiff"
1213
go install github.com/joelanford/go-apidiff@latest > /dev/null
1314

14-
current_ref=$(git rev-parse main || echo)
15-
GIT_BASE_REF=${GIT_BASE_REF:-$current_ref}
16-
TARGET_BREAKING_CHANGES_FILE=${TARGET_BREAKING_CHANGES_FILE:-""}
17-
18-
echo "Running breaking changes check for $GIT_BASE_REF"
15+
echo "Running breaking changes check comparing commits ${API_DIFF_OLD_COMMIT} and ${API_DIFF_NEW_COMMIT}"
1916

2017
pushd "$script_path/../../../" || exit ## workaround for --repo-path="../" not working
2118
echo "Changed directory to $(pwd)"
2219
set +e
23-
BREAKING_CHANGES=$("$GOPATH/bin/go-apidiff" "$GIT_BASE_REF" "$(git rev-parse head)" --compare-imports="false" --print-compatible="false" )
20+
BREAKING_CHANGES=$("$GOPATH/bin/go-apidiff" "${API_DIFF_OLD_COMMIT}" "${API_DIFF_NEW_COMMIT}" --compare-imports="false" --print-compatible="false")
2421
set -e
2522
popd || exit
2623

0 commit comments

Comments
 (0)