generateCacheMemoryGitCommitSteps emits post-agent steps that commit agent-written changes to the current integrity branch. These steps run after agent execution and before artifact upload so that the saved tarball always includes up-to-date git history.
(builder *strings.Builder, data *WorkflowData)
| 633 | // to the current integrity branch. These steps run after agent execution and before artifact |
| 634 | // upload so that the saved tarball always includes up-to-date git history. |
| 635 | func generateCacheMemoryGitCommitSteps(builder *strings.Builder, data *WorkflowData) { |
| 636 | if data.CacheMemoryConfig == nil || len(data.CacheMemoryConfig.Caches) == 0 { |
| 637 | return |
| 638 | } |
| 639 | |
| 640 | cacheLog.Printf("Generating cache-memory git commit steps for %d caches", len(data.CacheMemoryConfig.Caches)) |
| 641 | |
| 642 | useBackwardCompatiblePaths := len(data.CacheMemoryConfig.Caches) == 1 && data.CacheMemoryConfig.Caches[0].ID == "default" |
| 643 | |
| 644 | for _, cache := range data.CacheMemoryConfig.Caches { |
| 645 | // Skip restore-only caches (nothing to commit) |
| 646 | if cache.RestoreOnly { |
| 647 | continue |
| 648 | } |
| 649 | |
| 650 | cacheDir := cacheMemoryDirFor(cache.ID) |
| 651 | |
| 652 | if useBackwardCompatiblePaths { |
| 653 | builder.WriteString(" - name: Commit cache-memory changes\n") |
| 654 | } else { |
| 655 | fmt.Fprintf(builder, " - name: Commit cache-memory changes (%s)\n", cache.ID) |
| 656 | } |
| 657 | // Run even when agent fails so that partial work is still recorded. |
| 658 | builder.WriteString(" if: always()\n") |
| 659 | builder.WriteString(" env:\n") |
| 660 | fmt.Fprintf(builder, " GH_AW_CACHE_DIR: %s\n", cacheDir) |
| 661 | builder.WriteString(" run: bash \"${RUNNER_TEMP}/gh-aw/actions/commit_cache_memory_git.sh\"\n") |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | // generateCacheMemoryValidation generates validation steps for cache-memory file types |
| 666 | // This should be called after agent execution to validate files before upload/save |