Debian Codegraph @

internal/buildscripts/compare-apidiff.sh

raw
1 #!/usr/bin/env bash
2 #
3 # Copyright The OpenTelemetry Authors
4 # SPDX-License-Identifier: Apache-2.0
5
6 # This script is used to compare API state snapshots to the current package state in order to validate releases are not breaking backwards compatibility.
7
8 usage() {
9 echo "Usage: $0"
10 echo
11 echo "-c Check-incompatibility mode. Script will fail if an incompatible change is found. Default: 'false'"
12 echo "-p Package to generate API state snapshot of. Default: ''"
13 echo "-d directory where prior states will be read from. Default: './internal/data/apidiff'"
14 exit 1
15 }
16
17 package=""
18 input_dir="./internal/data/apidiff"
19 check_only=false
20 repo_toplevel="$( git rev-parse --show-toplevel )"
21 tools_mod_file="${repo_toplevel}/internal/tools/go.mod"
22
23 while getopts "cp:d:" o; do
24 case "${o}" in
25 c)
26 check_only=true
27 ;;
28 p)
29 package=$OPTARG
30 ;;
31 d)
32 input_dir=$OPTARG
33 ;;
34 *)
35 usage
36 ;;
37 esac
38 done
39 shift $((OPTIND-1))
40
41 if [ -z "$package" ]; then
42 usage
43 fi
44
45 set -e
46
47 if [ -e "$input_dir"/"$package"/apidiff.state ]; then
48 changes=$(go tool -modfile "${tools_mod_file}" apidiff "$input_dir"/"$package"/apidiff.state "$package")
49 if [ -n "$changes" ] && [ "$changes" != " " ]; then
50 SUB='Incompatible changes:'
51 if [ $check_only = true ] && [[ "$changes" =~ .*"$SUB".* ]]; then
52 echo "Incompatible Changes Found."
53 echo "Check the logs in the GitHub Action log group: 'Compare-States'."
54 exit 1
55 else
56 echo "Changes found in $package:"
57 echo "$changes"
58 fi
59 fi
60 fi