ValidateActionSHAsInLockFile validates action SHAs in a lock file and emits warnings
(ctx context.Context, lockFilePath string, cache *ActionCache, verbose bool)
| 69 | |
| 70 | // ValidateActionSHAsInLockFile validates action SHAs in a lock file and emits warnings |
| 71 | func ValidateActionSHAsInLockFile(ctx context.Context, lockFilePath string, cache *ActionCache, verbose bool) error { |
| 72 | actionSHACheckerLog.Printf("Validating action SHAs in: %s", lockFilePath) |
| 73 | |
| 74 | // Extract actions from lock file |
| 75 | actions, err := ExtractActionsFromLockFile(lockFilePath) |
| 76 | if err != nil { |
| 77 | return fmt.Errorf("failed to extract actions: %w", err) |
| 78 | } |
| 79 | |
| 80 | if len(actions) == 0 { |
| 81 | actionSHACheckerLog.Print("No pinned actions found in lock file") |
| 82 | if verbose { |
| 83 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage("No pinned actions to validate")) |
| 84 | } |
| 85 | return nil |
| 86 | } |
| 87 | |
| 88 | // Create resolver for checking latest SHAs |
| 89 | resolver := NewActionResolver(cache) |
| 90 | |
| 91 | // Check for updates |
| 92 | checks := CheckActionSHAUpdates(ctx, actions, resolver) |
| 93 | |
| 94 | // Count and report updates |
| 95 | updateCount := 0 |
| 96 | for _, check := range checks { |
| 97 | if check.NeedsUpdate { |
| 98 | updateCount++ |
| 99 | // Emit warning (FormatWarningMessage adds the warning emoji) |
| 100 | warningMsg := fmt.Sprintf("%s@%s has a newer SHA available: %s → %s", |
| 101 | check.Action.Repo, |
| 102 | check.Action.Version, |
| 103 | check.Action.SHA[:7], |
| 104 | check.LatestSHA[:7]) |
| 105 | fmt.Fprintln(os.Stderr, console.FormatWarningMessage(warningMsg)) |
| 106 | |
| 107 | // Show full SHA in verbose mode |
| 108 | if verbose { |
| 109 | fmt.Fprintf(os.Stderr, " Current: %s\n", check.Action.SHA) |
| 110 | fmt.Fprintf(os.Stderr, " Latest: %s\n", check.LatestSHA) |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | if updateCount > 0 { |
| 116 | actionSHACheckerLog.Printf("Found %d actions that need updating", updateCount) |
| 117 | // Save the cache with updated SHAs so the next compilation will use them |
| 118 | if err := cache.Save(); err != nil { |
| 119 | actionSHACheckerLog.Printf("Warning: failed to save action cache: %v", err) |
| 120 | } else { |
| 121 | actionSHACheckerLog.Print("Saved updated action cache") |
| 122 | } |
| 123 | // Provide suggestion to fix the issue |
| 124 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage("To apply updated action SHAs, recompile with: gh aw compile")) |
| 125 | if verbose { |
| 126 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Found %d action(s) with available updates", updateCount))) |
| 127 | } |
| 128 | } else { |