22set -euo pipefail
33
44# script/apidiff.sh
5- # Compare API of only modified Go packages between PR HEAD and default branch using apidiff.
5+ # Compare API of only modified Go packages between PR HEAD and default branch using apidiff, formatted for GitHub Actions .
66# Usage: ./script/apidiff.sh
77
88# Ensure apidiff is installed
99if ! command -v apidiff & > /dev/null; then
10- echo " apidiff not found, installing..."
10+ echo " ::warning:: apidiff not found, installing..."
1111 go install golang.org/x/exp/apidiff@latest
1212fi
1313
@@ -39,7 +39,9 @@ readarray -t changed_dirs < <(
3939 sort -u
4040)
4141
42- echo " Modified directories: ${changed_dirs[*]} "
42+ echo " ::group::Modified directories"
43+ echo " ${changed_dirs[@]} "
44+ echo " ::endgroup::"
4345
4446# Create temporary workspace
4547tmp_dir=$( mktemp -d)
5961readarray -t pkgs < <( printf ' %s
6062' " ${pkgs[@]} " | sort -u)
6163
62- echo " Packages to compare: ${pkgs[*]} "
64+ echo " ::group::Packages to compare"
65+ echo " ${pkgs[@]} "
66+ echo " ::endgroup::"
6367
6468# Prepare export dirs
6569exports_dir=" $tmp_dir /exports"
@@ -73,7 +77,6 @@ generate_pkg_exports() {
7377 pushd " $tree " > /dev/null
7478 for pkg in " ${pkgs[@]} " ; do
7579 local file=${pkg// \/ / _} .export
76- echo " Exporting $pkg -> $dest /$file "
7780 apidiff -w " $dest /$file " " $pkg "
7881 done
7982 popd > /dev/null
@@ -83,24 +86,43 @@ generate_pkg_exports "$tmp_dir/base" "$base_exports"
8386generate_pkg_exports " $tmp_dir /head" " $head_exports "
8487
8588# Compare exports for breaking changes
86- echo -e " \nComparing API for breaking changes... "
89+ echo " ::group:: API Comparison "
8790broken=false
91+ declare -a broken_pkgs
8892for pkg in " ${pkgs[@]} " ; do
8993 file=${pkg// \/ / _} .export
90- echo -e " \nChecking $pkg "
91- if ! apidiff " $base_exports /$file " " $head_exports /$file " ; then
94+ echo " ::group::Checking $pkg "
95+ # show full apidiff output
96+ output=$( apidiff " $base_exports /$file " " $head_exports /$file " 2>&1 )
97+ echo " ${output} "
98+ if grep -q " Incompatible changes" <<< " $output" ; then
9299 broken=true
100+ broken_pkgs+=(" $pkg " )
101+ echo " ::error title=API break detected::$pkg has breaking changes"
102+ else
103+ echo " ::notice::$pkg : no incompatible changes"
93104 fi
105+ echo " ::endgroup::"
94106done
95107
108+ # Summary of broken packages
109+ if [[ " $broken " == true ]]; then
110+ echo " ::group::Breaking API Summary"
111+ for pkg in " ${broken_pkgs[@]} " ; do
112+ echo " ::error::$pkg has breaking changes"
113+ done
114+ echo " ::endgroup::"
115+ fi
116+ # end API Comparison
117+ echo " ::endgroup::"
118+
96119# Clean up worktrees
97120git worktree remove " $tmp_dir /base" --force
98121git worktree remove " $tmp_dir /head" --force
99122
100123# Final status
101124if [[ " $broken " == true ]]; then
102- echo -e " \nBreaking API changes detected."
103125 exit 1
104126else
105- echo -e " \nNo breaking API changes detected."
127+ echo " ::notice::No breaking API changes detected."
106128fi
0 commit comments