artifacts

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 17 Imported by: 0

README

CRE Workflow Artifacts

Common abstraction for managing CRE Workflow Artifacts for different services/clients including CRE-CLI to

  • Compile WASM workflows: For Typescript and Go CRE workflows
  • Upload artifacts like workflow binaries and configs to storage service

Testing

$ cd /path/to/chainlink-common/pkg/workflows/artifacts/
$ go test -v -count=1 ./

Testdata management

To get the exact CRE-CLI workflow wasm binary data and its hash for testing comparison.

  • Add a project.yaml to ./pkg/workflows/artifacts/project.yaml
local-simulation:
  rpcs:
    - chain-name: ethereum-testnet-sepolia
      url: <ETH_SEPOLIA_RPC_URL>
staging:
  cre-cli:
    don-family: "<DON_FAMILY>"
  rpcs:
    - chain-name: ethereum-testnet-sepolia
      url: <ETH_SEPOLIA_RPC_URL>
  • Add a workflow.yaml to ./pkg/workflows/artifacts/testdata/workflow.yaml
local-simulation:
  user-workflow:
    workflow-name: "wf-test-1"
  workflow-artifacts:
    workflow-path: "./"
    config-path: ""
staging:
  user-workflow:
    workflow-name: "wf-test-1"
  workflow-artifacts:
    workflow-path: "./"
    config-path: ""
  • Then run cre workflow deploy to compile workflow wasm binary from testdata folder to get the exact base64 encoded brotli compressed wasm binary
$ cre login
$ cd /path/to/chainlink-common/pkg/workflows/artifacts/
$ cre workflow deploy ./testdata
$ cat testdata/binary.wasm.br.b64 | cast keccak256

Documentation

Index

Constants

View Source
const (
	WorkflowLanguageGolang     = "golang"
	WorkflowLanguageTypeScript = "typescript"
)

Variables

This section is empty.

Functions

func CalculateContentHash

func CalculateContentHash(content []byte) string

Calculate the content hash of the artifact to generate the presigned URL for the artifact in the storage service

func EnsureTool

func EnsureTool(bin string) error

EnsureTool checks that the binary exists on PATH

func GetBuildCmd

func GetBuildCmd(inputFile string, outputFile string, rootFolder string) *exec.Cmd

Gets a build command for either Golang or Typescript based on the filename

func GetWorkflowLanguage

func GetWorkflowLanguage(inputFile string) string

GetWorkflowLanguage determines the workflow language based on the file extension Note: inputFile can be a file path (e.g., "main.ts" or "main.go") or a directory (for Go workflows, e.g., ".") Returns constants.WorkflowLanguageTypeScript for .ts or .tsx files, constants.WorkflowLanguageGolang otherwise

func IsBinaryFile

func IsBinaryFile(fileName string) (bool, error)

There is only a small group of acceptable file extensions by this tool and only few of them are considered to be binary files

func ScanFilesForContent

func ScanFilesForContent(dirPath string) (string, error)

ScanFilesForContent scans all files in the specified directory (non-recursive) and returns the name of the first file whose content contains all the specified substrings. Returns an error if no file matches all substrings or if there's an error reading the directory.

Types

type ArtifactType

type ArtifactType string
const (
	ArtifactTypeBinary ArtifactType = "BINARY"
	ArtifactTypeConfig ArtifactType = "CONFIG"
)

type ArtifactUpload

type ArtifactUpload struct {
	Content     []byte
	ContentType ArtifactType
	ContentHash string
}

Read in an artifact file from a given filepath and calculate the content hash

func NewArtifactUpload

func NewArtifactUpload(filepath string, contentType ArtifactType) (*ArtifactUpload, error)

Constructor for ArtifactUpload

type Artifacts

type Artifacts struct {
	// contains filtered or unexported fields
}

func NewWorkflowArtifacts

func NewWorkflowArtifacts(
	input *Input,
	lggr *slog.Logger,
) *Artifacts

Constructor for WorkflowArtifacts

func (*Artifacts) Compile

func (a *Artifacts) Compile() error

Function to compile CRE workflow into a WASM binary, brotli compress it and base64 encode it Input.WorkflowPath is the path to the workflow directory or file. If it's a directory, it will be scanned for a main workflow file either in .go or .ts/.tsx files for CRE Workflow Runner execution.

func (*Artifacts) DurableUpload

func (a *Artifacts) DurableUpload(uploadInput *UploadInput) error

DurableUpload uploads an artifact with up to 3 attempts and exponential backoff.

func (*Artifacts) GetBinaryData

func (a *Artifacts) GetBinaryData() []byte

Returns the binary data after preparing the artifacts This value is empty until Prepare() is called

func (*Artifacts) GetBinaryPath

func (a *Artifacts) GetBinaryPath() string

Returns the binary path after preparing the artifacts This value is empty until Prepare() is called

func (*Artifacts) GetConfigData

func (a *Artifacts) GetConfigData() []byte

Returns the config data after preparing the artifacts This value is empty until Prepare() is called

func (*Artifacts) GetWorkflowID

func (a *Artifacts) GetWorkflowID() string

Returns the generated workflow ID after preparing the artifacts This value is empty until Prepare() is called

func (*Artifacts) GetWorkflowMainFile

func (a *Artifacts) GetWorkflowMainFile(workflowPath string) (string, error)

Get the path to main workflow file for a Go workflow

func (*Artifacts) Prepare

func (a *Artifacts) Prepare() error

Prepares the workflow artifacts for workflow deployment

type Field

type Field struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type Input

type Input struct {
	WorkflowOwner string
	WorkflowName  string
	WorkflowPath  string
	ConfigPath    string
	BinaryPath    string
}

type UploadInput

type UploadInput struct {
	PresignedURL    string        `json:"presignedUrl"`
	PresignedFields []Field       `json:"presignedFields"`
	ContentType     ArtifactType  `json:"contentType"`
	Filepath        string        `json:"-"`
	Timeout         time.Duration `json:"-"`
}

Input for uploading artifacts to storage service using presigned URLs

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL