@@ -33,6 +33,7 @@ type Command struct {
3333 Depends * Deps
3434 ChecksumMap map [string ]string
3535 PersistChecksum bool
36+ ChecksumCmd string
3637 // args from 'lets run --debug' will become [--debug]
3738 Args []string
3839
@@ -68,7 +69,8 @@ func (c *Command) UnmarshalYAML(unmarshal func(interface{}) error) error {
6869 After string
6970 Ref string
7071 Checksum * Checksum
71- PersistChecksum bool `yaml:"persist_checksum"`
72+ ChecksumCmd string `yaml:"checksum_cmd"`
73+ PersistChecksum bool `yaml:"persist_checksum"`
7274 }
7375
7476 if err := unmarshal (& cmd ); err != nil {
@@ -109,9 +111,13 @@ func (c *Command) UnmarshalYAML(unmarshal func(interface{}) error) error {
109111 c .ChecksumSources = * cmd .Checksum
110112 }
111113
114+ if cmd .ChecksumCmd != "" {
115+ c .ChecksumCmd = cmd .ChecksumCmd
116+ }
117+
112118 c .PersistChecksum = cmd .PersistChecksum
113- if len (c .ChecksumSources ) == 0 && c .PersistChecksum {
114- return errors .New ("'persist_checksum' must be used with 'checksum'" )
119+ if len (c .ChecksumSources ) == 0 && c .ChecksumCmd == "" && c . PersistChecksum {
120+ return errors .New ("'persist_checksum' must be used with 'checksum' or 'checksum_cmd' " )
115121 }
116122
117123 if cmd .Ref != "" {
@@ -154,6 +160,7 @@ func (c *Command) Clone() *Command {
154160 Depends : c .Depends .Clone (),
155161 ChecksumMap : cloneMap (c .ChecksumMap ),
156162 PersistChecksum : c .PersistChecksum ,
163+ ChecksumCmd : c .ChecksumCmd ,
157164 ChecksumSources : cloneMapSlice (c .ChecksumSources ),
158165 persistedChecksums : cloneMap (c .persistedChecksums ),
159166 Args : cloneSlice (c .Args ),
@@ -190,7 +197,17 @@ func (c *Command) Help() string {
190197 return strings .TrimSuffix (buf .String (), "\n " )
191198}
192199
193- func (c * Command ) ChecksumCalculator (workDir string ) error {
200+ func (c * Command ) ChecksumCalculator (shell , workDir string ) error {
201+ if c .ChecksumCmd != "" {
202+ checksumResult , err := checksum .CalculateChecksumFromCmd (shell , workDir , c .ChecksumCmd )
203+ if err != nil {
204+ return err
205+ }
206+ c .ChecksumMap = make (map [string ]string , 1 )
207+ c .ChecksumMap [checksum .DefaultChecksumKey ] = checksumResult
208+ return nil
209+ }
210+
194211 if len (c .ChecksumSources ) == 0 {
195212 return nil
196213 }
0 commit comments