-
Notifications
You must be signed in to change notification settings - Fork 373
Cache action pin resolutions in memory across workflow compilations #3688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f0bfd78
Initial plan
Copilot 92d96ca
Add in-memory caching for action pin resolver across workflows
Copilot 02899fa
Merge branch 'main' into copilot/cache-resolved-pins-in-memory
pelikhan d828378
Fix: Use shared cache for action SHA validation
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| package workflow | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestCompilerSharedActionCache(t *testing.T) { | ||
| // Create a temporary directory for test workflows | ||
| tmpDir := t.TempDir() | ||
|
|
||
| // Change to the temp directory so the cache path is consistent | ||
| origDir, err := os.Getwd() | ||
| if err != nil { | ||
| t.Fatalf("Failed to get current directory: %v", err) | ||
| } | ||
| defer func() { | ||
| if err := os.Chdir(origDir); err != nil { | ||
| t.Errorf("Failed to restore directory: %v", err) | ||
| } | ||
| }() | ||
|
|
||
| if err := os.Chdir(tmpDir); err != nil { | ||
| t.Fatalf("Failed to change to temp directory: %v", err) | ||
| } | ||
|
|
||
| // Create a compiler instance | ||
| compiler := NewCompiler(false, "", "test") | ||
|
|
||
| // Get the shared action resolver (first time - should initialize) | ||
| cache1, resolver1 := compiler.getSharedActionResolver() | ||
| if cache1 == nil { | ||
| t.Error("Expected cache to be initialized") | ||
| } | ||
| if resolver1 == nil { | ||
| t.Error("Expected resolver to be initialized") | ||
| } | ||
|
|
||
| // Add an entry to the cache | ||
| cache1.Set("actions/checkout", "v5", "test-sha-abc") | ||
|
|
||
| // Get the shared action resolver again (should be same instance) | ||
| cache2, resolver2 := compiler.getSharedActionResolver() | ||
|
|
||
| // Verify it's the same instance | ||
| if cache1 != cache2 { | ||
| t.Error("Expected same cache instance to be returned") | ||
| } | ||
| if resolver1 != resolver2 { | ||
| t.Error("Expected same resolver instance to be returned") | ||
| } | ||
|
|
||
| // Verify the cache entry is still there (proves it's shared) | ||
| sha, found := cache2.Get("actions/checkout", "v5") | ||
| if !found { | ||
| t.Error("Expected to find cached entry") | ||
| } | ||
| if sha != "test-sha-abc" { | ||
| t.Errorf("Expected SHA 'test-sha-abc', got '%s'", sha) | ||
| } | ||
| } | ||
|
|
||
| func TestCompilerSharedCacheAcrossWorkflows(t *testing.T) { | ||
| // Create a temporary directory for test | ||
| tmpDir := t.TempDir() | ||
|
|
||
| // Change to the temp directory | ||
| origDir, err := os.Getwd() | ||
| if err != nil { | ||
| t.Fatalf("Failed to get current directory: %v", err) | ||
| } | ||
| defer func() { | ||
| if err := os.Chdir(origDir); err != nil { | ||
| t.Errorf("Failed to restore directory: %v", err) | ||
| } | ||
| }() | ||
|
|
||
| if err := os.Chdir(tmpDir); err != nil { | ||
| t.Fatalf("Failed to change to temp directory: %v", err) | ||
| } | ||
|
|
||
| // Create test workflow files | ||
| workflowsDir := filepath.Join(tmpDir, ".github", "workflows") | ||
| if err := os.MkdirAll(workflowsDir, 0755); err != nil { | ||
| t.Fatalf("Failed to create workflows directory: %v", err) | ||
| } | ||
|
|
||
| workflow1Content := `--- | ||
| on: push | ||
| engine: copilot | ||
| --- | ||
| # Test Workflow 1 | ||
| Test content | ||
| ` | ||
|
|
||
| workflow2Content := `--- | ||
| on: pull_request | ||
| engine: copilot | ||
| --- | ||
| # Test Workflow 2 | ||
| Test content | ||
| ` | ||
|
|
||
| workflow1Path := filepath.Join(workflowsDir, "workflow1.md") | ||
| workflow2Path := filepath.Join(workflowsDir, "workflow2.md") | ||
|
|
||
| if err := os.WriteFile(workflow1Path, []byte(workflow1Content), 0644); err != nil { | ||
| t.Fatalf("Failed to write workflow1: %v", err) | ||
| } | ||
| if err := os.WriteFile(workflow2Path, []byte(workflow2Content), 0644); err != nil { | ||
| t.Fatalf("Failed to write workflow2: %v", err) | ||
| } | ||
|
|
||
| // Create a compiler | ||
| compiler := NewCompiler(false, "", "test") | ||
| compiler.SetSkipValidation(true) | ||
| compiler.SetNoEmit(true) | ||
|
|
||
| // Parse the first workflow | ||
| data1, err := compiler.ParseWorkflowFile(workflow1Path) | ||
| if err != nil { | ||
| t.Fatalf("Failed to parse workflow1: %v", err) | ||
| } | ||
|
|
||
| // Manually add a cache entry via the first workflow's cache | ||
| data1.ActionCache.Set("actions/checkout", "v5", "shared-sha-123") | ||
|
|
||
| // Parse the second workflow | ||
| data2, err := compiler.ParseWorkflowFile(workflow2Path) | ||
| if err != nil { | ||
| t.Fatalf("Failed to parse workflow2: %v", err) | ||
| } | ||
|
|
||
| // Verify the second workflow uses the same cache instance | ||
| if data1.ActionCache != data2.ActionCache { | ||
| t.Error("Expected both workflows to share the same cache instance") | ||
| } | ||
|
|
||
| // Verify the cache entry is available in the second workflow | ||
| sha, found := data2.ActionCache.Get("actions/checkout", "v5") | ||
| if !found { | ||
| t.Error("Expected to find cached entry in second workflow") | ||
| } | ||
| if sha != "shared-sha-123" { | ||
| t.Errorf("Expected SHA 'shared-sha-123', got '%s'", sha) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.