Skip to content
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

Enable generation and comparison of public API snapshots #3081

Merged
merged 10 commits into from
May 11, 2021
Merged
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ install-tools:
cd $(TOOLS_MOD_DIR) && go install github.com/ory/go-acc
cd $(TOOLS_MOD_DIR) && go install github.com/pavius/impi/cmd/impi
cd $(TOOLS_MOD_DIR) && go install github.com/tcnksm/ghr
cd $(TOOLS_MOD_DIR) && go install golang.org/x/exp/cmd/apidiff
cd $(TOOLS_MOD_DIR) && go install golang.org/x/tools/cmd/goimports
cd cmd/mdatagen && go install ./
cd cmd/checkdoc && go install ./
Expand Down Expand Up @@ -372,3 +373,13 @@ certs-dryrun:
.PHONY: checkdoc
checkdoc:
go run cmd/checkdoc/main.go cmd/checkdoc/docs.go --project-path $(CURDIR) --component-rel-path $(COMP_REL_PATH) --module-name $(MOD_NAME)

# Construct new API state snapshots
.PHONY: apidiff-build
apidiff-build:
@$(foreach pkg,$(ALL_PKGS),$(call exec-command,./internal/buildscripts/gen-apidiff.sh -p $(pkg)))

# Compare API state snapshots
.PHONY: apidiff-compare
apidiff-compare:
@$(foreach pkg,$(ALL_PKGS),$(call exec-command,./internal/buildscripts/compare-apidiff.sh -p $(pkg)))
44 changes: 44 additions & 0 deletions internal/buildscripts/compare-apidiff.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

# This script is used to compare API state snapshots to the current package state in order to validate releases are not breaking backwards compatibility.

usage() {
echo "Usage: $0"
echo
echo "-p Package to generate API state snapshot of. Default: ''"
echo "-d directory where prior states will be read from. Default: './internal/data/apidiff'"
exit 1
}

package=""
input_dir="./internal/data/apidiff"


while getopts "p:d:" o; do
case "${o}" in
p)
package=$OPTARG
;;
d)
input_dir=$OPTARG
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))

if [ -z $package ]; then
usage
fi

set -e

if [ -d $input_dir/$package ]; then
changes=$(apidiff $input_dir/$package/apidiff.state $package)
if [ ! -z "$changes" -a "$changes"!=" " ]; then
echo "Changes found in $package:"
echo "$changes"
fi
fi
65 changes: 65 additions & 0 deletions internal/buildscripts/gen-apidiff.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash

# This script is used to create API state snapshots used to validate releases are not breaking backwards compatibility.

usage() {
echo "Usage: $0"
echo
echo "-d Dry-run mode. No project files will not be modified. Default: 'false'"
echo "-p Package to generate API state snapshot of. Default: ''"
echo "-o Output directory where state will be written to. Default: './internal/data/apidiff'"
exit 1
}

dry_run=false
package=""
output_dir="./internal/data/apidiff"


while getopts "dp:o:" o; do
case "${o}" in
d)
dry_run=true
;;
p)
package=$OPTARG
;;
o)
output_dir=$OPTARG
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))

if [ -z $package ]; then
usage
fi

set -ex

# Create temp dir for generated files.
tmp_dir=$(mktemp -d -t apidiff)
clean_up() {
ARG=$?
if [ $dry_run = true ]; then
echo "Dry-run complete. Generated files can be found in $tmp_dir"
else
rm -rf "$tmp_dir"
fi
exit $ARG
}
trap clean_up EXIT

mkdir -p $tmp_dir/$package

apidiff -w $tmp_dir/$package/apidiff.state $package

# Copy files if not in dry-run mode.
if [ $dry_run = false ]; then
mkdir -p "$output_dir/$package" && \
cp "$tmp_dir/$package/apidiff.state" \
"$output_dir/$package"
fi
1 change: 1 addition & 0 deletions internal/tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ require (
github.com/ory/go-acc v0.2.6
github.com/pavius/impi v0.0.3
github.com/tcnksm/ghr v0.13.0
golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5
golang.org/x/tools v0.1.0
)
1 change: 1 addition & 0 deletions internal/tools/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5 h1:FR+oGxGfbQu1d+jglI3rCkjAjUnhRSZcUxr+DqlDLNo=
golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
Expand Down
1 change: 1 addition & 0 deletions internal/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ import (
_ "github.com/ory/go-acc"
_ "github.com/pavius/impi/cmd/impi"
_ "github.com/tcnksm/ghr"
_ "golang.org/x/exp/cmd/apidiff"
_ "golang.org/x/tools/cmd/goimports"
)