-
Notifications
You must be signed in to change notification settings - Fork 6
add workflow ID command #215
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
Open
tarcisiozf
wants to merge
7
commits into
main
Choose a base branch
from
DEVSVCS-2981/workflow-id
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ba9f590
squash commits
tarcisiozf 4abf6cf
fix import
tarcisiozf 78f2b84
fix command name
tarcisiozf 1cccfc1
change log level
tarcisiozf 4c23751
change log level
tarcisiozf 09eaf92
change base64 decoding
tarcisiozf b96e6e5
do not require auth for generate-id command
tarcisiozf 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -13,6 +13,8 @@ import ( | |
| "github.com/spf13/viper" | ||
|
|
||
| "github.com/smartcontractkit/cre-cli/cmd/client" | ||
| "github.com/smartcontractkit/cre-cli/internal/artifacts" | ||
| "github.com/smartcontractkit/cre-cli/internal/build" | ||
| "github.com/smartcontractkit/cre-cli/internal/constants" | ||
| "github.com/smartcontractkit/cre-cli/internal/credentials" | ||
| "github.com/smartcontractkit/cre-cli/internal/environments" | ||
|
|
@@ -59,9 +61,11 @@ type handler struct { | |
| stdin io.Reader | ||
| credentials *credentials.Credentials | ||
| environmentSet *environments.EnvironmentSet | ||
| workflowArtifact *workflowArtifact | ||
| workflowArtifact *artifacts.Artifact | ||
| wrc *client.WorkflowRegistryV2Client | ||
| runtimeContext *runtime.Context | ||
| builder *build.Builder | ||
| artifactBuilder *artifacts.Builder | ||
|
|
||
| validated bool | ||
|
|
||
|
|
@@ -73,7 +77,7 @@ type handler struct { | |
| wrcErr error | ||
| } | ||
|
|
||
| var defaultOutputPath = "./binary.wasm.br.b64" | ||
| const defaultOutputPath = "./binary.wasm.br.b64" | ||
|
Contributor
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. As this is now shared we should move it to the constants package: |
||
|
|
||
| func New(runtimeContext *runtime.Context) *cobra.Command { | ||
| var deployCmd = &cobra.Command{ | ||
|
|
@@ -115,7 +119,9 @@ func newHandler(ctx *runtime.Context, stdin io.Reader) *handler { | |
| stdin: stdin, | ||
| credentials: ctx.Credentials, | ||
| environmentSet: ctx.EnvironmentSet, | ||
| workflowArtifact: &workflowArtifact{}, | ||
| workflowArtifact: &artifacts.Artifact{}, | ||
| builder: build.NewBuilder(ctx.Logger), | ||
| artifactBuilder: artifacts.NewBuilder(ctx.Logger), | ||
| wrc: nil, | ||
| runtimeContext: ctx, | ||
| validated: false, | ||
|
|
@@ -180,13 +186,17 @@ func (h *handler) ValidateInputs() error { | |
| func (h *handler) Execute() error { | ||
| h.displayWorkflowDetails() | ||
|
|
||
| if !h.validated { | ||
|
Contributor
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. 👍 |
||
| return errors.New("inputs have not been validated") | ||
| } | ||
|
|
||
| if err := h.Compile(); err != nil { | ||
| return fmt.Errorf("failed to compile workflow: %w", err) | ||
| return err | ||
| } | ||
|
|
||
| if err := h.PrepareWorkflowArtifact(); err != nil { | ||
| return fmt.Errorf("failed to prepare workflow artifact: %w", err) | ||
| } | ||
|
|
||
| h.runtimeContext.Workflow.ID = h.workflowArtifact.WorkflowID | ||
|
|
||
| h.wg.Wait() | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,72 +1,21 @@ | ||
| package deploy | ||
|
|
||
| import ( | ||
| "encoding/base64" | ||
| "fmt" | ||
| "os" | ||
|
|
||
| workflowUtils "github.com/smartcontractkit/chainlink-common/pkg/workflows" | ||
| "github.com/smartcontractkit/cre-cli/internal/artifacts" | ||
| ) | ||
|
|
||
| type workflowArtifact struct { | ||
| BinaryData []byte | ||
| ConfigData []byte | ||
| WorkflowID string | ||
| } | ||
|
|
||
| func (h *handler) prepareWorkflowBinary() ([]byte, error) { | ||
| h.log.Debug().Str("Binary Path", h.inputs.OutputPath).Msg("Fetching workflow binary") | ||
| binaryData, err := os.ReadFile(h.inputs.OutputPath) | ||
| if err != nil { | ||
| h.log.Error().Err(err).Str("path", h.inputs.OutputPath).Msg("Failed to read output file") | ||
| return nil, err | ||
| } | ||
| h.log.Debug().Msg("Workflow binary WASM is ready") | ||
| return binaryData, nil | ||
| } | ||
|
|
||
| func (h *handler) prepareWorkflowConfig() ([]byte, error) { | ||
| h.log.Debug().Str("Config Path", h.inputs.ConfigPath).Msg("Fetching workflow config") | ||
| var configData []byte | ||
| var err error | ||
| if h.inputs.ConfigPath != "" { | ||
| configData, err = os.ReadFile(h.inputs.ConfigPath) | ||
| if err != nil { | ||
| h.log.Error().Err(err).Str("path", h.inputs.ConfigPath).Msg("Failed to read config file") | ||
| return nil, err | ||
| } | ||
| } | ||
| h.log.Debug().Msg("Workflow config is ready") | ||
| return configData, nil | ||
| } | ||
|
|
||
| func (h *handler) PrepareWorkflowArtifact() error { | ||
| var err error | ||
| binaryData, err := h.prepareWorkflowBinary() | ||
| func (h *handler) PrepareWorkflowArtifact() (err error) { | ||
| h.workflowArtifact, err = h.artifactBuilder.Build(artifacts.Inputs{ | ||
| WorkflowOwner: h.inputs.WorkflowOwner, | ||
| WorkflowName: h.inputs.WorkflowName, | ||
| OutputPath: h.inputs.OutputPath, | ||
| ConfigPath: h.inputs.ConfigPath, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| configData, err := h.prepareWorkflowConfig() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Note: the binary data read from file is base64 encoded, so we need to decode it before generating the workflow ID. | ||
| // This matches the behavior in the Chainlink node. Ref https://github.com/smartcontractkit/chainlink/blob/a4adc900d98d4e6eec0a6f80fcf86d883a8f1e3c/core/services/workflows/artifacts/v2/store.go#L211-L213 | ||
| binaryDataDecoded, err := base64.StdEncoding.DecodeString(string(binaryData)) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to decode base64 binary data: %w", err) | ||
| } | ||
|
|
||
| workflowID, err := workflowUtils.GenerateWorkflowIDFromStrings(h.inputs.WorkflowOwner, h.inputs.WorkflowName, binaryDataDecoded, configData, "") | ||
| if err != nil { | ||
| return fmt.Errorf("failed to generate workflow ID: %w", err) | ||
| } | ||
|
|
||
| h.workflowArtifact.BinaryData = binaryData | ||
| h.workflowArtifact.ConfigData = configData | ||
| h.workflowArtifact.WorkflowID = workflowID | ||
| h.log.Debug().Str("workflowID", h.workflowArtifact.WorkflowID).Msg("Prepared workflow artifact") | ||
|
|
||
| return nil | ||
| } |
Oops, something went wrong.
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.
This should be removed. We want to enforce auth validation
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.
Discussed offline and it was decided to keep as is without validating auth