diff --git a/cmd/release.go b/cmd/release.go index 545c62a..c5a8f69 100644 --- a/cmd/release.go +++ b/cmd/release.go @@ -29,7 +29,7 @@ var releaseCmd = &cobra.Command{ Short: "Record a release on the service timeline", Long: `Records a single release event at the moment a tag is created, for pipelines that cut releases as a CI/CD step. Run this from a tag-triggered job; it resolves the version, release notes and commit range from git and posts one timeline event. -Requires the UIGRAPH_TOKEN environment variable.`, +Requires the UIGRAPH_TOKEN environment variable, except for a dry run, which reaches no gateway.`, Args: cobra.NoArgs, RunE: runRelease, } @@ -46,14 +46,14 @@ func init() { releaseCmd.Flags().StringVar(&enterpriseEnv, "enterprise", "", "Record the release on the UiGraph gateway ("+enterpriseGatewayURL+"); pass --enterprise=DEV for "+enterpriseDevGatewayURL) releaseCmd.Flags().Lookup("enterprise").NoOptDefVal = "DEFAULT" releaseCmd.MarkFlagsMutuallyExclusive("api-url", "enterprise") - releaseCmd.Flags().BoolVar(&dryRun, "dry-run", false, "Print the event without sending it to the gateway") + releaseCmd.Flags().BoolVar(&dryRun, "dry-run", false, "Print the event without sending it to the gateway (no token or gateway URL needed)") } func runRelease(cmd *cobra.Command, args []string) error { ctx := cmd.Context() token := os.Getenv("UIGRAPH_TOKEN") - if token == "" { + if token == "" && !dryRun { fmt.Fprintln(os.Stderr, "Error: UIGRAPH_TOKEN environment variable is required") os.Exit(1) } @@ -71,7 +71,7 @@ func runRelease(cmd *cobra.Command, args []string) error { if apiURL == "" { apiURL = os.Getenv("UIGRAPH_GATEWAY_URL") } - if apiURL == "" { + if apiURL == "" && !dryRun { fmt.Fprintln(os.Stderr, "Error: gateway URL is required (set --enterprise, --api-url or UIGRAPH_GATEWAY_URL environment variable)") os.Exit(1) } diff --git a/cmd/sync.go b/cmd/sync.go index 548095f..b8601e0 100644 --- a/cmd/sync.go +++ b/cmd/sync.go @@ -35,7 +35,8 @@ var syncCmd = &cobra.Command{ Use: "sync", Short: "Sync service and APIs to UiGraph Gateway", Long: `Reads .uigraph.yaml, captures git metadata, and syncs service, API groups, architecture diagrams, test packs/test cases, and database schemas (when configured) to the gateway. -This command is designed to run in CI/CD environments and requires UIGRAPH_TOKEN environment variable.`, +This command is designed to run in CI/CD environments and requires UIGRAPH_TOKEN environment variable. +A dry run reaches no gateway, so it needs neither UIGRAPH_TOKEN nor a gateway URL.`, Args: cobra.NoArgs, RunE: runSync, } @@ -46,7 +47,7 @@ func init() { syncCmd.Flags().StringVar(&enterpriseEnv, "enterprise", "", "Sync to the UiGraph gateway ("+enterpriseGatewayURL+"); pass --enterprise=DEV for "+enterpriseDevGatewayURL) syncCmd.Flags().Lookup("enterprise").NoOptDefVal = "DEFAULT" syncCmd.MarkFlagsMutuallyExclusive("api-url", "enterprise") - syncCmd.Flags().BoolVar(&dryRun, "dry-run", false, "Print payloads without sending to gateway") + syncCmd.Flags().BoolVar(&dryRun, "dry-run", false, "Print payloads without sending to gateway (no token or gateway URL needed)") syncCmd.Flags().BoolVar(&verbose, "verbose", false, "Log every MLflow and gateway request with its duration") } @@ -107,7 +108,7 @@ func runSync(cmd *cobra.Command, args []string) error { // 1. Authenticate using UIGRAPH_TOKEN token := os.Getenv("UIGRAPH_TOKEN") - if token == "" { + if token == "" && !dryRun { fmt.Fprintln(os.Stderr, "Error: UIGRAPH_TOKEN environment variable is required") os.Exit(1) } @@ -125,7 +126,7 @@ func runSync(cmd *cobra.Command, args []string) error { if apiURL == "" { apiURL = os.Getenv("UIGRAPH_GATEWAY_URL") } - if apiURL == "" { + if apiURL == "" && !dryRun { fmt.Fprintln(os.Stderr, "Error: gateway URL is required (set --enterprise, --api-url or UIGRAPH_GATEWAY_URL environment variable)") os.Exit(1) } @@ -909,18 +910,20 @@ func runSync(cmd *cobra.Command, args []string) error { watermarks := map[string]time.Time{} deletedProjects := map[string]bool{} - states, err := client.ListMLProjects(ctx, true) - if err != nil { - exitGatewayErrorErr("read last ML sync time", err) - } - for _, state := range states { - if state.DeletedAt != nil { - deletedProjects[state.Name] = true + if !dryRun { + states, err := client.ListMLProjects(ctx, true) + if err != nil { + exitGatewayErrorErr("read last ML sync time", err) } - if state.SyncedAt == nil { - continue + for _, state := range states { + if state.DeletedAt != nil { + deletedProjects[state.Name] = true + } + if state.SyncedAt == nil { + continue + } + watermarks[state.Name] = *state.SyncedAt } - watermarks[state.Name] = *state.SyncedAt } orderedML := make([]config.MLProjectRef, 0, len(cfg.ML))