Skip to content

Commit

Permalink
short form for override and fix versioned override
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherHX committed Jan 30, 2024
1 parent b1957d1 commit 2e041c9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
14 changes: 11 additions & 3 deletions pkg/runner/local_repository_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"io/fs"
goURL "net/url"
"os"
"path/filepath"
"strings"
Expand All @@ -22,14 +23,21 @@ type LocalRepositoryCache struct {

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[cacheDir] = dest
return "local-repository", nil
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
}
}
return l.Parent.Fetch(ctx, cacheDir, url, ref, token)

Check warning on line 35 in pkg/runner/local_repository_cache.go

View check run for this annotation

Codecov / codecov/patch

pkg/runner/local_repository_cache.go#L35

Added line #L35 was not covered by tests
}

func (l *LocalRepositoryCache) GetTarArchive(ctx context.Context, cacheDir, sha, includePrefix string) (io.ReadCloser, error) {
if dest, ok := l.CacheDirCache[cacheDir]; ok {
// 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)
Expand Down
3 changes: 2 additions & 1 deletion pkg/runner/testdata/local-remote-action-overrides/config.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
local-repositories:
https://github.com/nektos/test-override@a: testdata/actions/node20
https://github.com/nektos/test-override@a: testdata/actions/node20
nektos/test-override@b: testdata/actions/node16
3 changes: 2 additions & 1 deletion pkg/runner/testdata/local-remote-action-overrides/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: nektos/test-override@a
- uses: nektos/test-override@a
- uses: nektos/test-override@b

0 comments on commit 2e041c9

Please sign in to comment.