PruneOrphanedEntries removes action cache entries whose keys are not present in referencedKeys. It returns the number of entries that were removed. This is used to keep actions-lock.json a faithful reflection of what the compiled workflows actually reference — entries for old action versions that ar
(referencedKeys map[string]bool)
| 105 | // compiled workflows actually reference — entries for old action versions that |
| 106 | // are no longer used by any workflow are removed. |
| 107 | func (c *ActionCache) PruneOrphanedEntries(referencedKeys map[string]bool) int { |
| 108 | if len(referencedKeys) == 0 { |
| 109 | return 0 |
| 110 | } |
| 111 | |
| 112 | // Compiler-generated actions that should never be pruned. |
| 113 | // These are embedded in Go code rather than markdown workflows and include: |
| 114 | // - Core workflow actions (cache, checkout, github-script) |
| 115 | // - Runtime setup actions (from runtime_definitions.go) |
| 116 | // - Security scanning actions (CodeQL) |
| 117 | compilerGeneratedRepos := []string{ |
| 118 | "actions/cache/", |
| 119 | "actions/checkout", |
| 120 | "actions/github-script", |
| 121 | "github/codeql-action/upload-sarif", |
| 122 | } |
| 123 | |
| 124 | // Add all runtime-managed actions from runtime_definitions.go |
| 125 | for _, runtime := range knownRuntimes { |
| 126 | if runtime.ActionRepo != "" { |
| 127 | compilerGeneratedRepos = append(compilerGeneratedRepos, runtime.ActionRepo) |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | isCompilerGenerated := func(cacheKey string) bool { |
| 132 | for _, repo := range compilerGeneratedRepos { |
| 133 | if strings.HasPrefix(cacheKey, repo) { |
| 134 | return true |
| 135 | } |
| 136 | } |
| 137 | return false |
| 138 | } |
| 139 | |
| 140 | pruned := 0 |
| 141 | for key := range c.Entries { |
| 142 | if !referencedKeys[key] && !isCompilerGenerated(key) { |
| 143 | delete(c.Entries, key) |
| 144 | c.dirty = true |
| 145 | pruned++ |
| 146 | actionCacheLog.Printf("Pruned orphaned action cache entry: %s", key) |
| 147 | } |
| 148 | } |
| 149 | if pruned > 0 { |
| 150 | actionCacheLog.Printf("Pruned %d orphaned action cache entries, %d entries remaining", pruned, len(c.Entries)) |
| 151 | } |
| 152 | return pruned |
| 153 | } |
| 154 | |
| 155 | // PruneStaleContainerPins removes container pin entries whose keys are not present |
| 156 | // in knownImages. It returns the number of entries that were removed. |