diff --git a/.github/workflows/verify-codegen.yml b/.github/workflows/verify-codegen.yml new file mode 100644 index 0000000..78318bc --- /dev/null +++ b/.github/workflows/verify-codegen.yml @@ -0,0 +1,45 @@ +name: Verify + +on: + pull_request: + workflow_dispatch: + +jobs: + verify: + name: Verify Codegen + + runs-on: ubuntu-latest + steps: + - name: Clone the code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Run Codegen + shell: bash + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: make update-codegen + + - name: Verify + shell: bash + run: | + # URL encode function for GitHub Actions annotations + # From: https://backreference.org/2009/12/23/how-to-match-newlines-in-sed/ + function urlencode() { + sed ':begin;$!N;s/\n/%0A/;tbegin' + } + + if [[ -z "$(git status --porcelain)" ]]; then + echo "${{ github.repository }} up to date." + else + echo "Found diffs in: $(git diff-index --name-only HEAD --)" + for x in $(git diff-index --name-only HEAD --); do + echo "::error file=$x::Please run 'make update-codegen'.%0A$(git diff $x | urlencode)" + done + echo "Generated code is out of date. Please run 'make update-codegen' and commit the changes." + exit 1 + fi diff --git a/Makefile b/Makefile index 7d3e945..1c987eb 100644 --- a/Makefile +++ b/Makefile @@ -239,6 +239,9 @@ undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/. create-kind-cluster: ./hack/create-kind-cluster.sh +.PHONY: update-codegen +update-codegen: generate manifests gen-mocks + ##@ Dependencies ## Location to install dependencies to