Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat(action): impl check-release flag for check command (#16426)

p0nyac096a7a910b
diff --git a/action/README.md b/action/README.md
index 5b986b1108..b12ff8acb8 100644
--- a/action/README.md
+++ b/action/README.md
@@ -60,6 +60,18 @@ These flags apply to the main `bytebase-action` command and its subcommands (`ch
- Default: `""` (empty string)
- Note: Migration filenames should conform to a versioning format. The version part of the filename must start with an optional 'v' or 'V', followed by one or more numbers, with subsequent numbers separated by a dot. For example: v1.2.3_description.sql, 1.0_initial_schema.sql, V2_add_users_table.sql. The version is extracted based on the pattern ^[vV]?(\d+(\.\d+)*).
+### `check` Command Specific Flags
+
+These flags are specific to the `check` subcommand (`bytebase-action check`).
+
+- **`--check-release`**: Determines whether to fail the command based on check results.
+ - Valid values:
+ - `SKIP`: Do not fail regardless of check results (default behavior).
+ - `FAIL_ON_WARNING`: Fail if there are warnings or errors in the check results.
+ - `FAIL_ON_ERROR`: Fail only if there are errors in the check results.
+ - Default: `SKIP`
+ - Note: Platform-specific outputs (GitHub comments, GitLab reports, etc.) are always generated before evaluating whether to fail.
+
### `rollout` Command Specific Flags
These flags are specific to the `rollout` subcommand (`bytebase-action rollout`).
diff --git a/action/main.go b/action/main.go
index 0e192f7793..4803861365 100644
--- a/action/main.go
+++ b/action/main.go
@@ -37,6 +37,14 @@ var (
Targets []string
FilePattern string
+ // bytebase-action check flags
+ // An enum to determine should we fail on warning or error.
+ // Valid values:
+ // - SKIP
+ // - FAIL_ON_WARNING
+ // - FAIL_ON_ERROR
+ CheckRelease string
+
// bytebase-action rollout flags
ReleaseTitle string // The title of the release
RolloutTitle string // The title of the rollout
@@ -75,9 +83,11 @@ func init() {
Use: "check",
Short: "Check the release files",
Args: cobra.NoArgs,
- PersistentPreRunE: nil,
+ PersistentPreRunE: validateCheckFlags,
RunE: runCheck,
}
+ cmdCheck.Flags().StringVar(&Config.CheckRelease, "check-release", "SKIP", "Whether to fail on warning/error. Valid values: SKIP, FAIL_ON_WARNING, FAIL_ON_ERROR")
+
cmd.AddCommand(cmdCheck)
// bytebase-action rollout flags
@@ -127,6 +137,16 @@ func validateSharedFlags(*cobra.Command, []string) error {
return nil
}
+func validateCheckFlags(*cobra.Command, []string) error {
+ switch Config.CheckRelease {
+ case "SKIP", "FAIL_ON_WARNING", "FAIL_ON_ERROR":
+ default:
+ return errors.Errorf("invalid check-release value: %s. Valid values: SKIP, FAIL_ON_WARNING, FAIL_ON_ERROR", Config.CheckRelease)
+ }
+
+ return nil
+}
+
func validateRolloutFlags(*cobra.Command, []string) error {
if Config.TargetStage == "" {
return errors.Errorf("target-stage is required and cannot be empty")
@@ -174,6 +194,7 @@ func writeOutputJSON(*cobra.Command, []string) error {
func runCheck(*cobra.Command, []string) error {
platform := getJobPlatform()
+ slog.Info("running on platform", "platform", platform.String())
client, err := NewClient(Config.URL, Config.ServiceAccount, Config.ServiceAccountSecret)
if err != nil {
return err
@@ -193,6 +214,7 @@ func runCheck(*cobra.Command, []string) error {
slog.Info("check release response", "resultCount", len(checkReleaseResponse.Results))
+ // Generate platform-specific outputs
switch platform {
case GitHub:
if err := github.CreateCommentAndAnnotation(checkReleaseResponse); err != nil {
@@ -211,6 +233,31 @@ func runCheck(*cobra.Command, []string) error {
return err
}
}
+
+ // Evaluate check results and return errors based on CheckRelease flag
+ if Config.CheckRelease == "SKIP" {
+ return nil
+ }
+
+ var errorCount, warningCount int
+ for _, result := range checkReleaseResponse.Results {
+ for _, advice := range result.Advices {
+ switch advice.Status {
+ case v1pb.Advice_ERROR:
+ errorCount++
+ case v1pb.Advice_WARNING:
+ warningCount++
+ }
+ }
+ }
+
+ if errorCount > 0 {
+ return errors.Errorf("found %d error(s) in release check. view on Bytebase", errorCount)
+ }
+ if warningCount > 0 && Config.CheckRelease == "FAIL_ON_WARNING" {
+ return errors.Errorf("found %d warning(s) in release check. view on Bytebase", warningCount)
+ }
+
return nil
}