From 820f17c73bdb20282b34a7355b2518a9630af3dd Mon Sep 17 00:00:00 2001 From: Varsha Prasad Narsing Date: Tue, 13 Jun 2023 14:09:12 -0400 Subject: [PATCH] [Chore] Enable go-api-diff checker This PR introduces go-api-diff checker in Makefile and in CI to make sure we don't end up breaking APIs unintentionally. Signed-off-by: Varsha Prasad Narsing --- .github/workflows/apidiff.yml | 36 +++++++++++++++++++++++++++++++++++ Makefile | 8 ++++++++ go.work.sum | 10 +++++----- 3 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/apidiff.yml diff --git a/.github/workflows/apidiff.yml b/.github/workflows/apidiff.yml new file mode 100644 index 000000000..2ccf11758 --- /dev/null +++ b/.github/workflows/apidiff.yml @@ -0,0 +1,36 @@ +name: APIDiff + +# Trigger the workflow on pull requests and direct pushes to any branch +on: + push: + pull_request: + +jobs: + go-apidiff: + name: Verify API differences + runs-on: ubuntu-latest + # Pull requests from different repository only trigger this checks + if: (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) + steps: + - name: Clone the code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version-file: go.work + - name: Execute go-apidiff + uses: joelanford/go-apidiff@v0.6.0 + with: + compare-imports: true + print-compatible: true + - name: Report failure + uses: nashmaniac/create-issue-action@v1.1 + # Only report failures of pushes (PRs have are visible through the Checks section) to the default branch + if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/master' + with: + title: 🐛 go-apidiff failed for ${{ github.sha }} + token: ${{ secrets.GITHUB_TOKEN }} + labels: kind/bug + body: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} diff --git a/Makefile b/Makefile index e36b2087d..3755874e6 100644 --- a/Makefile +++ b/Makefile @@ -126,6 +126,14 @@ check-license: $(MYGOBIN)/addlicense lint: $(MYGOBIN)/golangci-lint $(MYGOBIN)/goimports $(builtinplugins) ./hack/for-each-module.sh "make lint" +.PHONY: apidiff +apidiff: go-apidiff ## Run the go-apidiff to verify any API differences compared with origin/master + $(GOBIN)/go-apidiff master --compare-imports --print-compatible --repo-path=. + +.PHONY: go-apidiff +go-apidiff: + go install github.com/joelanford/go-apidiff@v0.6.0 + .PHONY: test-unit-all test-unit-all: \ test-unit-non-plugin \ diff --git a/go.work.sum b/go.work.sum index 16f051230..55f6b5190 100644 --- a/go.work.sum +++ b/go.work.sum @@ -20,16 +20,17 @@ github.com/onsi/gomega v1.27.4/go.mod h1:riYq/GJKh8hhoM01HN6Vmuy93AarCXCBGpvFDK3 github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -go.starlark.net v0.0.0-20230525235612-a134d8f9ddca h1:VdD38733bfYv5tUZwEIskMM93VanwNIi5bIKnDrJdEY= -go.starlark.net v0.0.0-20230525235612-a134d8f9ddca/go.mod h1:jxU+3+j+71eXOW14274+SmmuW82qJzl6iZSeqEtTGds= -golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 h1:hb9wdF1z5waM+dSIICn1l0DkLVDT3hqhhQsDNUmHPRE= -golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +go.starlark.net v0.0.0-20190528202925-30ae18b8564f/go.mod h1:c1/X6cHgvdXj6pUlmWKMkuqRnW4K8x2vwt6JAaaircg= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= @@ -43,5 +44,4 @@ k8s.io/klog/v2 v2.80.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a/go.mod h1:y5VtZWM9sHHc2ZodIH/6SHzXj+TPU5USoA8lcIeKEKY= k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f/go.mod h1:byini6yhqGC14c3ebc/QwanvYwhuMWF6yz2F8uwW8eg= k8s.io/utils v0.0.0-20230209194617-a36077c30491/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -sigs.k8s.io/kustomize/cmd/config v0.11.3/go.mod h1:ENTZ8Ds12gewUpdxF5PJq/9qPVQFd5VPvMIL11wrBIU= sigs.k8s.io/structured-merge-diff v1.0.1-0.20191108220359-b1b620dd3f06 h1:zD2IemQ4LmOcAumeiyDWXKUI2SO0NYDe3H6QGvPOVgU=