From 614635cd738670887e1e6b1378a1cee4b916c455 Mon Sep 17 00:00:00 2001 From: Marco Iorio Date: Tue, 24 Nov 2020 08:44:00 +0100 Subject: [PATCH] Github Actions: ensure generated files are up-to-date --- .github/workflows/test.yml | 70 +++++++++++++++++++++++++++++++++++--- operators/Makefile | 6 +--- operators/go.mod | 2 +- 3 files changed, 68 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 98909a041..d28638d58 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,14 +1,14 @@ name: Code testing on: - pull_request: + pull_request_target: types: - opened - reopened - synchronize jobs: - laboratory-operator: - name: Laboratory Operator + operators: + name: Operators runs-on: ubuntu-latest steps: @@ -29,13 +29,75 @@ jobs: curl -L -O "https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${version}/kubebuilder_${version}_linux_${arch}.tar.gz" tar -zxvf kubebuilder_${version}_linux_${arch}.tar.gz mv kubebuilder_${version}_linux_${arch} kubebuilder && sudo mv kubebuilder /usr/local/ - + - name: Perform the tests working-directory: operators/ run: | make test + operators-generated: + name: Operators (Generated manifests) + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + persist-credentials: false + + - name: Setup Go + uses: actions/setup-go@v1 + with: + go-version: 1.15 + + - name: Run the automatic generation + working-directory: operators/ + run: | + make generate + make manifests + + - name: Gather the differences + id: git-diff + run: | + output=$(git diff | head -n 100) + exit_code=$([ "${output}" ] && echo 1 || echo 0) + + # Required to correctly manage multi-line outputs + output="${output//'%'/'%25'}" + output="${output//$'\n'/'%0A'}" + output="${output//$'\r'/'%0D'}" + + echo "::set-output name=diff::${output}" + + # Trigger a failure in case the diff is not empty + exit ${exit_code} + + - name: Issue a comment in case the diff is not empty + uses: peter-evans/create-or-update-comment@v1 + with: + token: ${{ secrets.CI_TOKEN }} + issue-number: ${{ github.event.pull_request.number }} + body: | + The generated files in the `operators/` folder appear to be out-of-date. + + Please, ensure you are using the correct version of `controller-gen` and re-run: + ``` + make generate + make manifests + ``` + +
+ Here it is an excerpt of the diff: + + ```diff + ${{ steps.git-diff.outputs.diff }} + ``` +
+ reactions: confused + if: failure() + + kubernetes-manifests: name: Kubernetes manifests runs-on: ubuntu-latest diff --git a/operators/Makefile b/operators/Makefile index fe87c9bd4..d654ab2a3 100644 --- a/operators/Makefile +++ b/operators/Makefile @@ -1,7 +1,3 @@ - -# Produce CRDs that work back to Kubernetes 1.11 (no version conversion) -CRD_OPTIONS ?= "crd:trivialVersions=true" - # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) GOBIN=$(shell go env GOPATH)/bin @@ -25,7 +21,7 @@ uninstall: manifests # Generate manifests e.g. CRD, RBAC etc. manifests: controller-gen - $(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./api/..." output:crd:artifacts:config=deploy/crds + $(CONTROLLER_GEN) crd:maxDescLen=127 paths="./api/..." output:crd:artifacts:config=deploy/crds # Run go fmt against code fmt: go fmt ./... diff --git a/operators/go.mod b/operators/go.mod index b859a9fa0..fbf8ae98d 100644 --- a/operators/go.mod +++ b/operators/go.mod @@ -1,6 +1,6 @@ module github.com/netgroup-polito/CrownLabs/operators -go 1.13 +go 1.15 require ( github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect