diff --git a/tooling/templatize/internal/end2end/e2e_test.go b/tooling/templatize/internal/end2end/e2e_test.go index d74625069..63ccd231a 100644 --- a/tooling/templatize/internal/end2end/e2e_test.go +++ b/tooling/templatize/internal/end2end/e2e_test.go @@ -3,6 +3,7 @@ package testutil import ( "context" "os" + "path/filepath" "testing" "gotest.tools/v3/assert" @@ -134,14 +135,15 @@ func TestE2EShell(t *testing.T) { t.Skip("Skipping end-to-end tests") } - tmpDir := t.TempDir() + tmpDir, err := filepath.EvalSymlinks(t.TempDir()) + assert.NilError(t, err) e2eImpl := newE2E(tmpDir) e2eImpl.AddStep(pipeline.Step{ Name: "readInput", Action: "Shell", - Command: "/usr/bin/echo ${PWD} > env.txt", + Command: "/bin/echo ${PWD} > env.txt", }) persistAndRun(t, &e2eImpl) diff --git a/tooling/templatize/pkg/pipeline/pipeline.schema.v1.json b/tooling/templatize/pkg/pipeline/pipeline.schema.v1.json index 6a3c16dc9..3c1bb8225 100644 --- a/tooling/templatize/pkg/pipeline/pipeline.schema.v1.json +++ b/tooling/templatize/pkg/pipeline/pipeline.schema.v1.json @@ -188,7 +188,7 @@ "command": { "type": "string" }, - "envVars": { + "variables": { "type": "array", "items": { "$ref": "#/definitions/variable" diff --git a/tooling/templatize/pkg/pipeline/shell_test.go b/tooling/templatize/pkg/pipeline/shell_test.go index a85e6a757..bee5ff4de 100644 --- a/tooling/templatize/pkg/pipeline/shell_test.go +++ b/tooling/templatize/pkg/pipeline/shell_test.go @@ -25,25 +25,25 @@ func TestCreateCommand(t *testing.T) { { name: "basic", step: &Step{ - Command: "/usr/bin/echo hello", + Command: "/bin/echo hello", }, - expectedScript: buildBashScript("/usr/bin/echo hello"), + expectedScript: buildBashScript("/bin/echo hello"), }, { name: "dry-run", step: &Step{ - Command: "/usr/bin/echo hello", + Command: "/bin/echo hello", DryRun: DryRun{ - Command: "/usr/bin/echo dry-run", + Command: "/bin/echo dry-run", }, }, dryRun: true, - expectedScript: buildBashScript("/usr/bin/echo dry-run"), + expectedScript: buildBashScript("/bin/echo dry-run"), }, { name: "dry-run-env", step: &Step{ - Command: "/usr/bin/echo", + Command: "/bin/echo", DryRun: DryRun{ Variables: []Variable{ { @@ -54,14 +54,14 @@ func TestCreateCommand(t *testing.T) { }, }, dryRun: true, - expectedScript: buildBashScript("/usr/bin/echo"), + expectedScript: buildBashScript("/bin/echo"), envVars: map[string]string{}, expectedEnv: []string{"DRY_RUN=true"}, }, { name: "dry-run fail", step: &Step{ - Command: "/usr/bin/echo", + Command: "/bin/echo", }, dryRun: true, skipCommand: true, diff --git a/tooling/templatize/pkg/pipeline/validation.go b/tooling/templatize/pkg/pipeline/validation.go index 033a909b5..ec70460ab 100644 --- a/tooling/templatize/pkg/pipeline/validation.go +++ b/tooling/templatize/pkg/pipeline/validation.go @@ -11,6 +11,8 @@ import ( //go:embed pipeline.schema.v1.json var pipelineSchemaV1Content []byte +var pipelineSchemaV1Ref = "pipeline.schema.v1" +var defaultSchemaRef = pipelineSchemaV1Ref func ValidatePipelineSchema(pipelineContent []byte) error { // unmarshal pipeline content @@ -21,7 +23,7 @@ func ValidatePipelineSchema(pipelineContent []byte) error { } // load pipeline schema - pipelineSchema, schemaUrl, err := getSchemaForPipeline(pipelineMap) + pipelineSchema, schemaRef, err := getSchemaForPipeline(pipelineMap) if err != nil { return fmt.Errorf("failed to load pipeline schema: %v", err) } @@ -29,49 +31,46 @@ func ValidatePipelineSchema(pipelineContent []byte) error { // validate pipeline schema err = pipelineSchema.Validate(pipelineMap) if err != nil { - return fmt.Errorf("pipeline is not compliant with schema %s: %v", schemaUrl, err) + return fmt.Errorf("pipeline is not compliant with schema %s: %v", schemaRef, err) } return nil } -func getSchemaForPipeline(pipelineMap map[string]interface{}) (*jsonschema.Schema, string, error) { +func getSchemaForPipeline(pipelineMap map[string]interface{}) (pipelineSchema *jsonschema.Schema, schemaRef string, err error) { schemaRef, ok := pipelineMap["$schema"].(string) if !ok { - return nil, "", fmt.Errorf("pipeline $schema reference is missing - add $schema: pipeline.schema.v1") + schemaRef = defaultSchemaRef } switch schemaRef { - case "pipeline.schema.v1": - return compileSchema(pipelineSchemaV1Content) + case pipelineSchemaV1Ref: + pipelineSchema, err = compileSchema(schemaRef, pipelineSchemaV1Content) default: return nil, "", fmt.Errorf("unsupported schema reference: %s", schemaRef) } + return } -func compileSchema(schemaBytes []byte) (*jsonschema.Schema, string, error) { +func compileSchema(schemaRef string, schemaBytes []byte) (*jsonschema.Schema, error) { // parse schema content schemaMap := make(map[string]interface{}) err := json.Unmarshal(schemaBytes, &schemaMap) if err != nil { - return nil, "", fmt.Errorf("failed to unmarshal schema content: %v", err) - } - schemaUrl, ok := schemaMap["title"].(string) - if !ok { - return nil, "", fmt.Errorf("failed to get schema title") + return nil, fmt.Errorf("failed to unmarshal schema content: %v", err) } // compile schema c := jsonschema.NewCompiler() - err = c.AddResource(schemaUrl, schemaMap) + err = c.AddResource(schemaRef, schemaMap) if err != nil { - return nil, "", fmt.Errorf("failed to add schema resource %s: %v", schemaUrl, err) + return nil, fmt.Errorf("failed to add schema resource %s: %v", schemaRef, err) } - pipelineSchema, err := c.Compile(schemaUrl) + pipelineSchema, err := c.Compile(schemaRef) if err != nil { - return nil, "", fmt.Errorf("failed to compile schema %s: %v", schemaUrl, err) + return nil, fmt.Errorf("failed to compile schema %s: %v", schemaRef, err) } - return pipelineSchema, schemaUrl, nil + return pipelineSchema, nil } func (p *Pipeline) Validate() error { diff --git a/tooling/templatize/testdata/pipeline.yaml b/tooling/templatize/testdata/pipeline.yaml index f87e53052..6ac26dcbb 100644 --- a/tooling/templatize/testdata/pipeline.yaml +++ b/tooling/templatize/testdata/pipeline.yaml @@ -1,3 +1,4 @@ +$schema: pipeline.schema.v1 serviceGroup: Microsoft.Azure.ARO.Test rolloutName: Test Rollout resourceGroups: diff --git a/tooling/templatize/testdata/zz_fixture_TestRawOptions.yaml b/tooling/templatize/testdata/zz_fixture_TestRawOptions.yaml index 48bd192ec..dbe5f20d8 100644 --- a/tooling/templatize/testdata/zz_fixture_TestRawOptions.yaml +++ b/tooling/templatize/testdata/zz_fixture_TestRawOptions.yaml @@ -1,3 +1,4 @@ +$schema: pipeline.schema.v1 serviceGroup: Microsoft.Azure.ARO.Test rolloutName: Test Rollout resourceGroups: