Redesign checksum config and add migration tool#342
Draft
Conversation
Reviewer's GuideRefactors command checksum configuration to support a new object-based syntax with files/shell/persist options while keeping legacy behavior, adds a Class diagram for updated command checksum configurationclassDiagram
direction LR
class Command {
+string Name
+string GroupName
+Cmds Cmds
+string After
+string Shell
+string WorkDir
+string Description
+Env Env
+EnvFiles EnvFiles
+string Docopts
+bool SkipDocopts
+map~string,string~ Options
+map~string,string~ CliOptions
+Deps Depends
+map~string,string~ ChecksumMap
+bool PersistChecksum
+bool DeprecatedPersistChecksum
+string ChecksumSh
+map~string,[]string~ ChecksumSources
+map~string,string~ persistedChecksums
+[]string Args
+UnmarshalYAML(unmarshal func_any_error) error
+Clone() *Command
+ChecksumCalculator(workDir string, shell string, env map~string,string~) error
}
class CommandChecksum {
+ChecksumFiles Files
+string Sh
+*bool Persist
+UnmarshalYAML(node *yaml_Node) error
}
class ChecksumFiles {
<<type>>
+map~string,[]string~ (alias)
+UnmarshalYAML(unmarshal func_any_error) error
}
class Checksum {
<<type alias>>
+ChecksumFiles (alias for env checksum)
}
class Executor {
+Config cfg
+initCmd(ctx *Context) error
}
class Config {
+string Shell
+string WorkDir
+map~string,string~ GetEnv()
+map~string,string~ CommandBuiltinEnv(cmd *Command, shell string, workDir string)
}
class Context {
+*Command command
+ExecLogger logger
}
class ExecLogger {
+string prefix
+Warn(format string, a ...any)
+Info(format string, a ...any)
+Debug(format string, a ...any)
}
class checksum_pkg {
+CalculateChecksumFromSources(workDir string, checksumSources map~string,[]string~) (map~string,string~, error)
+CalculateChecksumFromConfig(workDir string, checksumSources map~string,[]string~, shell string, script string, env map~string,string~) (map~string,string~, error)
+CalculateChecksumFromScript(workDir string, shell string, script string, env map~string,string~) (string, error)
}
Command "1" --> "0..1" CommandChecksum : yaml field checksum
Command --> ChecksumFiles : uses as ChecksumSources
Command --> checksum_pkg : calls
Command --> Executor : used by
Executor --> Command : initCmd operates on
Executor --> Config : uses cfg
Executor --> Context : receives
Context --> ExecLogger : has
Config --> Command : passed into CommandBuiltinEnv
checksum_pkg ..> ChecksumFiles : input type
CommandChecksum ..> ChecksumFiles : field Files
Command o--> ChecksumFiles : ChecksumSources
Command o--> string : ChecksumSh
Command o--> bool : PersistChecksum
Command o--> bool : DeprecatedPersistChecksum
Class diagram for migration framework and checksum migrationclassDiagram
direction LR
class Migration {
<<interface>>
+Name() string
+Apply(root *yaml_Node) (bool, error)
}
class ChecksumMigration {
+Name() string
+Apply(root *yaml_Node) (bool, error)
+migrateCommandChecksum(command *yaml_Node) (bool, error)
+isNewChecksumNode(node *yaml_Node) bool
+mappingIndex(node *yaml_Node, key string) int
+appendMapping(node *yaml_Node, key *yaml_Node, value *yaml_Node)
+removeMappingIndex(node *yaml_Node, idx int)
+scalar(value string) *yaml_Node
+cloneNode(node *yaml_Node) *yaml_Node
}
class Result {
+[]string ChangedFiles
+[]string RemoteMixins
+[]string Applied
+bool Changed
+bool DryRun
+[]string Previews
}
class migrate_pkg {
+DefaultMigrations() []Migration
+Fix(configName string, configDir string, dryRun bool, out io_Writer) (Result, error)
+fixFile(path string, dryRun bool, migrations []Migration) (bool, []string, string, error)
+decodeYAML(data []byte) (*yaml_Node, error)
+encodeYAML(root *yaml_Node) ([]byte, error)
+formatCommandSpacing(data []byte) []byte
+isCommandEntryLine(line string) bool
+collectConfigPaths(rootPath string, workDir string) ([]string, []string, error)
+document(root *yaml_Node) *yaml_Node
+mappingValue(node *yaml_Node, key string) *yaml_Node
+writeResult(out io_Writer, result Result)
}
class FixCommand {
+bool dryRun
+initFixCommand() *cobra_Command
}
class Cobra_Command {
+Use string
+Short string
+RunE(func(cmd *cobra_Command, args []string) error)
+Flags() *pflag_FlagSet
+Root() *cobra_Command
+OutOrStdout() io_Writer
}
Migration <|.. ChecksumMigration
migrate_pkg --> Migration : uses
migrate_pkg --> Result : returns
migrate_pkg --> ChecksumMigration : DefaultMigrations
FixCommand --> Cobra_Command : constructs
FixCommand --> migrate_pkg : calls Fix
ChecksumMigration --> yaml_Node : operates on
migrate_pkg --> yaml_Node : parses and writes YAML
migrate_pkg --> Result : populates
migrate_pkg --> ChecksumMigration : applies checksum migration
Cobra_Command --> FixCommand : created by initFixCommand
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
checksum.files,checksum.sh, andchecksum.persistwhile keeping legacy checksum syntax workinglets self fixto migrate local configs and mixins, with dry-run preview outputpersist_checksumTesting
go test ./...lets lintlets test-bats command_checksum.batslets test-bats command_persist_checksum.batslets test-bats self_fix.batsSummary by Sourcery
Redesign command checksum configuration to support new schema options and introduce an automated migration path, while keeping legacy behavior compatible and deprecated.
New Features:
checksum.files,checksum.sh, andchecksum.persistalongside existing checksum support.LETS_CHECKSUMfrom an arbitrary command.lets self fixcommand with optional--dry-runto automatically migrate configs and mixins from deprecated checksum syntax to the new format.persist_checksumusage and emit runtime warnings when it is used.Enhancements:
Documentation:
checksum.persist.lets self fixCLI command and note the deprecation of direct list/mapchecksumwith command-levelpersist_checksum.Tests:
persist_checksumwarnings.