MCPcopy Create free account
hub / github.com/github/gh-aw / upgradeSetupCliVersionInContent

Function upgradeSetupCliVersionInContent

pkg/cli/copilot_setup.go:327–353  ·  view source on GitHub ↗

upgradeSetupCliVersionInContent replaces the setup-cli action reference and the associated version: parameter in the raw YAML content using targeted regex substitutions, preserving all other formatting in the file. Returns (upgraded, updatedContent, error). upgraded is false when no change was req

(ctx context.Context, content []byte, actionMode workflow.ActionMode, version string, resolver workflow.SHAResolver)

Source from the content-addressed store, hash-verified

325// Returns (upgraded, updatedContent, error). upgraded is false when no change
326// was required (e.g. already at the target version, or file has no setup-cli step).
327func upgradeSetupCliVersionInContent(ctx context.Context, content []byte, actionMode workflow.ActionMode, version string, resolver workflow.SHAResolver) (bool, []byte, error) {
328 if !actionMode.IsRelease() && !actionMode.IsAction() {
329 return false, content, nil
330 }
331
332 if !setupCliUsesPattern.Match(content) {
333 return false, content, nil
334 }
335
336 actionRef := getActionRef(ctx, actionMode, version, resolver)
337 actionRepo := "github/gh-aw-actions/setup-cli"
338 newUses := actionRepo + actionRef
339
340 // Replace the uses: line, stripping any surrounding quotes in the process.
341 updated := setupCliUsesPattern.ReplaceAll(content, []byte("${1}"+newUses+"${3}"))
342
343 // Replace the version: value in the with: block immediately following the
344 // setup-cli uses: line. versionInWithPattern matches any valid setup-cli
345 // reference so it succeeds even when there was pre-existing drift between
346 // the uses: comment and the version: parameter before the upgrade was run.
347 updated = versionInWithPattern.ReplaceAll(updated, []byte("${1}"+version+"${3}"))
348
349 if bytes.Equal(content, updated) {
350 return false, content, nil
351 }
352 return true, updated, nil
353}

Calls 3

getActionRefFunction · 0.85
IsReleaseMethod · 0.80
IsActionMethod · 0.80