Skip to content

Commit

Permalink
Fix caching a local repo on Windows (#48)
Browse files Browse the repository at this point in the history
(Also fix a couple of other CI issues)
  • Loading branch information
AriehSchneier authored Aug 1, 2024
1 parent a406d68 commit ca2dbe8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.21
check-latest: true
cache: false

- name: Check out
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Make Short Test
if: ${{ github.repository_owner != 'anz-bank' }}
Expand All @@ -34,3 +35,7 @@ jobs:
run: make test
env:
TEST_PRIV_REPO_TOKEN: ${{ secrets.TEST_PRIV_REPO_TOKEN }}
GIT_AUTHOR_NAME: "Tester"
GIT_AUTHOR_EMAIL: "[email protected]"
GIT_COMMITTER_NAME: "Tester"
GIT_COMMITTER_EMAIL: "[email protected]"
4 changes: 2 additions & 2 deletions .github/workflows/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
runs-on: ${{ vars.RUNNER_UBUNTU && fromJSON(vars.RUNNER_UBUNTU) || 'ubuntu-latest' }}
steps:
- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: '0'

- name: Checkout github-tag-action
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: ${{ vars.GENERATE_TAG_REPO || 'anz-bank/github-tag-action' }}
ref: ${{ vars.GENERATE_TAG_REF || '1.40.0' }}
Expand Down
11 changes: 9 additions & 2 deletions retriever/git/cacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package git

import (
"path/filepath"
"strings"
"sync"

"github.com/go-git/go-billy/v5/osfs"
Expand Down Expand Up @@ -84,7 +85,7 @@ func (s FsCache) NewStorer(repo string) storage.Storer {
}

func (s FsCache) repoDir(repo string) string {
return filepath.Join(s.dir, repo)
return filepath.Join(s.dir, cleanForSubPath(repo))
}

// PlainFsCache implements the Cacher interface storing repositories in filesystem
Expand Down Expand Up @@ -118,5 +119,11 @@ func (s PlainFsCache) NewStorer(repo string) storage.Storer {
}

func (s PlainFsCache) RepoDir(repo string) string {
return filepath.Join(s.dir, repo)
return filepath.Join(s.dir, cleanForSubPath(repo))
}

// cleanForSubPath will return a string that is suitable to be used as subpath in the cache directory
// for Windows caching a local repo we need to remove the colon in the drive letter
func cleanForSubPath(repo string) string {
return strings.ReplaceAll(repo, ":", "")
}
11 changes: 8 additions & 3 deletions retriever/git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"bytes"
"context"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"os"
"os/exec"
"path/filepath"
"testing"

log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// Verify setting the repository using the various supported reference types (branch, tag, hash) sets the content.
Expand Down Expand Up @@ -687,6 +688,10 @@ func TestGitSession_Set_Fetch(t *testing.T) {
require.NoError(t, err)
require.Equal(t, pubRepoMainContent, string(file))

// Set the config to keep line endings so the test doesn't fail on Windows
err = execute(repoDir, "git", "config", "core.autocrlf", "input")
require.NoError(t, err)

// In an out-of-band process, move the head to a different commit.
err = execute(repoDir, "git", "reset", "--hard", pubRepoV1SHA)
require.NoError(t, err)
Expand Down

0 comments on commit ca2dbe8

Please sign in to comment.