Skip to content

Commit

Permalink
ci: fix codegen (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek authored Dec 9, 2024
1 parent 2b9555f commit ba02fcd
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 36 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ jobs:
echo "result=true" >> $GITHUB_OUTPUT
fi
codegen:
runs-on: ubuntu-latest
needs:
- up-to-date
if: needs.up-to-date.outputs.status != 'true'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- run: make update-codegen verify-codegen

enterprise-integration-tests:
needs:
- should-run-with-secrets
Expand All @@ -76,6 +86,7 @@ jobs:
runs-on: ubuntu-latest
needs:
- up-to-date
- codegen
- integration-tests
- enterprise-integration-tests
if: always()
Expand Down
13 changes: 13 additions & 0 deletions scripts/_lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash -e

function install-deepcopy-gen() {
go install k8s.io/code-generator/cmd/deepcopy-gen
}

function run-deepcopy-gen() {
local output_file="${1}"
deepcopy-gen \
--output-file zz_generated.deepcopy.go \
--go-header-file scripts/header-template.go.tmpl \
"${output_file}"
}
24 changes: 6 additions & 18 deletions scripts/update-deepcopy-gen.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
#!/bin/bash -e

go install k8s.io/code-generator/cmd/deepcopy-gen
TMP_DIR=$(mktemp -d)
trap "rm -rf $TMP_DIR" EXIT
set -x

# konnect package
deepcopy-gen --input-dirs github.com/kong/go-database-reconciler/pkg/konnect \
-O zz_generated.deepcopy \
--go-header-file scripts/header-template.go.tmpl \
--output-base $TMP_DIR
SCRIPT_DIR="$(dirname $0)"
source ${SCRIPT_DIR}/_lib.sh

cp $TMP_DIR/github.com/kong/go-database-reconciler/pkg/konnect/zz_generated.deepcopy.go \
pkg/konnect/zz_generated.deepcopy.go
install-deepcopy-gen

# file package
deepcopy-gen --input-dirs github.com/kong/go-database-reconciler/pkg/file \
-O zz_generated.deepcopy \
--go-header-file scripts/header-template.go.tmpl \
--output-base $TMP_DIR

cp $TMP_DIR/github.com/kong/go-database-reconciler/pkg/file/zz_generated.deepcopy.go \
pkg/file/zz_generated.deepcopy.go
run-deepcopy-gen ./pkg/konnect
run-deepcopy-gen ./pkg/file
11 changes: 8 additions & 3 deletions scripts/verify-codegen.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#!/bin/bash -e

FILE="kong_json_schema.json"
cp file/${FILE} /tmp/${FILE}
set -x

SCHEMA_FILE_NAME="kong_json_schema.json"
SOURCE_FILE_PATH="pkg/file/${SCHEMA_FILE_NAME}"
TMP_SCHEMA_FILE_PATH="/tmp/${SCHEMA_FILE_NAME}"

cp "${SOURCE_FILE_PATH}" "${TMP_SCHEMA_FILE_PATH}"
go generate ./...

diff -u /tmp/${FILE} file/${FILE}
diff -u "${TMP_SCHEMA_FILE_PATH}" "${SOURCE_FILE_PATH}"
31 changes: 16 additions & 15 deletions scripts/verify-deepcopy-gen.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
#!/bin/bash -e

go install k8s.io/code-generator/cmd/deepcopy-gen
set -x

SCRIPT_DIR="$(dirname $0)"
source ${SCRIPT_DIR}/_lib.sh

TMP_DIR=$(mktemp -d)
trap "rm -rf $TMP_DIR" EXIT

# konnect package
deepcopy-gen --input-dirs github.com/kong/go-database-reconciler/pkg/konnect \
-O zz_generated.deepcopy \
--go-header-file scripts/header-template.go.tmpl \
--output-base $TMP_DIR
function run-deepcopy-and-diff() {
local pkg="${1}"

cp ./pkg/${pkg}/zz_generated.deepcopy.go ${TMP_DIR}/${pkg}.zz_generated.deepcopy.go
run-deepcopy-gen ./pkg/${pkg}

diff -Naur konnect/zz_generated.deepcopy.go \
$TMP_DIR/github.com/kong/go-database-reconciler/pkg/konnect/zz_generated.deepcopy.go
diff -Naur ./pkg/${pkg}/zz_generated.deepcopy.go \
${TMP_DIR}/${pkg}.zz_generated.deepcopy.go
}

# file package
deepcopy-gen --input-dirs github.com/kong/go-database-reconciler/pkg/file \
-O zz_generated.deepcopy \
--go-header-file scripts/header-template.go.tmpl \
--output-base $TMP_DIR
install-deepcopy-gen

diff -Naur file/zz_generated.deepcopy.go \
$TMP_DIR/github.com/kong/go-database-reconciler/pkg/file/zz_generated.deepcopy.go
run-deepcopy-and-diff konnect
run-deepcopy-and-diff file

0 comments on commit ba02fcd

Please sign in to comment.