Skip to content

Commit

Permalink
don't display 0.0 as supported VERSION (#3578)
Browse files Browse the repository at this point in the history
Fixes an error which stated `VERSION 0.0` is valid (when in fact it's
only ever used in tests)

Signed-off-by: Alex Couture-Beil <[email protected]>
  • Loading branch information
alexcb authored Dec 8, 2023
1 parent 970fb95 commit fd1623e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 14 additions & 1 deletion ast/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ func validateAst(ef spec.Earthfile) error {
return nil
}

func getValidVersionsFormatted() string {
if validEarthfileVersions[0] != "0.0" {
panic("validEarthfileVersions should start with 0.0")
}
var sb strings.Builder
latestIndex := len(validEarthfileVersions) - 1
for i := 1; i < latestIndex; i++ {
sb.WriteString(validEarthfileVersions[i] + ", ")
}
sb.WriteString("or " + validEarthfileVersions[latestIndex])
return sb.String()
}

func validVersion(ef spec.Earthfile) []error {
var errs []error

Expand All @@ -77,7 +90,7 @@ func validVersion(ef spec.Earthfile) []error {
}

if !isVersionValid {
errs = append(errs, errors.Errorf("Earthfile version is invalid, supported versions are %v", validEarthfileVersions))
errs = append(errs, errors.Errorf("Earthfile version is invalid, supported versions are %v", getValidVersionsFormatted()))
}

return errs
Expand Down
7 changes: 7 additions & 0 deletions tests/version/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,16 @@ test-whitespace-then-version:

test-invalid-versions:
DO --pass-args +RUN_EARTHLY_ARGS --should_fail=true --earthfile=invalid-major-version.earth --target=+base
RUN acbgrep 'Earthfile version is invalid, supported versions are 0.5, 0.6, or 0.7' earthly.output

DO --pass-args +RUN_EARTHLY_ARGS --should_fail=true --earthfile=invalid-minor-version.earth --target=+base
RUN acbgrep 'Earthfile version is invalid, supported versions are 0.5, 0.6, or 0.7' earthly.output

DO --pass-args +RUN_EARTHLY_ARGS --should_fail=true --earthfile=invalid-patch-version.earth --target=+base
RUN acbgrep 'unexpected VERSION arguments; should be VERSION \[flags\] <major-version>.<minor-version>' earthly.output

DO --pass-args +RUN_EARTHLY_ARGS --should_fail=true --earthfile=invalid-format-version.earth --target=+base
RUN acbgrep 'unexpected VERSION arguments; should be VERSION \[flags\] <major-version>.<minor-version>' earthly.output

test-all:
BUILD +test-single-line
Expand Down

0 comments on commit fd1623e

Please sign in to comment.