-
Notifications
You must be signed in to change notification settings - Fork 429
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
feat(ui,api): ascode action form & analysis #6513
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7391c61
feat: wip action form
sguiheux 4eb15c6
fix: forget file
sguiheux 280d422
feat(ui): manage array jsonschema form generation
sguiheux d3d6e26
feat: add map
sguiheux 736cc53
fix: remove console.log
sguiheux 0534360
feat: add pattern
sguiheux b686675
Merge branch 'master' into actionAsCodeForm2
sguiheux 3f3e28a
feat: add pattern on step id and input/output keys
sguiheux 259796b
Merge branch 'master' into actionAsCodeForm2
sguiheux 8fc412a
feat: add enum
sguiheux 6f33da8
feat: add with and load
sguiheux fd65ddd
Merge branch 'master' into actionAsCodeForm2
sguiheux c15a033
feat: manage step uses with
sguiheux 1e194c4
fix(api): error
sguiheux 6b92fba
feat: add test to analyse an action
sguiheux 3bfbd21
fix: add manage-action permission
sguiheux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package sdk | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/xeipuuv/gojsonschema" | ||
) | ||
|
||
const ( | ||
EntityActionInputKey = "^[a-zA-Z]{1,}$" | ||
EntityActionStepID = "^[a-zA-Z]{0,}$" | ||
) | ||
|
||
type V2Action struct { | ||
Name string `json:"name" jsonschema_extras:"order=1" jsonschema_description:"Name of the action"` | ||
Description string `json:"description,omitempty" jsonschema_extras:"order=2"` | ||
Inputs map[string]ActionInput `json:"inputs,omitempty" jsonschema_extras:"order=3,mode=edit" jsonschema_description:"Inputs of the action"` | ||
Outputs map[string]ActionOutput `json:"outputs,omitempty" jsonschema_extras:"order=4,mode=edit" jsonschema_description:"Outputs compute by the action"` | ||
Runs ActionRuns `json:"runs" jsonschema_extras:"order=5"` | ||
} | ||
|
||
type ActionRuns struct { | ||
Steps []ActionStep `json:"steps" jsonschema_description:"List of sequential steps executed by the action"` | ||
} | ||
|
||
type ActionInput struct { | ||
Description string `json:"description,omitempty" jsonschema_extras:"order=2"` | ||
Default string `json:"default,omitempty" jsonschema_extras:"order=1" jsonschema_description:"Default input value used if the caller do not specified anything"` | ||
} | ||
|
||
type ActionOutput struct { | ||
Description string `json:"description,omitempty" jsonschema_extras:"order=2"` | ||
Value string `json:"value" jsonschema_extras:"order=1"` | ||
} | ||
|
||
type ActionStep struct { | ||
ID string `json:"id,omitempty" jsonschema_extras:"order=2" jsonschema_description:"Identifier of the step"` | ||
Uses string `json:"uses,omitempty" jsonschema:"oneof_required=uses" jsonschema_extras:"order=1,onchange=loadentity" jsonschema_description:"Sub action to call"` | ||
Run string `json:"run,omitempty" jsonschema:"oneof_required=run" jsonschema_extras:"order=1" jsonschema_description:"Script to execute"` | ||
With map[string]string `json:"with,omitempty" jsonschema:"oneof_not_required=run" jsonschema_extras:"order=3,mode=use" jsonschema_description:"Action parameters"` | ||
} | ||
|
||
type ActionStepUsesWith map[string]string | ||
|
||
func (a V2Action) GetName() string { | ||
return a.Name | ||
} | ||
|
||
func (a V2Action) Lint() []error { | ||
actionSchema := GetActionJsonSchema(nil) | ||
actionSchemaS, err := actionSchema.MarshalJSON() | ||
if err != nil { | ||
return []error{NewErrorFrom(err, "unable to load action schema")} | ||
} | ||
schemaLoader := gojsonschema.NewStringLoader(string(actionSchemaS)) | ||
|
||
modelJson, err := json.Marshal(a) | ||
if err != nil { | ||
return []error{NewErrorFrom(err, "unable to marshal action")} | ||
} | ||
documentLoader := gojsonschema.NewStringLoader(string(modelJson)) | ||
|
||
result, err := gojsonschema.Validate(schemaLoader, documentLoader) | ||
if err != nil { | ||
return []error{NewErrorFrom(err, "unable to validate action")} | ||
} | ||
if result.Valid() { | ||
return nil | ||
} | ||
|
||
errors := make([]error, 0, len(result.Errors())) | ||
for _, e := range result.Errors() { | ||
errors = append(errors, NewErrorFrom(ErrInvalidData, e.String())) | ||
} | ||
return errors | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: test-action | ||
author: cds_team | ||
description: simple test action as code | ||
inputs: | ||
name: | ||
description: name of the person to greet | ||
required: true | ||
default: Steven | ||
outputs: | ||
name: | ||
description: name of the person who was greeted | ||
value: ${{ steps.hello.outputs.person }} | ||
runs: | ||
steps: | ||
- run: echo Welcome in nthis new action | ||
- id: hello | ||
run: echo Hello ${{ inputs.name }} | ||
- run: echo "name=${{ inputs.name }}" >> $CDS_OUTPUT | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any tests with |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need unit test on Lint() ?