Skip to content

Commit

Permalink
add go-apidiff to verify api differences
Browse files Browse the repository at this point in the history
- create apidiff.yaml in github workflows
- Added `apidiff` target to Makefile for local testing
- Always compare with master for any api differences
- Invoke tests in CI only on pull_request from a different repo
  • Loading branch information
Goutam Tadi committed May 27, 2021
1 parent 68841fd commit 9e94fe0
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/apidiff.yml
Original file line number Diff line number Diff line change
@@ -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@v2
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.15'
- name: Execute go-apidiff
uses: joelanford/[email protected]
with:
compare-imports: true
print-compatible: true
- name: Report failure
uses: nashmaniac/[email protected]
# 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 }}
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ golangci-lint:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) v1.37.1 ;\
}

.PHONY: apidiff
apidiff: go-apidiff ## Run the go-apidiff to verify any API differences compared with origin/master
$(GO_APIDIFF) master --compare-imports --print-compatible --repo-path=.

GO_APIDIFF = $(shell pwd)/bin/go-apidiff
go-apidiff:
@[ -f $(GO_APIDIFF) ] || { \
cd tools && go build -tags=tools -o $(GO_APIDIFF) github.com/joelanford/go-apidiff ;\
}

##@ Tests

.PHONY: test
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/cloudflare/cfssl v1.5.0 // for `kubebuilder alpha config-gen`
github.com/go-logr/logr v0.3.0 // indirect
github.com/gobuffalo/flect v0.2.2
github.com/joelanford/go-apidiff v0.1.0
// TODO: remove this in favor of embed once using 1.16
github.com/markbates/pkger v0.17.1 // for `kubebuilder alpha config-gen`
github.com/onsi/ginkgo v1.15.0
Expand Down
Loading

0 comments on commit 9e94fe0

Please sign in to comment.