Skip to content

Commit

Permalink
Handle warnings from go-pipeline Parse
Browse files Browse the repository at this point in the history
  • Loading branch information
DrJosh9000 committed Apr 2, 2024
1 parent 4acfa17 commit dab8a99
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
10 changes: 7 additions & 3 deletions clicommand/pipeline_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/buildkite/go-pipeline/jwkutil"
"github.com/buildkite/go-pipeline/ordered"
"github.com/buildkite/go-pipeline/signature"
"github.com/buildkite/go-pipeline/warning"
"github.com/urfave/cli"
"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -262,7 +263,9 @@ var PipelineUploadCommand = cli.Command{
}

result, err := cfg.parseAndInterpolate(src, input, environ)
if err != nil {
if w := warning.As(err); w != nil {
l.Warn("There were some issues with the pipeline input:\n%v", w)
} else if err != nil {
return err
}

Expand Down Expand Up @@ -388,7 +391,7 @@ func searchForSecrets(

func (cfg *PipelineUploadConfig) parseAndInterpolate(src string, input io.Reader, environ *env.Environment) (*pipeline.Pipeline, error) {
result, err := pipeline.Parse(input)
if err != nil {
if err != nil && !warning.Is(err) {
return nil, fmt.Errorf("pipeline parsing of %q failed: %w", src, err)
}
if !cfg.NoInterpolation {
Expand All @@ -402,5 +405,6 @@ func (cfg *PipelineUploadConfig) parseAndInterpolate(src string, input io.Reader
return nil, fmt.Errorf("pipeline interpolation of %q failed: %w", src, err)
}
}
return result, nil
// err may be nil or a warning from pipeline.Parse
return result, err
}
9 changes: 7 additions & 2 deletions clicommand/tool_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/buildkite/go-pipeline"
"github.com/buildkite/go-pipeline/jwkutil"
"github.com/buildkite/go-pipeline/signature"
"github.com/buildkite/go-pipeline/warning"
"github.com/lestrrat-go/jwx/v2/jwk"
"github.com/urfave/cli"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -186,7 +187,9 @@ func signOffline(
}

parsedPipeline, err := pipeline.Parse(input)
if err != nil {
if w := warning.As(err); w != nil {
l.Warn("There were some issues with the pipeline input:\n%v", w)
} else if err != nil {
return fmt.Errorf("pipeline parsing of %q failed: %w", filename, err)
}

Expand Down Expand Up @@ -240,7 +243,9 @@ func signWithGraphQL(
l.Info("Signing pipeline with the repository URL:\n%s", resp.Pipeline.Repository.Url)

parsedPipeline, err := pipeline.Parse(strings.NewReader(resp.Pipeline.Steps.Yaml))
if err != nil {
if w := warning.As(err); w != nil {
l.Warn("There were some issues with the pipeline input:\n%v", w)
} else if err != nil {
return fmt.Errorf("pipeline parsing failed: %w", err)
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/aws/aws-sdk-go v1.51.11
github.com/brunoscheufler/aws-ecs-metadata-go v0.0.0-20220812150832-b6b31c6eeeaf
github.com/buildkite/bintest/v3 v3.2.0
github.com/buildkite/go-pipeline v0.4.1
github.com/buildkite/go-pipeline v0.5.0
github.com/buildkite/roko v1.2.0
github.com/buildkite/shellwords v0.0.0-20180315084142-c3f497d1e000
github.com/creack/pty v1.1.21
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ github.com/brunoscheufler/aws-ecs-metadata-go v0.0.0-20220812150832-b6b31c6eeeaf
github.com/brunoscheufler/aws-ecs-metadata-go v0.0.0-20220812150832-b6b31c6eeeaf/go.mod h1:CeKhh8xSs3WZAc50xABMxu+FlfAAd5PNumo7NfOv7EE=
github.com/buildkite/bintest/v3 v3.2.0 h1:1GqUILGGni5UViGPH/PbSq0MxB9gzY3J/P7vNVqCkX4=
github.com/buildkite/bintest/v3 v3.2.0/go.mod h1:+AdQZcVlzCiW2UyZWeG63xeH5z011XUBW6kWcRdaMtU=
github.com/buildkite/go-pipeline v0.4.1 h1:RZ1afSHOt5mUcTzhFab0WxKm90vvJsOUAPpfQBETgkE=
github.com/buildkite/go-pipeline v0.4.1/go.mod h1:/8zdWlpn40HsxZql5iUbr00P8/Fm/yud9+Bqrar8S3s=
github.com/buildkite/go-pipeline v0.5.0 h1:V8TaxKIzvhvIMIcHGtR1Z6Q9RFyTrtaO0e0N1A4BwdY=
github.com/buildkite/go-pipeline v0.5.0/go.mod h1:lHk0pJoZ8yxlOaUMRwzS/HyY0W6xh+ne8u+Cabw+DeM=
github.com/buildkite/interpolate v0.0.0-20200526001904-07f35b4ae251 h1:k6UDF1uPYOs0iy1HPeotNa155qXRWrzKnqAaGXHLZCE=
github.com/buildkite/interpolate v0.0.0-20200526001904-07f35b4ae251/go.mod h1:gbPR1gPu9dB96mucYIR7T3B7p/78hRVSOuzIWLHK2Y4=
github.com/buildkite/roko v1.2.0 h1:hbNURz//dQqNl6Eo9awjQOVOZwSDJ8VEbBDxSfT9rGQ=
Expand Down

0 comments on commit dab8a99

Please sign in to comment.