README
¶
Scripts Directory
This directory contains utility scripts for uptool development and maintenance.
Available Scripts
gen_integrations.go
Purpose: Automatically generates internal/integrations/all/all.go which imports all integration packages.
Why This Exists:
- Go requires explicit imports to trigger
init()functions - Each integration registers itself in its
init()function - Without this, adding a new integration would require manually updating imports
- This script automates the process by scanning for integration packages
How It Works:
- Scans
internal/integrations/directory - Finds all subdirectories containing
.gofiles - Excludes special directories (
all, hidden directories, test files) - Generates
all.gowith blank imports for each integration - Formats the generated code with
go/format
Usage:
# Manual execution (from repository root)
go run scripts/gen_integrations.go
# Or via go generate
go generate ./internal/integrations
When to Run:
- After creating a new integration in
internal/integrations/<name>/ - After renaming an integration directory
- After deleting an integration
- If
internal/integrations/all/all.gois corrupted or missing
Example Output:
// Code generated by scripts/gen_integrations.go. DO NOT EDIT.
// Package all imports all integration packages to trigger their self-registration.
package all
import (
// Import all integration packages to trigger init() functions
_ "github.com/santosr2/uptool/internal/integrations/asdf"
_ "github.com/santosr2/uptool/internal/integrations/helm"
_ "github.com/santosr2/uptool/internal/integrations/mise"
_ "github.com/santosr2/uptool/internal/integrations/npm"
_ "github.com/santosr2/uptool/internal/integrations/precommit"
_ "github.com/santosr2/uptool/internal/integrations/terraform"
_ "github.com/santosr2/uptool/internal/integrations/tflint"
)
Integration Registration Pattern:
Each integration package has an init() function that registers itself:
// internal/integrations/myintegration/myintegration.go
package myintegration
import "github.com/santosr2/uptool/internal/integrations"
func init() {
integrations.Register("myintegration", func() engine.Integration {
return New()
})
}
Automatic Execution:
The script is configured to run via //go:generate directive in internal/integrations/registry.go:
//go:generate go run ../../scripts/gen_integrations.go
Run all generators with:
go generate ./...
Error Handling:
The script will fail if:
go.modis not found (not in repository root)internal/integrations/directory doesn't exist- No integration packages are found
- Generated code fails to format
Development Workflow:
-
Create new integration:
mkdir -p internal/integrations/myintegration # Add myintegration.go with init() function -
Run generator:
go generate ./internal/integrations -
Verify:
cat internal/integrations/all/all.go # Should include your new integration -
Build and test:
mise run build ./dist/uptool list # Should show your integration
Troubleshooting:
Problem: "No integrations found"
- Ensure integration directory contains
.gofiles (not just_test.go) - Directory name should not start with
.or_ - Directory should not be named
all
Problem: "Generated code won't compile"
- Check that integration package has valid Go code
- Verify module path in
go.modmatchesmodulePathconstant - Run
go mod tidy
Problem: "Integration not registering"
- Ensure integration package has
init()function - Verify
init()callsintegrations.Register() - Check that
internal/integrations/allis imported somewhere - Import it with blank identifier:
_ "github.com/santosr2/uptool/internal/integrations/all"
Future Scripts
As the project grows, additional scripts may be added:
gen_docs.sh- Generate API documentationcheck_versions.sh- Verify version consistency across filesvalidate_integrations.sh- Validateintegrations.yamlagainst codebuild_releases.sh- Build binaries for multiple platforms
Contributing Scripts
When adding new scripts:
- Documentation: Add clear comments and usage instructions
- Error Handling: Exit with non-zero status on errors
- Idempotent: Scripts should be safe to run multiple times
- Repository Root: Scripts should work from repository root
- Dependencies: Document any external tool dependencies
- Testing: Test scripts on clean repository clone
Script Conventions
Naming:
- Go scripts:
gen_*.go(generators),check_*.go(validators) - Shell scripts:
*.shwith executable permissions
Error Messages:
- Write errors to stderr:
fmt.Fprintf(os.Stderr, "Error: %v\n", err) - Exit with status 1 on failure:
os.Exit(1)
Output:
- Normal output to stdout
- Progress messages to stdout
- Errors to stderr
Location:
- Executable from repository root
- Use
findRepoRoot()pattern to locate repository - Change to repository root before executing logic
See Also
- Contributing Guide - Development workflow
- Adding Integrations - Integration development
- Go Generate - Official Go blog post