Skip to content

Commit 206d340

Browse files
committed
tooling: add crdify generator to run crdify against CRD changes
Signed-off-by: Bryce Palmer <[email protected]>
1 parent 83b017b commit 206d340

File tree

35 files changed

+3870
-2
lines changed

35 files changed

+3870
-2
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ verify-scripts:
7373
hack/verify-payload-featuregates.sh
7474

7575
.PHONY: verify
76-
verify: verify-scripts lint verify-crd-schema verify-codegen-crds
76+
verify: verify-scripts lint verify-crd-schema verify-crdify verify-codegen-crds
7777

7878
.PHONY: verify-codegen-crds
7979
verify-codegen-crds:
@@ -83,6 +83,10 @@ verify-codegen-crds:
8383
verify-crd-schema:
8484
bash -x hack/verify-crd-schema-checker.sh
8585

86+
.PHONY: verify-crdify
87+
verify-crdify:
88+
bash -x hack/verify-crdify.sh
89+
8690
.PHONY: verify-feature-promotion
8791
verify-feature-promotion:
8892
hack/verify-promoted-features-pass-tests.sh

hack/verify-crdify.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"
4+
5+
# Use PULL_BASE_REF for CI, otherwise use master unless overriden.
6+
COMPARISON_BASE=${COMPARISON_BASE:-${PULL_BASE_SHA:-"master"}}
7+
8+
# Use a trap so this gets printed at the end of the log even when we exit early due to an error/failure
9+
trap 'echo This verifier checks all files that have changed. In some cases you may have changed or renamed a file that \
10+
already contained api violations, but you are not introducing a new violation. In such cases it is appropriate to /override the \
11+
failing CI job.' EXIT
12+
13+
GENERATOR=crdify EXTRA_ARGS=--crdify:comparison-base=${COMPARISON_BASE} ${SCRIPT_ROOT}/hack/update-codegen.sh

tools/codegen/cmd/crdify.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/openshift/api/tools/codegen/pkg/crdify"
7+
"github.com/openshift/api/tools/codegen/pkg/generation"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
var crdifyComparisonBase = "master"
12+
13+
func newCrdifyCommand() *cobra.Command {
14+
cmd := &cobra.Command{
15+
Use: "crdify",
16+
Short: "crdify verifies compatibility of CRD API schemas",
17+
RunE: func(cmd *cobra.Command, args []string) error {
18+
genCtx, err := generation.NewContext(generation.Options{
19+
BaseDir: baseDir,
20+
APIGroupVersions: apiGroupVersions,
21+
})
22+
if err != nil {
23+
return fmt.Errorf("could not build generation context: %w", err)
24+
}
25+
26+
gen := crdify.NewGenerator(crdify.WithComparisonBase(crdifyComparisonBase))
27+
28+
return executeGenerators(genCtx, gen)
29+
},
30+
}
31+
32+
return cmd
33+
}
34+
35+
func init() {
36+
rootCmd.AddCommand(newCrdifyCommand())
37+
rootCmd.PersistentFlags().StringVar(&crdifyComparisonBase, "crdify:comparison-base", crdifyComparisonBase, "base branch/commit to compare against")
38+
}

0 commit comments

Comments
 (0)