Skip to content

Commit

Permalink
fix(attestation): push on dry-run (#932)
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
  • Loading branch information
migmartri committed Jun 11, 2024
1 parent 6503995 commit 48a9540
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
4 changes: 4 additions & 0 deletions app/cli/cmd/attestation_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func newAttestationInitCmd() *cobra.Command {
return newGracefulError(err)
}

if res.DryRun {
logger.Info().Msg("The attestation is being crafted in dry-run mode. It will not get stored once rendered")
}

return encodeOutput(res, simpleStatusTable)
},
}
Expand Down
11 changes: 1 addition & 10 deletions app/cli/cmd/attestation_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"time"

"github.com/jedib0t/go-pretty/v6/table"
"github.com/jedib0t/go-pretty/v6/text"
"github.com/muesli/reflow/wrap"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -107,15 +106,7 @@ func attestationStatusTableOutput(status *action.AttestationStatusResult, full b
return err
}

if err := envVarsTable(status, full); err != nil {
return err
}

if status.DryRun {
colors := text.Colors{text.FgHiBlack, text.BgHiYellow}
fmt.Println(colors.Sprint("The attestation is being crafted in dry-run mode. It will not get stored once rendered"))
}
return nil
return envVarsTable(status, full)
}

func envVarsTable(status *action.AttestationStatusResult, full bool) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ import (

// ValidateComplete makes sure that the crafting state has been completed
// before it gets passed to the renderer
func (state *CraftingState) ValidateComplete() error {
func (state *CraftingState) ValidateComplete(dryRun bool) error {
validator, err := protovalidate.New()
if err != nil {
return fmt.Errorf("could not create validator: %w", err)
}

if err := validator.Validate(state); err != nil {
return fmt.Errorf("invalid crafting state: %w", err)
// We do not want to validate the schema of the state if we are just doing a dry run
// since it's known to not to contain the workflow metadata information
if !dryRun {
if err := validator.Validate(state); err != nil {
return fmt.Errorf("invalid crafting state: %w", err)
}
}

// Semantic errors
Expand Down
2 changes: 1 addition & 1 deletion internal/attestation/crafter/crafter.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ func (c *Crafter) ValidateAttestation() error {
return err
}

return c.CraftingState.ValidateComplete()
return c.CraftingState.ValidateComplete(c.CraftingState.GetDryRun())
}

func (c *Crafter) requireStateLoaded() error {
Expand Down

0 comments on commit 48a9540

Please sign in to comment.