Skip to content
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

[TT-1981] use chainlink cli in the keystone smoke test #16146

Merged
merged 87 commits into from
Feb 3, 2025

Conversation

Tofel
Copy link
Contributor

@Tofel Tofel commented Jan 30, 2025

disclaimer: idk why we see such a long commit history, it's completely out of whack. This PR adds but 4-5 new commits.

changes:

  • use chainlink-cli by default in the CI
  • call chainlink-cli using it's absolute path
  • detect os/arch before downloading chainlink-cli (it executes on host machine, so we need to support darwin/arm64 for local execution and linux/amd64 for the CI)
  • make chainlink-cli and capabilities version to use a configurable setting

lukaszcl
lukaszcl previously approved these changes Jan 31, 2025
@Tofel Tofel enabled auto-merge January 31, 2025 15:36
@@ -44,6 +44,13 @@ The test requires several environment variables. Below is a launch configuration
- **`GITHUB_READ_TOKEN`**: Required for downloading the `cron` capability binary and `chainlink-cli` (if enabled). Requires `content:read` permission for `smartcontractkit/capabilities` and `smartcontractkit/dev-platform` repositories. Use a fine-grained personal access token (PAT) tied to the **organization’s GitHub account**.
- **`GIST_WRITE_TOKEN`**: Required only for compiling and uploading a new workflow. It needs `gist:read:write` permissions and should be a fine-grained PAT **tied to your personal GitHub account**.

Test also expects you to have the Job Distributor image available locally. By default, `environment.toml` expectes image tagged as `jd-test-1:latest`. The easiest way to get it, is to clone the Job Distributor repository and build it locally with:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit/ typo expectes -> expects

&oauth2.Token{AccessToken: ghToken},
)
tc := oauth2.NewClient(ctx, ts)
ctx := context.Background()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should there be some reasonable timeout? a few minutes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, yes

if err != nil {
return content, errors.Wrapf(err, "failed to list releases for %s", repository)
}
ghReleases, _, err := ghClient.Repositories.ListReleases(context.Background(), owner, repository, &github.ListOptions{PerPage: 20})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use ctx var

}
asset, _, err := ghClient.Repositories.DownloadReleaseAsset(context.Background(), owner, repository, assetID, tc)
if err != nil {
return content, errors.Wrapf(err, "failed to download asset %s for %s", assetName, *ghRelease.TagName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pkg/errors is depreciated

use fmt.Errorf("this is a wrapped error: %w", err)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but we keep using it as there's no good replacement. fmt.Errorf doesn't give you the stacktrace.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm. ok.

we should need the stack trace if the error wrapping is done well

we probably do return err in too many places and lose the meaning of the err along the way

if err != nil {
return err
return errors.Wrapf(err, "failed to download chainlink-cli asset %s", chainlinkCliAssetFile)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'%w'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only if we go with fmt.Errof, which I'd rather avoid.


cmd := exec.Command("tar", "-xvf", tmpfile.Name(), "-C", ".") // #nosec G204
if cmd.Run() != nil {
return errors.Wrapf(err, "failed to extract chainlink-cli asset %s", chainlinkCliAssetFile)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

extractedFileName := fmt.Sprintf("cre_%s_%s_%s", version, system, arch)
cmd = exec.Command("chmod", "+x", extractedFileName)
if cmd.Run() != nil {
return errors.Wrapf(err, "failed to make %s executable", extractedFileName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

if err != nil {
return err
return errors.Wrapf(err, "failed to open %s", extractedFileName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

if err != nil {
return err
return errors.Wrapf(err, "failed to get absolute path for %s", tmpfile.Name())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@@ -712,7 +748,7 @@ func compileWorkflowWithChainlinkCli(t *testing.T, in *WorkflowTestConfig, feeds

var outputBuffer bytes.Buffer

compileCmd := exec.Command("chainlink-cli", "workflow", "compile", "-S", settingsFile.Name(), "-c", configFile.Name(), "main.go") // #nosec G204
compileCmd := exec.Command(chainlinkCliCommand, "workflow", "compile", "-S", settingsFile.Name(), "-c", configFile.Name(), "main.go") // #nosec G204
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this work from all current working dirs? hardcoded "main.go" looks suspicious

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't run in current working directory, but in:

compileCmd.Dir = *in.WorkflowConfig.ChainlinkCLI.FolderLocation

main.go is hardcoded, because that's the has been the typical name of entry workflow file so far. Also, chainlink-cli expects you to have go.mod in the workflow folder, which won't allow you to compile workflow that resides in a package different than main. I'll add a comment.

@cl-sonarqube-production
Copy link

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

@Tofel Tofel added this pull request to the merge queue Feb 3, 2025
Merged via the queue into develop with commit 4052d7a Feb 3, 2025
184 checks passed
@Tofel Tofel deleted the tt-1981-use-chainlink-cli branch February 3, 2025 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants