Skip to content

Commit 6b12cba

Browse files
Dynamic template fetching from GitHub repos (#279)
* test charm lib impelentation for cre init * Add shared UI package with Charm ecosystem for styled CLI output - Create internal/ui/ package with centralized Lipgloss styles (styles.go) - Add output helpers for consistent styling: Title, Box, Success, Dim, etc. - Implement Bubble Tea spinner with reference counting for async operations - Add GlobalSpinner singleton for seamless spinner across CLI lifecycle - Update PersistentPreRunE to show spinner during initialization - Migrate cre init and cre whoami to use shared UI package * Add spinner to cre init and fix layout issues - Add spinner during file generation (copying, generating templates, contracts) - Show spinner during Go dependencies installation - Display dependencies in styled box after spinner completes - Fix Next steps box spacing and formatting - Refactor initializeGoModule to return deps instead of printing * Style help page with Lipgloss - Add styled template functions (styleTitle, styleSection, styleCommand, styleDim, styleSuccess, styleCode) - Update help template to use Lipgloss styling - Style section headers, command names, tips, and URLs - Improve visual hierarchy and readability * Apply Chainlink Blocks color palette to CLI - Add complete Blocks palette constants (Gray, Blue, Green, Red, Orange, Yellow, Teal, Purple) - Use high-contrast colors for dark terminal readability - Style titles/commands with Blue 400-500 for visibility - Style secondary info with Gray 500 (dimmed) - Create custom Huh theme with Blocks colors for forms - Update spinner to use Blue 500 * Modernize cre login command with Charm UI components - Add styled title and welcome message using Chainlink theme - Add Bubble Tea spinner with progress states throughout auth flow: - Preparing authentication - Opening browser - Waiting for authentication - Exchanging authorization code - Saving credentials - Show styled URL fallback when browser cannot open automatically - Display success message with next steps in branded box - Update spinner message during org membership retry flow - Update tests to include spinner in handler instantiations * Add styled error display for CLI using ui.Error() - Add SilenceErrors: true to root command to disable Cobra's default error output - Display all user-facing errors with styled ui.Error() in Execute() - Errors now show with red color and ✗ prefix consistent with Chainlink theme - Internal debug logging via zerolog remains unchanged * Improve CLI error display with styled output and smart usage handling - Add SilenceErrors: true to disable Cobra's default error output - Display errors with styled ui.Error() (red with ✗ prefix) - Set SilenceUsage in PersistentPreRunE to hide usage for runtime errors - Keep usage/suggestions visible for command typos and flag errors * Add login prompt when authentication is required * Fix tests broken by Charm UI changes * Fix cre logout to skip credential check and handle nil credentials * Modernize cre version command with Charm UI styling * Modernize cre update command with progress bar and Charm UI * Fix creinit tests to provide all inputs via flags * Update the list-key command to use the shared Charm UI components for consistent styling across the CLI * Update test assertions for Charm UI output changes * Update the generate-bindings command to use the shared Charm UI * Update the secrets list command to use the shared Charm UI component * Update the secrets delete command to use the shared Charm UI components * Modernize workflow pause, activate, delete with Charm UI * updated styling for workflow deploy, pause, delete and transaction * mondernized link and unlink command using charm lib * updated missing charm console output in creinit.go * fixed build output ui * updated fmt.print with new ui that were not replaced * mondernized simulate command with charm ui output * 1. Updated internal/settings/settings_generate.go: - Replaced prompt.YesNoPrompt with huh.NewConfirm forms - Removed stdin io.Reader parameter 2. Updated cmd/creinit/creinit.go: - Updated call sites to match new function signatures 3. Updated cmd/secrets/common/handler.go: - Replaced ~25 fmt.Print* calls with ui.* functions 4. Updated cmd/workflow/simulate/telemetry_writer.go: - Replaced fmt.Printf with ui.Printf - Removed unused fmt import 5. Deleted internal/prompt/ directory: - Removed entire old promptui-based package 6. Cleaned cmd/common/utils.go: - Removed unused MustGetUserInputWithPrompt function - Removed unused bufio and errors imports 7. Dependencies cleaned (go mod tidy): - Removed github.com/manifoldco/promptui - Removed github.com/chzyer/readline * improved prompt behavior with autocomplete and default value * added error helpers * improved login command with cancellation / escape * fixed logout issue that was not flushing credentials * updated login to remove the esc logic * updated secret tests that were failing * fixed lint error: unused functions and returns * Refactored credentials.go for deploy access status and added deploy access display to cre whoami command * Updated gated message with the command to request access * added new account access command * added account access command to settings exclusion * access command logic to submit form to zendesk * added prompt to request access when running cre account access cmd * Refactor access request logic into shared package and add deploy access check to workflow deploy command * Fix background goroutine error appearing during deploy access prompt * Update account command description to mention deploy access * Show deploy access hint after successful workflow simulation * Add deploy access hint to global help template for gated users * Added prompt to describe use cases when request access request * update code so that request is sent to a proxy that will take care of submitting the request to zendesk * updated deploy request changes to be compatible with new charm lib refactor * updated simulator deploy message to use box layout * Yes is now selected by default for cre deploy access request prompt * updated creinit to use bubbletea wizard * fixed linter issues * fixed weird spacing in creinit.go * cre init: wizard now display files created in <workflow directory> and - Contracts generated in <contracts directory> * restored original comments in creinit.go * fixed update cmd progress indicator issue * Temp mock access request behavior before API implementation * Added ascii logo in creinit wizard * Spinner do not display in verbose mode to avoid stdout and stderr conflict and visual display issue in verbose mode * replaced temp REST HTTP client with GraphQL client * added tests for access cmd * Replace embedded templates with dynamic GitHub-based template fetching Templates are now discovered and downloaded from GitHub repositories at runtime instead of being embedded in the CLI binary via go:embed. This enables template updates without CLI releases and supports multiple template sources. New packages: - internal/templaterepo/ - GitHub API client, file cache, and registry for discovering, caching, and scaffolding templates - internal/config/ - CLI config (~/.cre/config.yaml) for template repository sources with env var and flag overrides Changes: - cmd/creinit: rewritten to use registry-based template fetching with RegistryInterface for testability. Wizard simplified to 3 steps (project name, template selection, workflow name) - cmd/creinit/template/workflow/ removed (all embedded templates) - cmd/creinit/go_module_init.go removed (templates are self-contained) - SDK version constants moved to internal/constants/ - cmd/generate-bindings updated to import from constants package - E2E tests updated: --template-id flag replaced with --template using template name strings (kv-store-go, cre-custom-data-feed-go, etc.) Template sources configurable via: - --template-repo flag - CRE_TEMPLATE_REPOS env var - ~/.cre/config.yaml - Default: smartcontractkit/cre-templates@main * fix & log for extracing templates * Built-in hello-world template — always available, even offline: - internal/templaterepo/builtin/hello-world-go/ — embedded files (main.go, workflow.yaml, README.md, configs, secrets.yaml) - internal/templaterepo/builtin.go — //go:embed, BuiltInTemplate var, ScaffoldBuiltIn() function - TemplateSummary.BuiltIn bool field to distinguish embedded vs remote - ListTemplates() always prepends the built-in template (no network needed) - ScaffoldTemplate() uses ScaffoldBuiltIn() for built-in templates instead of downloading * Remove template-repo flag from cre init, added template-id as a deprecated flag for backward compatibility * Added back builtin TS hello world template, updated template-id behavior * Added networks field to template metadata (internal/templaterepo/types.go) — An optional []string of chain names in template.yaml. Dynamic project.yaml RPC generation (internal/settings/): - project.yaml.tpl now uses a {{RPCsList}} placeholder instead of hardcoded chains - BuildRPCsListYAML() generates the rpcs YAML block from networks + URLs - Falls back to ethereum-testnet-sepolia with default public RPC when no networks specified New wizard step (cmd/creinit/wizard.go): - stepNetworkRPCs between template selection and workflow name - Prompts for each network's RPC URL sequentially - Empty input accepted (fill later), non-empty input validated as valid HTTP/HTTPS URL - Step is skipped if template has no networks or all RPCs provided via flags --rpc-url flag (cmd/creinit/creinit.go): - Repeatable StringArray flag: --rpc-url chain-name=url - Parsed in ResolveInputs(), merged with wizard results in Execute() - Flag values override wizard input * Patch RPC when template arleady have rpc configured in project.yaml * Fixed go init for default embed template * Fixed TS template default template (same as main branch now) * Updated init wizard for better layout * Add multi-workflow support and preserve template-shipped workflow.yaml - Add WorkflowDirEntry struct and Workflows/PostInit fields to TemplateMetadata in types.go - Rewrite renameWorkflowDir in registry.go to branch on workflow count: skip renaming for multi-workflow, rename single workflow, heuristic fallback for legacy - Update wizard to skip workflow name prompt for multi-workflow templates and default placeholder from Workflows[0].Dir - Default workflowName from Workflows[0].Dir in non-interactive mode - Loop GenerateWorkflowSettingsFile for each declared workflow dir in multi-workflow templates - Skip workflow.yaml generation when template already ships one (prevents overwriting custom config paths) - Rewrite printSuccessMessage to show per-workflow summary and postInit instructions - Add 6 new test cases covering multi-workflow, single-workflow defaults, rename with flag, and built-in backwards compat * added in wizard check for cre init - folder and rpc url * updated cre init list layout * cre init search wizard stay displayed * updated template.yaml local to .cre/template.yaml * added a flag to pass new repository url, made ~/.cre/template.yaml source of truth for template source * Root-level template repo extraction fix * added cre templates list/add/remove to manage repo sources * template.yaml now has projectDir to specify the cre project dir, updated copy logic * Added prediction market repo as default * fix go mod tidy for dynamic template in go * fix linter * cre init create .env file if not present * updated default template source repo to main * handle error for relative path in builtin.go * Sanitize template repo external values * prevent zip slip * Fixed setAuthHeader for fetching template metadata * gendoc * Fix dir rename that was failing tests * Updated tests now that templates are dynamic * Fix linter issues * fixed linter * Fix deprecated template id * Fix zip slip warning * Fix zip slip * updated tests * Fixed linter and go mod tidy * Add tracking to template id when using cre init (#284) * Always track flag --template even when not provided * linter fixes * fix path extraction on windows --------- Co-authored-by: Tarcísio Zotelli Ferraz <tar-2008.ferraz@hotmail.com>
1 parent 72002a3 commit 6b12cba

111 files changed

Lines changed: 4262 additions & 6081 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/creinit/creinit.go

Lines changed: 295 additions & 445 deletions
Large diffs are not rendered by default.

cmd/creinit/creinit_test.go

Lines changed: 567 additions & 194 deletions
Large diffs are not rendered by default.

cmd/creinit/go_module_init.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@ import (
77
"path/filepath"
88

99
"github.com/rs/zerolog"
10-
)
1110

12-
const (
13-
SdkVersion = "v1.2.0"
14-
EVMCapabilitiesVersion = "v1.0.0-beta.5"
15-
HTTPCapabilitiesVersion = "v1.0.0-beta.0"
16-
CronCapabilitiesVersion = "v1.0.0-beta.0"
11+
"github.com/smartcontractkit/cre-cli/internal/constants"
1712
)
1813

1914
// InstalledDependencies contains info about installed Go dependencies
@@ -26,10 +21,10 @@ func initializeGoModule(logger *zerolog.Logger, workingDirectory, moduleName str
2621
result := &InstalledDependencies{
2722
ModuleName: moduleName,
2823
Deps: []string{
29-
"cre-sdk-go@" + SdkVersion,
30-
"capabilities/blockchain/evm@" + EVMCapabilitiesVersion,
31-
"capabilities/networking/http@" + HTTPCapabilitiesVersion,
32-
"capabilities/scheduler/cron@" + CronCapabilitiesVersion,
24+
"cre-sdk-go@" + constants.SdkVersion,
25+
"capabilities/blockchain/evm@" + constants.EVMCapabilitiesVersion,
26+
"capabilities/networking/http@" + constants.HTTPCapabilitiesVersion,
27+
"capabilities/scheduler/cron@" + constants.CronCapabilitiesVersion,
3328
},
3429
}
3530

@@ -40,16 +35,16 @@ func initializeGoModule(logger *zerolog.Logger, workingDirectory, moduleName str
4035
}
4136
}
4237

43-
if err := runCommand(logger, workingDirectory, "go", "get", "github.com/smartcontractkit/cre-sdk-go@"+SdkVersion); err != nil {
38+
if err := runCommand(logger, workingDirectory, "go", "get", "github.com/smartcontractkit/cre-sdk-go@"+constants.SdkVersion); err != nil {
4439
return nil, err
4540
}
46-
if err := runCommand(logger, workingDirectory, "go", "get", "github.com/smartcontractkit/cre-sdk-go/capabilities/blockchain/evm@"+EVMCapabilitiesVersion); err != nil {
41+
if err := runCommand(logger, workingDirectory, "go", "get", "github.com/smartcontractkit/cre-sdk-go/capabilities/blockchain/evm@"+constants.EVMCapabilitiesVersion); err != nil {
4742
return nil, err
4843
}
49-
if err := runCommand(logger, workingDirectory, "go", "get", "github.com/smartcontractkit/cre-sdk-go/capabilities/networking/http@"+HTTPCapabilitiesVersion); err != nil {
44+
if err := runCommand(logger, workingDirectory, "go", "get", "github.com/smartcontractkit/cre-sdk-go/capabilities/networking/http@"+constants.HTTPCapabilitiesVersion); err != nil {
5045
return nil, err
5146
}
52-
if err := runCommand(logger, workingDirectory, "go", "get", "github.com/smartcontractkit/cre-sdk-go/capabilities/scheduler/cron@"+CronCapabilitiesVersion); err != nil {
47+
if err := runCommand(logger, workingDirectory, "go", "get", "github.com/smartcontractkit/cre-sdk-go/capabilities/scheduler/cron@"+constants.CronCapabilitiesVersion); err != nil {
5348
return nil, err
5449
}
5550

@@ -75,7 +70,7 @@ func runCommand(logger *zerolog.Logger, dir, command string, args ...string) err
7570

7671
output, err := cmd.CombinedOutput()
7772
if err != nil {
78-
logger.Error().Err(err).Msgf("Command failed: %s %v\nOutput:\n%s", command, args, output)
73+
logger.Info().Msgf("%s", string(output))
7974
return err
8075
}
8176

cmd/creinit/go_module_init_test.go

Lines changed: 0 additions & 162 deletions
This file was deleted.

cmd/creinit/template/workflow/blankTemplate/config.production.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

cmd/creinit/template/workflow/blankTemplate/config.staging.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

cmd/creinit/template/workflow/blankTemplate/contracts/evm/src/abi/keep.tpl

Whitespace-only changes.

cmd/creinit/template/workflow/blankTemplate/contracts/evm/src/keystone/keep.tpl

Whitespace-only changes.

cmd/creinit/template/workflow/porExampleDev/README.md

Lines changed: 0 additions & 150 deletions
This file was deleted.

cmd/creinit/template/workflow/porExampleDev/config.production.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)