Skip to content

Commit

Permalink
feat: Support archive folders (#895)
Browse files Browse the repository at this point in the history
* feat: Support archive folders

* refine JSON schema for SO

* add validation

* check absolute path

* auto convert backslashes
  • Loading branch information
tianfeng92 authored Mar 22, 2024
1 parent b79d820 commit fde9414
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 12 deletions.
59 changes: 54 additions & 5 deletions api/saucectl.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@
"directory"
],
"additionalProperties": false
},
"retain": {
"description": "Compress folders into zip files, which can then be downloaded as artifacts.",
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"additionalProperties": false
Expand Down Expand Up @@ -567,6 +574,13 @@
"directory"
],
"additionalProperties": false
},
"retain": {
"description": "Compress folders into zip files, which can then be downloaded as artifacts.",
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"additionalProperties": false
Expand Down Expand Up @@ -2651,11 +2665,6 @@
"title": "saucectl image runner configuration",
"description": "Configuration file for running container images using saucectl",
"type": "object",
"allOf": [
{
"$ref": "#/allOf/0/then/allOf/0"
}
],
"definitions": {
"sauce": {
"description": "All settings related to how tests are run and identified in the Sauce Labs platform.",
Expand Down Expand Up @@ -2878,6 +2887,46 @@
},
"additionalProperties": false
}
},
"artifacts": {
"description": "Manage test output, such as logs, videos, and screenshots.",
"type": "object",
"properties": {
"cleanup": {
"description": "Whether to remove all contents of artifacts directory",
"type": "boolean"
},
"download": {
"description": "Settings related to downloading test artifacts from Sauce Labs.",
"type": "object",
"properties": {
"match": {
"description": "Specifies which artifacts to download based on whether they match the file pattern provided. Supports the wildcard character '*'.",
"type": "array"
},
"when": {
"description": "Specifies when and under what circumstances to download artifacts.",
"enum": [
"always",
"fail",
"never",
"pass"
]
},
"directory": {
"description": "Specifies the path to the folder in which to download artifacts. A separate subdirectory is generated in this location for each suite.",
"type": "string"
}
},
"required": [
"when",
"match",
"directory"
],
"additionalProperties": false
},
"additionalProperties": false
}
}
},
"properties": {
Expand Down
7 changes: 7 additions & 0 deletions api/v1/subschema/artifacts.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
"directory"
],
"additionalProperties": false
},
"retain": {
"description": "Compress folders into zip files, which can then be downloaded as artifacts.",
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"additionalProperties": false
Expand Down
45 changes: 40 additions & 5 deletions api/v1alpha/framework/imagerunner.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
"title": "saucectl image runner configuration",
"description": "Configuration file for running container images using saucectl",
"type": "object",
"allOf": [
{
"$ref": "../subschema/artifacts.schema.json"
}
],
"definitions": {
"sauce": {
"description": "All settings related to how tests are run and identified in the Sauce Labs platform.",
Expand Down Expand Up @@ -223,6 +218,46 @@
},
"additionalProperties": false
}
},
"artifacts": {
"description": "Manage test output, such as logs, videos, and screenshots.",
"type": "object",
"properties": {
"cleanup": {
"description": "Whether to remove all contents of artifacts directory",
"type": "boolean"
},
"download": {
"description": "Settings related to downloading test artifacts from Sauce Labs.",
"type": "object",
"properties": {
"match": {
"description": "Specifies which artifacts to download based on whether they match the file pattern provided. Supports the wildcard character '*'.",
"type": "array"
},
"when": {
"description": "Specifies when and under what circumstances to download artifacts.",
"enum": [
"always",
"fail",
"never",
"pass"
]
},
"directory": {
"description": "Specifies the path to the folder in which to download artifacts. A separate subdirectory is generated in this location for each suite.",
"type": "string"
}
},
"required": [
"when",
"match",
"directory"
],
"additionalProperties": false
},
"additionalProperties": false
}
}
},
"properties": {
Expand Down
7 changes: 7 additions & 0 deletions api/v1alpha/subschema/artifacts.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
"directory"
],
"additionalProperties": false
},
"retain": {
"description": "Compress folders into zip files, which can then be downloaded as artifacts.",
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"additionalProperties": false
Expand Down
24 changes: 22 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ type Slack struct {

// Artifacts represents the test artifacts configuration.
type Artifacts struct {
Download ArtifactDownload `yaml:"download,omitempty" json:"download"`
Cleanup bool `yaml:"cleanup,omitempty" json:"cleanup"`
Retain map[string]string `yaml:"retain,omitempty" json:"retain"`
Download ArtifactDownload `yaml:"download,omitempty" json:"download"`
Cleanup bool `yaml:"cleanup,omitempty" json:"cleanup"`
}

// Reporters represents the reporter configuration.
Expand Down Expand Up @@ -606,3 +607,22 @@ func ValidateRegistries(registries []Registry) error {
}
return nil
}

func ValidateArtifacts(artifacts Artifacts) error {
for source, dest := range artifacts.Retain {
if filepath.IsAbs(source) {
return fmt.Errorf("invalid source path %q: absolute path is not allowed", source)
}
if !strings.HasSuffix(dest, ".zip") {
return fmt.Errorf("invalid zip filename %q: only .zip file is permitted", dest)
}

// Automatically convert the path to use slashes.
newSource := strings.ReplaceAll(source, "\\", "/")
if newSource != source {
artifacts.Retain[newSource] = dest
delete(artifacts.Retain, source)
}
}
return nil
}
3 changes: 3 additions & 0 deletions internal/cucumber/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ func Validate(p *Project) error {
if err != nil {
return err
}
if err := config.ValidateArtifacts(p.Artifacts); err != nil {
return err
}

p.Playwright.Version = config.StandardizeVersionFormat(p.Playwright.Version)
if p.Playwright.Version == "" {
Expand Down
3 changes: 3 additions & 0 deletions internal/cypress/v1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ func (p *Project) Validate() error {
if err != nil {
return err
}
if err := config.ValidateArtifacts(p.Artifacts); err != nil {
return err
}

if p.Sauce.LaunchOrder != "" && p.Sauce.LaunchOrder != config.LaunchOrderFailRate {
return fmt.Errorf(msg.InvalidLaunchingOption, p.Sauce.LaunchOrder, string(config.LaunchOrderFailRate))
Expand Down
4 changes: 4 additions & 0 deletions internal/playwright/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ func Validate(p *Project) error {
return err
}

if err := config.ValidateArtifacts(p.Artifacts); err != nil {
return err
}

if p.Sauce.LaunchOrder != "" && p.Sauce.LaunchOrder != config.LaunchOrderFailRate {
return fmt.Errorf(msg.InvalidLaunchingOption, p.Sauce.LaunchOrder, string(config.LaunchOrderFailRate))
}
Expand Down
4 changes: 4 additions & 0 deletions internal/testcafe/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ func Validate(p *Project) error {
return err
}

if err := config.ValidateArtifacts(p.Artifacts); err != nil {
return err
}

p.Testcafe.Version = config.StandardizeVersionFormat(p.Testcafe.Version)
if p.Testcafe.Version == "" {
return errors.New(msg.MissingFrameworkVersionConfig)
Expand Down

0 comments on commit fde9414

Please sign in to comment.