| 791 | } |
| 792 | |
| 793 | func updateActionRefsInContentWithDeps(ctx context.Context, deps actionUpdateDeps, content string, cache map[string]latestReleaseResult, coolDownCache map[string]coolDownCheckResult, allowMajor, verbose bool, coolDown time.Duration) (bool, string, error) { |
| 794 | changed := false |
| 795 | lines := strings.Split(content, "\n") |
| 796 | |
| 797 | for i, line := range lines { |
| 798 | match := actionRefPattern.FindStringSubmatchIndex(line) |
| 799 | if match == nil { |
| 800 | continue |
| 801 | } |
| 802 | |
| 803 | // Extract matched groups |
| 804 | prefix := line[match[2]:match[3]] // "uses: " |
| 805 | repo := line[match[4]:match[5]] // e.g. "actions/checkout" |
| 806 | ref := line[match[6]:match[7]] // SHA or version tag |
| 807 | comment := "" |
| 808 | if match[8] >= 0 { |
| 809 | comment = line[match[8]:match[9]] // e.g. " # v6.0.2" |
| 810 | } |
| 811 | trailing := "" |
| 812 | if match[10] >= 0 { |
| 813 | trailing = line[match[10]:match[11]] |
| 814 | } |
| 815 | |
| 816 | // When release bumps are disabled, skip non-core (non actions/*) action refs. |
| 817 | effectiveAllowMajor := allowMajor || isCoreAction(repo) |
| 818 | if !effectiveAllowMajor { |
| 819 | continue |
| 820 | } |
| 821 | |
| 822 | // Determine the "current version" to pass to the latest-release resolver. |
| 823 | isSHA := IsCommitSHA(ref) |
| 824 | currentVersion := ref |
| 825 | if isSHA { |
| 826 | // Extract version from comment (e.g., " # v6.0.2" -> "v6.0.2") |
| 827 | if comment != "" { |
| 828 | commentVersion := strings.TrimSpace(strings.TrimPrefix(strings.TrimSpace(comment), "#")) |
| 829 | if commentVersion != "" { |
| 830 | currentVersion = commentVersion |
| 831 | } else { |
| 832 | currentVersion = "" |
| 833 | } |
| 834 | } else { |
| 835 | currentVersion = "" |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | // Resolve latest version/SHA, using the cache to avoid redundant API calls. |
| 840 | // Use "|" as separator since GitHub repo names cannot contain "|". |
| 841 | cacheKey := repo + "|" + currentVersion |
| 842 | result, cached := cache[cacheKey] |
| 843 | if !cached { |
| 844 | latestVersion, latestSHA, err := deps.getLatestRelease(ctx, repo, currentVersion, effectiveAllowMajor, verbose) |
| 845 | if err != nil { |
| 846 | updateLog.Printf("Failed to get latest release for %s: %v", repo, err) |
| 847 | continue |
| 848 | } |
| 849 | result = latestReleaseResult{version: latestVersion, sha: latestSHA} |
| 850 | cache[cacheKey] = result |