-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat: Test writing remote Actions locally #2155
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ba69f85
feat: Test writing remote Actions locally
ChristopherHX fee6a28
Merge branch 'master' into local-repository-action-cache
ChristopherHX 3f4aff6
Merge branch 'master' into local-repository-action-cache
ChristopherHX 5c1546f
Merge branch 'master' into local-repository-action-cache
mergify[bot] 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
This file contains 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 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 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,91 @@ | ||
package runner | ||
|
||
import ( | ||
"archive/tar" | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"io" | ||
"io/fs" | ||
goURL "net/url" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/nektos/act/pkg/filecollector" | ||
) | ||
|
||
type LocalRepositoryCache struct { | ||
Parent ActionCache | ||
LocalRepositories map[string]string | ||
CacheDirCache map[string]string | ||
} | ||
|
||
func (l *LocalRepositoryCache) Fetch(ctx context.Context, cacheDir, url, ref, token string) (string, error) { | ||
if dest, ok := l.LocalRepositories[fmt.Sprintf("%s@%s", url, ref)]; ok { | ||
l.CacheDirCache[fmt.Sprintf("%s@%s", cacheDir, ref)] = dest | ||
return ref, nil | ||
} | ||
if purl, err := goURL.Parse(url); err == nil { | ||
if dest, ok := l.LocalRepositories[fmt.Sprintf("%s@%s", strings.TrimPrefix(purl.Path, "/"), ref)]; ok { | ||
l.CacheDirCache[fmt.Sprintf("%s@%s", cacheDir, ref)] = dest | ||
return ref, nil | ||
} | ||
} | ||
Comment on lines
+29
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. short localrepository definition without uri host are now matchng |
||
return l.Parent.Fetch(ctx, cacheDir, url, ref, token) | ||
} | ||
|
||
func (l *LocalRepositoryCache) GetTarArchive(ctx context.Context, cacheDir, sha, includePrefix string) (io.ReadCloser, error) { | ||
// sha is mapped to ref in fetch if there is a local override | ||
if dest, ok := l.CacheDirCache[fmt.Sprintf("%s@%s", cacheDir, sha)]; ok { | ||
srcPath := filepath.Join(dest, includePrefix) | ||
buf := &bytes.Buffer{} | ||
tw := tar.NewWriter(buf) | ||
defer tw.Close() | ||
srcPath = filepath.Clean(srcPath) | ||
fi, err := os.Lstat(srcPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
tc := &filecollector.TarCollector{ | ||
TarWriter: tw, | ||
} | ||
if fi.IsDir() { | ||
srcPrefix := srcPath | ||
if !strings.HasSuffix(srcPrefix, string(filepath.Separator)) { | ||
srcPrefix += string(filepath.Separator) | ||
} | ||
fc := &filecollector.FileCollector{ | ||
Fs: &filecollector.DefaultFs{}, | ||
SrcPath: srcPath, | ||
SrcPrefix: srcPrefix, | ||
Handler: tc, | ||
} | ||
err = filepath.Walk(srcPath, fc.CollectFiles(ctx, []string{})) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} else { | ||
var f io.ReadCloser | ||
var linkname string | ||
if fi.Mode()&fs.ModeSymlink != 0 { | ||
linkname, err = os.Readlink(srcPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} else { | ||
f, err = os.Open(srcPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer f.Close() | ||
} | ||
err := tc.WriteFile(fi.Name(), fi, linkname, f) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
return io.NopCloser(buf), nil | ||
} | ||
return l.Parent.GetTarArchive(ctx, cacheDir, sha, includePrefix) | ||
} |
This file contains 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 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,3 @@ | ||
local-repositories: | ||
https://github.com/nektos/test-override@a: testdata/actions/node20 | ||
nektos/test-override@b: testdata/actions/node16 | ||
Comment on lines
+1
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added a new config.yml for tests, to configure selected config options |
This file contains 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,9 @@ | ||
name: basic | ||
on: push | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: nektos/test-override@a | ||
- uses: nektos/test-override@b |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CacheDirCache no longer causes key collision if you override the same action with different version