-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #183 from ulucinar/break-crddiff
Break uptest & crddiff into two separate binaries in preparation of moving uptest under to the Crossplane organization
- Loading branch information
Showing
5 changed files
with
164 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Promote | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
description: 'Release version (e.g. v0.1.0)' | ||
required: true | ||
channel: | ||
description: 'Release channel' | ||
required: true | ||
default: 'alpha' | ||
|
||
env: | ||
# Common versions | ||
GO_VERSION: '1.19' | ||
|
||
# Common users. We can't run a step 'if secrets.XXX != ""' but we can run | ||
# a step 'if env.XXX' != ""', so we copy these to succinctly test whether | ||
# credentials have been provided before trying to run steps that need them. | ||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
|
||
jobs: | ||
promote-artifacts: | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4 | ||
with: | ||
submodules: true | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
|
||
- name: Fetch History | ||
run: git fetch --prune --unshallow | ||
|
||
- name: Promote Artifacts in S3 | ||
if: env.AWS_ACCESS_KEY_ID != '' | ||
run: make -j2 promote BRANCH_NAME=${GITHUB_REF##*/} | ||
env: | ||
VERSION: ${{ github.event.inputs.version }} | ||
CHANNEL: ${{ github.event.inputs.channel }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
AWS_DEFAULT_REGION: us-east-1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright 2024 Upbound Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// main package for the uptest tooling. | ||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"syscall" | ||
|
||
"gopkg.in/alecthomas/kingpin.v2" | ||
|
||
"github.com/upbound/uptest/internal/crdschema" | ||
) | ||
|
||
var ( | ||
app = kingpin.New("crddiff", "A tool for checking breaking API changes between two CRD OpenAPI v3 schemas. The schemas can come from either two revisions of a CRD, or from the versions declared in a single CRD.").DefaultEnvars() | ||
// crddiff sub-commands | ||
cmdRevision = app.Command("revision", "Compare the first schema available in a base CRD against the first schema from a revision CRD") | ||
cmdSelf = app.Command("self", "Use OpenAPI v3 schemas from a single CRD") | ||
) | ||
|
||
var ( | ||
revisionDiffOptions = getCRDdiffCommonOptions(cmdRevision) | ||
selfDiffOptions = getCRDdiffCommonOptions(cmdSelf) | ||
) | ||
|
||
func getCRDdiffCommonOptions(cmd *kingpin.CmdClause) *crdschema.CommonOptions { | ||
opts := &crdschema.CommonOptions{} | ||
cmd.Flag("enable-upjet-extensions", "Enables diff extensions for the CRDs generated by upjet. "+ | ||
"An example extension is the processing of the x-kubernetes-validations CEL rules generated by upjet.").Default("false").BoolVar(&opts.EnableUpjetExtensions) | ||
return opts | ||
} | ||
|
||
func main() { | ||
switch kingpin.MustParse(app.Parse(os.Args[1:])) { | ||
case cmdRevision.FullCommand(): | ||
crdDiffRevision() | ||
case cmdSelf.FullCommand(): | ||
crdDiffSelf() | ||
} | ||
} | ||
|
||
var ( | ||
baseCRDPath = cmdRevision.Arg("base", "The manifest file path of the CRD to be used as the base").Required().ExistingFile() | ||
revisionCRDPath = cmdRevision.Arg("revision", "The manifest file path of the CRD to be used as a revision to the base").Required().ExistingFile() | ||
) | ||
|
||
func crdDiffRevision() { | ||
crdDiff, err := crdschema.NewRevisionDiff(*baseCRDPath, *revisionCRDPath, crdschema.WithRevisionDiffCommonOptions(revisionDiffOptions)) | ||
kingpin.FatalIfError(err, "Failed to load CRDs") | ||
reportDiff(crdDiff) | ||
} | ||
|
||
var ( | ||
crdPath = cmdSelf.Arg("crd", "The manifest file path of the CRD whose versions are to be checked for breaking changes").Required().ExistingFile() | ||
) | ||
|
||
func crdDiffSelf() { | ||
crdDiff, err := crdschema.NewSelfDiff(*crdPath, crdschema.WithSelfDiffCommonOptions(selfDiffOptions)) | ||
kingpin.FatalIfError(err, "Failed to load CRDs") | ||
reportDiff(crdDiff) | ||
} | ||
|
||
func reportDiff(crdDiff crdschema.SchemaCheck) { | ||
versionMap, err := crdDiff.GetBreakingChanges() | ||
kingpin.FatalIfError(err, "Failed to compute CRD breaking API changes") | ||
|
||
l := log.New(os.Stderr, "", 0) | ||
breakingDetected := false | ||
for v, d := range versionMap { | ||
if d.Empty() { | ||
continue | ||
} | ||
breakingDetected = true | ||
l.Printf("Version %q:\n", v) | ||
l.Println(crdschema.GetDiffReport(d)) | ||
} | ||
if breakingDetected { | ||
syscall.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters