@@ -10,8 +10,9 @@ import (
1010
1111 "github.com/buildkite/zstash/internal/api"
1212 "github.com/buildkite/zstash/internal/archive"
13+ "github.com/buildkite/zstash/internal/cache"
14+ "github.com/buildkite/zstash/internal/configuration"
1315 "github.com/buildkite/zstash/internal/console"
14- "github.com/buildkite/zstash/internal/key"
1516 "github.com/buildkite/zstash/internal/store"
1617 "github.com/buildkite/zstash/internal/trace"
1718 "github.com/charmbracelet/lipgloss"
@@ -31,7 +32,13 @@ func (cmd *SaveCmd) Run(ctx context.Context, globals *Globals) error {
3132
3233 log .Info ().Str ("version" , globals .Version ).Msg ("Running SaveCmd" )
3334
34- for _ , cache := range globals .Caches {
35+ // Augment `cli.Caches` with template values.
36+ caches , err := configuration .ExpandCacheConfiguration (globals .Caches )
37+ if err != nil {
38+ return fmt .Errorf ("failed to load cache configuration: %w" , err )
39+ }
40+
41+ for _ , cache := range caches {
3542 if len (cmd .Ids ) > 0 && ! slices .Contains (cmd .Ids , cache .ID ) {
3643 log .Debug ().Str ("id" , cache .ID ).Msg ("Skipping cache save for ID" )
3744 continue
@@ -49,7 +56,7 @@ func (cmd *SaveCmd) Run(ctx context.Context, globals *Globals) error {
4956 return nil
5057}
5158
52- func (cmd * SaveCmd ) saveCache (ctx context.Context , cache Cache , globals * Globals ) error {
59+ func (cmd * SaveCmd ) saveCache (ctx context.Context , cache cache. Cache , globals * Globals ) error {
5360 ctx , span := trace .Start (ctx , "saveCache" )
5461 defer span .End ()
5562
@@ -110,34 +117,34 @@ func (cmd *SaveCmd) saveCache(ctx context.Context, cache Cache, globals *Globals
110117
111118 globals .Printer .Info ("📦" , "Creating new cache entry for key: %s store: %s" , data .cacheKey , cacheRegistryResp .Store )
112119
113- // Phase 3 : Build archive
120+ // Phase 2 : Build archive
114121 archiveResult , err := cmd .buildArchive (ctx , data , globals .Printer )
115122 if err != nil {
116123 return err
117124 }
118125
119- // Phase 4 : Register cache entry
126+ // Phase 3 : Register cache entry
120127 registrationResult , err := cmd .registerCacheEntry (ctx , data , archiveResult , globals .Client , globals .Common , cache .Registry , cacheRegistryResp .Store )
121128 if err != nil {
122129 return err
123130 }
124131
125132 globals .Printer .Info ("🚀" , "Registering cache entry with upload ID: %s" , registrationResult .uploadID )
126133
127- // Phase 5 : Upload archive
134+ // Phase 4 : Upload archive
128135 uploadResult , err := cmd .uploadArchive (ctx , data .cacheKey , cacheRegistryResp .Store , archiveResult , globals .Printer , globals .Common )
129136 if err != nil {
130137 return err
131138 }
132139
133- // Phase 6 : Commit cache
140+ // Phase 5 : Commit cache
134141 if err := cmd .commitCache (ctx , globals .Client , cache .Registry , registrationResult .uploadID ); err != nil {
135142 return err
136143 }
137144
138145 globals .Printer .Success ("🎉" , "Cache committed successfully" )
139146
140- // Phase 7 : Print summary
147+ // Phase 6 : Print summary
141148 t := table .New ().
142149 Border (lipgloss .NormalBorder ()).
143150 Row ("Key" , data .cacheKey ).
@@ -175,31 +182,16 @@ type uploadResult struct {
175182 transferInfo * store.TransferInfo
176183}
177184
178- func (cmd * SaveCmd ) validateAndPrepare (cache Cache ) (* saveData , error ) {
179- paths , err := checkPath (cache .Paths )
180- if err != nil {
181- return nil , fmt .Errorf ("failed to check paths: %w" , err )
182- }
183-
184- cacheKey , err := key .Template (cache .ID , cache .Key )
185- if err != nil {
186- return nil , fmt .Errorf ("failed to template key: %w" , err )
187- }
188-
189- fallbackKeys , err := restoreKeys (cache .ID , cache .FallbackKeys )
190- if err != nil {
191- return nil , fmt .Errorf ("failed to restore keys: %w" , err )
192- }
193-
194- _ , err = checkPathsExist (paths )
185+ func (cmd * SaveCmd ) validateAndPrepare (cache cache.Cache ) (* saveData , error ) {
186+ _ , err := checkPathsExist (cache .Paths )
195187 if err != nil {
196188 return nil , fmt .Errorf ("failed to check paths exist: %w" , err )
197189 }
198190
199191 return & saveData {
200- paths : paths ,
201- cacheKey : cacheKey ,
202- fallbackKeys : fallbackKeys ,
192+ paths : cache . Paths ,
193+ cacheKey : cache . Key ,
194+ fallbackKeys : cache . FallbackKeys ,
203195 }, nil
204196}
205197
0 commit comments