Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Even More Pipeline Parsing Fixes #2253

Merged
merged 5 commits into from
Jul 31, 2023
Merged

Even More Pipeline Parsing Fixes #2253

merged 5 commits into from
Jul 31, 2023

Conversation

moskyb
Copy link
Contributor

@moskyb moskyb commented Jul 28, 2023

This PR: Fixes two issues in the pipeline parser:

  • Block steps represented by a bare string were causing pipeline parsing to fail. Now, they'll be accepted
  • We were only ever inferring step type from attributes (eg. command steps have a command attribute). Turns out, step types can be explicit too (eg. type: "block"). We should also support these steps.

@moskyb moskyb requested review from DrJosh9000 and triarius and removed request for DrJosh9000 July 31, 2023 00:37
@moskyb moskyb marked this pull request as ready for review July 31, 2023 00:38
@moskyb moskyb changed the title [WIP] Even More Pipeline Parsing Fixes Even More Pipeline Parsing Fixes Jul 31, 2023
Copy link
Contributor

@triarius triarius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I think there's a stray file you didn't intend to commit?

@@ -10,6 +10,8 @@ fi

if [[ $(go mod tidy -v 2> >(wc -c)) != 0 ]]; then # go mod tidy -v outputs to stderr for some reason
echo "The go.mod file is out of sync with the source code"
echo "go mod tidy had output:"
go mod tidy -v
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💜

test.yml Outdated Show resolved Hide resolved

case o.Contains("trigger"):
step = make(TriggerStep)
func stepFromMap(o *ordered.MapSA) (Step, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Contributor

@DrJosh9000 DrJosh9000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this!

internal/pipeline/parser_test.go Outdated Show resolved Hide resolved
@moskyb moskyb force-pushed the even-more-parsing-fixes branch 2 times, most recently from 0b9acba to 4d3a73b Compare July 31, 2023 01:13
@@ -29,6 +30,29 @@ type Step interface {
selfInterpolater
}

type ScalarStep string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My feelings about the types here: I kinda want for it so that the types are easy to assemble in order to produce pipelines with Go. "ScalarStep" describes "a shape of data" more than "a type of step", and also overlaps semantic meaning with WaitStep and InputStep. But it's not too hard to use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, i had this thought as well... the other idea i had was something like

type WaitStep struct {
	Scalar string `yaml:"-"`
	RemainingFields map[string]any `yaml:",inline"`
}

and then have the marshal return the value of scalar if it's defined, and a regular marshal if not. is that something that feels better to you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sort of. I feel like if someone wants to write WaitStep{} it should marshal as "wait", because that's the kind of step it is. And then when we parse "wait" we should provide WaitStep{}, so that there's a canonical representation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is updated in a9621be - would love your thoughts!

Copy link
Contributor

@DrJosh9000 DrJosh9000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff!

Comment on lines 12 to 35
// In the buildkite pipeline yaml, some step types (broadly, wait steps, input steps and block steps) can be represented
// either by a scalar string (ie "wait") or by a mapping with keys and values and such
//
// This behaviour is difficult to cleanly model in go, which leads to the somewhat odd structure of the structs defined
// in this file - each type (WaitStep, InputStep) has a Scalar field which is set to the scalar value if the step was
// if, during pipeline parsing, the step was represented as a scalar, and is left empty if the step was represented as
// a mapping. In essence, if one of the fields of these structs is filled, the other should be empty.
//
// In reading this file, you may have noticed that I mentioned that there are three types of step that can be represented
// as a scalar, but there are only two structs defined here. This is because the third type, block steps, are represented
// in exactly the same way as input steps, so they can share the same struct. This is liable to change in the future,
// as conceptually they're different types, and it makes sense to have them as different types in go as well.
//
// Also also! The implementations for WaitStep and InputStep **almost**, but not quite identical. This is due to the behaviour
// of marshalling an empty struct into into JSON. For WaitStep, it makes sense that the empty &WaitStep{} struct marshals
// to "wait", but with InputStep, there's no way to tell whether it should be marshalled to "input" or "block", which
// have very different behaviour on the backend.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent commentary 👏👏

internal/pipeline/maybe_scalar_steps.go Outdated Show resolved Hide resolved
internal/pipeline/maybe_scalar_steps.go Outdated Show resolved Hide resolved
@moskyb moskyb enabled auto-merge July 31, 2023 06:00
@moskyb moskyb merged commit 5e7f87a into main Jul 31, 2023
1 check passed
@moskyb moskyb deleted the even-more-parsing-fixes branch July 31, 2023 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants