From fd1623e4e73ef1841bf3c708e5c72cb0228c8d73 Mon Sep 17 00:00:00 2001 From: Alex Couture-Beil Date: Fri, 8 Dec 2023 15:36:51 -0800 Subject: [PATCH] don't display 0.0 as supported VERSION (#3578) 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 --- ast/validator.go | 15 ++++++++++++++- tests/version/Earthfile | 7 +++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ast/validator.go b/ast/validator.go index 41d0d115..5ac3ca60 100644 --- a/ast/validator.go +++ b/ast/validator.go @@ -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 @@ -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 diff --git a/tests/version/Earthfile b/tests/version/Earthfile index 12b3b810..1755ce0a 100644 --- a/tests/version/Earthfile +++ b/tests/version/Earthfile @@ -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\] .' 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\] .' earthly.output test-all: BUILD +test-single-line