@@ -38,12 +38,12 @@ type AutoUpdateOptions struct {
3838 GithubClient * github.Client
3939}
4040
41- // AutoupdateImageRef is used to map a given update image to an entry in config.yaml.
42- // There may be multiple entries that have the same SourceImage , but different
43- // TargetImageNames , so we need to choose which one receives the update image .
44- type AutoupdateImageRef struct {
45- SourceImage string
46- TargetImageName string `json:",omitempty"`
41+ // AutoupdateArtifactRef is used to map a given update artifact to an entry in config.yaml.
42+ // There may be multiple entries that have the same SourceArtifact , but different
43+ // TargetArtifactName , so we need to choose which one receives the update artifact .
44+ type AutoupdateArtifactRef struct {
45+ SourceArtifact string
46+ TargetArtifactName string `json:",omitempty"`
4747}
4848
4949func Parse (filePath string ) ([]ConfigEntry , error ) {
@@ -135,53 +135,53 @@ func (entry ConfigEntry) Validate() error {
135135 return nil
136136}
137137
138- // GetUpdateImages returns a slice of Artifacts that depends on the
138+ // GetUpdateArtifacts returns a slice of Artifacts that depends on the
139139// configured update strategy. The returned Artifacts may be from
140140// any source, and they may be gathered in any way. The intention
141141// is that they are new Artifacts (or new tags of existing Artifacts) that
142142// we want to mirror.
143- func (entry ConfigEntry ) GetUpdateImages () ([]* config.Artifact , error ) {
143+ func (entry ConfigEntry ) GetUpdateArtifacts () ([]* config.Artifact , error ) {
144144 switch {
145145 case entry .GithubRelease != nil :
146- return entry .GithubRelease .GetUpdateImages ()
146+ return entry .GithubRelease .GetUpdateArtifacts ()
147147 case entry .HelmLatest != nil :
148- return entry .HelmLatest .GetUpdateImages ()
148+ return entry .HelmLatest .GetUpdateArtifacts ()
149149 case entry .Registry != nil :
150- return entry .Registry .GetUpdateImages ()
150+ return entry .Registry .GetUpdateArtifacts ()
151151 default :
152152 return nil , errors .New ("did not find update strategy" )
153153 }
154154}
155155
156156func (entry ConfigEntry ) Run (ctx context.Context , opts AutoUpdateOptions ) error {
157- newImages , err := entry .GetUpdateImages ()
157+ newArtifacts , err := entry .GetUpdateArtifacts ()
158158 if err != nil {
159- return fmt .Errorf ("failed to get latest images for %s: %w" , entry .Name , err )
159+ return fmt .Errorf ("failed to get latest artifacts for %s: %w" , entry .Name , err )
160160 }
161161
162162 accumulator := config .NewArtifactAccumulator ()
163163 accumulator .AddArtifacts (opts .ConfigYaml .Artifacts ... )
164164
165- imagesToUpdate := make ([]* config.Artifact , 0 , len (newImages ))
166- for _ , latestImage := range newImages {
167- imageToUpdate , err := accumulator .TagDifference (latestImage )
165+ artifactsToUpdate := make ([]* config.Artifact , 0 , len (newArtifacts ))
166+ for _ , latestArtifact := range newArtifacts {
167+ artifactToUpdate , err := accumulator .TagDifference (latestArtifact )
168168 if err != nil {
169- return fmt .Errorf ("failed to get tag difference for image %s: %w" , latestImage .SourceArtifact , err )
169+ return fmt .Errorf ("failed to get tag difference for artifact %s: %w" , latestArtifact .SourceArtifact , err )
170170 }
171- if imageToUpdate != nil {
172- imagesToUpdate = append (imagesToUpdate , imageToUpdate )
171+ if artifactToUpdate != nil {
172+ artifactsToUpdate = append (artifactsToUpdate , artifactToUpdate )
173173 }
174174 }
175- if len (imagesToUpdate ) == 0 {
175+ if len (artifactsToUpdate ) == 0 {
176176 fmt .Printf ("%s: no updates found\n " , entry .Name )
177177 return nil
178178 }
179179
180- imageSetHash , err := hashImageSet ( imagesToUpdate )
180+ artifactSetHash , err := hashArtifactSet ( artifactsToUpdate )
181181 if err != nil {
182- return fmt .Errorf ("failed to hash set of images that need updates: %w" , err )
182+ return fmt .Errorf ("failed to hash set of artifacts that need updates: %w" , err )
183183 }
184- branchName := fmt .Sprintf ("autoupdate/%s/%s" , entry .Name , imageSetHash )
184+ branchName := fmt .Sprintf ("autoupdate/%s/%s" , entry .Name , artifactSetHash )
185185
186186 // When filtering pull requests by head branch, the github API
187187 // requires that the head branch is in the format <owner>:<branch>.
@@ -213,62 +213,62 @@ func (entry ConfigEntry) Run(ctx context.Context, opts AutoUpdateOptions) error
213213
214214 if opts .DryRun {
215215 msg := fmt .Sprintf ("%s: would make PR under branch %s that adds:\n " , entry .Name , branchName )
216- for _ , imageToUpdate := range imagesToUpdate {
217- for _ , fullImage := range imageToUpdate .CombineSourceArtifactAndTags () {
218- msg = msg + " - " + fullImage + "\n "
216+ for _ , artifactToUpdate := range artifactsToUpdate {
217+ for _ , fullArtifact := range artifactToUpdate .CombineSourceArtifactAndTags () {
218+ msg = msg + " - " + fullArtifact + "\n "
219219 }
220220 }
221221 fmt .Print (msg )
222222 return nil
223223 }
224224
225- return entry .CreateImageUpdatePullRequest (ctx , opts , branchName , imagesToUpdate )
225+ return entry .CreateArtifactUpdatePullRequest (ctx , opts , branchName , artifactsToUpdate )
226226}
227227
228- func (entry ConfigEntry ) CreateImageUpdatePullRequest (ctx context.Context , opts AutoUpdateOptions , branchName string , imagesToUpdate []* config.Artifact ) error {
228+ func (entry ConfigEntry ) CreateArtifactUpdatePullRequest (ctx context.Context , opts AutoUpdateOptions , branchName string , artifactsToUpdate []* config.Artifact ) error {
229229 accumulator := config .NewArtifactAccumulator ()
230230 accumulator .AddArtifacts (opts .ConfigYaml .Artifacts ... )
231231
232232 if err := git .CreateAndCheckoutBranch (opts .BaseBranch , branchName ); err != nil {
233233 return fmt .Errorf ("failed to create and checkout branch %s: %w" , branchName , err )
234234 }
235- for _ , imageToUpdate := range imagesToUpdate {
235+ for _ , artifactToUpdate := range artifactsToUpdate {
236236 // We can reuse the accumulator here because we are making a sequence
237- // of commits, each of which makes an addition from imagesToUpdate .
237+ // of commits, each of which makes an addition from artifactsToUpdate .
238238 configYaml := opts .ConfigYaml
239- accumulator .AddArtifacts (imageToUpdate )
239+ accumulator .AddArtifacts (artifactToUpdate )
240240 configYaml .Artifacts = accumulator .Artifacts ()
241241 if err := config .Write (paths .ConfigYaml , configYaml ); err != nil {
242242 return fmt .Errorf ("failed to write %s: %w" , paths .ConfigYaml , err )
243243 }
244244
245245 regsyncYaml , err := configYaml .ToRegsyncConfig ()
246246 if err != nil {
247- return fmt .Errorf ("failed to generate regsync config for commit for image %s: %w" , imageToUpdate .SourceArtifact , err )
247+ return fmt .Errorf ("failed to generate regsync config for commit for artifact %s: %w" , artifactToUpdate .SourceArtifact , err )
248248 }
249249 if err := regsync .WriteConfig (paths .RegsyncYaml , regsyncYaml ); err != nil {
250- return fmt .Errorf ("failed to write regsync config for commit for image %s: %w" , imageToUpdate .SourceArtifact , err )
250+ return fmt .Errorf ("failed to write regsync config for commit for artifact %s: %w" , artifactToUpdate .SourceArtifact , err )
251251 }
252252
253- tagString := strings .Join (imageToUpdate .Tags , ", " )
254- msg := fmt .Sprintf ("Add tag(s) %s for image %s" , tagString , imageToUpdate .SourceArtifact )
253+ tagString := strings .Join (artifactToUpdate .Tags , ", " )
254+ msg := fmt .Sprintf ("Add tag(s) %s for artifact %s" , tagString , artifactToUpdate .SourceArtifact )
255255 if err := git .Commit (msg ); err != nil {
256- return fmt .Errorf ("failed to commit changes for image %s: %w" , imageToUpdate .SourceArtifact , err )
256+ return fmt .Errorf ("failed to commit changes for artifact %s: %w" , artifactToUpdate .SourceArtifact , err )
257257 }
258258 }
259259 if err := git .PushBranch (branchName , "origin" ); err != nil {
260260 return fmt .Errorf ("failed to push branch %s: %w" , branchName , err )
261261 }
262262
263263 tagCount := 0
264- for _ , imageToUpdate := range imagesToUpdate {
265- tagCount = tagCount + len (imageToUpdate .Tags )
264+ for _ , artifactToUpdate := range artifactsToUpdate {
265+ tagCount = tagCount + len (artifactToUpdate .Tags )
266266 }
267267 title := fmt .Sprintf ("[autoupdate] Add %d tag(s) for `%s`" , tagCount , entry .Name )
268- body := "This PR was created by the autoupdate workflow.\n \n It adds the following image tags:"
269- for _ , imageToUpdate := range imagesToUpdate {
270- for _ , fullImage := range imageToUpdate .CombineSourceArtifactAndTags () {
271- body = body + "\n - `" + fullImage + "`"
268+ body := "This PR was created by the autoupdate workflow.\n \n It adds the following artifact tags:"
269+ for _ , artifactToUpdate := range artifactsToUpdate {
270+ for _ , fullArtifact := range artifactToUpdate .CombineSourceArtifactAndTags () {
271+ body = body + "\n - `" + fullArtifact + "`"
272272 }
273273 }
274274 maintainerCanModify := true
@@ -292,21 +292,21 @@ func (entry ConfigEntry) CreateImageUpdatePullRequest(ctx context.Context, opts
292292 return nil
293293}
294294
295- // hashImageSet computes a human-readable hash from a passed
295+ // hashArtifactSet computes a human-readable hash from a passed
296296// set of Artifacts. Immune to different order of Artifacts, and
297- // immune to the order of of the tags in those Artifacts.
298- func hashImageSet ( images []* config.Artifact ) (string , error ) {
299- for _ , image := range images {
300- image .Sort ()
297+ // immune to the order of the tags in those Artifacts.
298+ func hashArtifactSet ( artifacts []* config.Artifact ) (string , error ) {
299+ for _ , artifact := range artifacts {
300+ artifact .Sort ()
301301 }
302- slices .SortStableFunc (images , config .CompareArtifacts )
302+ slices .SortStableFunc (artifacts , config .CompareArtifacts )
303303
304304 hasher := sha256 .New ()
305- for _ , image := range images {
306- for _ , fullImage := range image .CombineSourceArtifactAndTags () {
307- _ , err := io .WriteString (hasher , fullImage )
305+ for _ , artifact := range artifacts {
306+ for _ , fullArtifact := range artifact .CombineSourceArtifactAndTags () {
307+ _ , err := io .WriteString (hasher , fullArtifact )
308308 if err != nil {
309- return "" , fmt .Errorf ("failed to write full image %q: %w" , fullImage , err )
309+ return "" , fmt .Errorf ("failed to write full artifact %q: %w" , fullArtifact , err )
310310 }
311311 }
312312 }
0 commit comments