From 791fbd70fc1e8f62da8d8b26c60f8df43f018b2a Mon Sep 17 00:00:00 2001 From: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com> Date: Thu, 1 Aug 2024 09:37:46 +1000 Subject: [PATCH 1/9] Add author and committer to test commit to fix CI --- .github/workflows/test.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1467528..b5a5164 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -34,3 +34,7 @@ jobs: run: make test env: TEST_PRIV_REPO_TOKEN: ${{ secrets.TEST_PRIV_REPO_TOKEN }} + GIT_AUTHOR_NAME: "Tester" + GIT_AUTHOR_EMAIL: "email@address.com" + GIT_COMMITTER_NAME: "Tester" + GIT_COMMITTER_EMAIL: "email@address.com" From 3d9b16cd50237060a5947d51c41024e1c523cfc9 Mon Sep 17 00:00:00 2001 From: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com> Date: Thu, 1 Aug 2024 10:19:38 +1000 Subject: [PATCH 2/9] Fix newlines on Windows --- retriever/git/retriever_const_test.go | 14 ++++++++++++++ retriever/git/retriever_const_windows_test.go | 14 ++++++++++++++ retriever/git/retriever_test.go | 11 ++--------- 3 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 retriever/git/retriever_const_test.go create mode 100644 retriever/git/retriever_const_windows_test.go diff --git a/retriever/git/retriever_const_test.go b/retriever/git/retriever_const_test.go new file mode 100644 index 0000000..24fb34f --- /dev/null +++ b/retriever/git/retriever_const_test.go @@ -0,0 +1,14 @@ +//go:build !windows +// +build !windows + +package git + +const ( + pubRepoInitContent = "# a-public-repo\nA public repo for modules testing\n" + pubRepoV1Content = "# a-public-repo v0.0.1\nA public repo for modules testing\n" + pubRepoV2Content = "# a-public-repo v0.0.2\nA public repo for modules testing\n" + pubRepoDevelopContent = "# a-public-repo-dev\nA public repo for modules testing\n" + pubRepoMainContent = pubRepoV2Content + + privRepoContent = "# a-private-repo\nA private repo for modules testing\n" +) diff --git a/retriever/git/retriever_const_windows_test.go b/retriever/git/retriever_const_windows_test.go new file mode 100644 index 0000000..7915cdb --- /dev/null +++ b/retriever/git/retriever_const_windows_test.go @@ -0,0 +1,14 @@ +//go:build windows +// +build windows + +package git + +const ( + pubRepoInitContent = "# a-public-repo\r\nA public repo for modules testing\r\n" + pubRepoV1Content = "# a-public-repo v0.0.1\r\nA public repo for modules testing\r\n" + pubRepoV2Content = "# a-public-repo v0.0.2\r\nA public repo for modules testing\r\n" + pubRepoDevelopContent = "# a-public-repo-dev\r\nA public repo for modules testing\r\n" + pubRepoMainContent = pubRepoV2Content + + privRepoContent = "# a-private-repo\r\nA private repo for modules testing\r\n" +) diff --git a/retriever/git/retriever_test.go b/retriever/git/retriever_test.go index ec86af8..d8f88e1 100644 --- a/retriever/git/retriever_test.go +++ b/retriever/git/retriever_test.go @@ -25,18 +25,11 @@ const ( pubRepoV2Tag = "v0.0.2" pubRepoDevelopBranch = "develop" pubRepoMainBranch = "main" - - pubRepoInitContent = "# a-public-repo\nA public repo for modules testing\n" - pubRepoV1Content = "# a-public-repo v0.0.1\nA public repo for modules testing\n" - pubRepoV2Content = "# a-public-repo v0.0.2\nA public repo for modules testing\n" - pubRepoDevelopContent = "# a-public-repo-dev\nA public repo for modules testing\n" - pubRepoMainContent = pubRepoV2Content ) const ( - privRepo = "github.com/SyslBot/a-private-repo" - privRepoREADME = privRepo + "/README.md" - privRepoContent = "# a-private-repo\nA private repo for modules testing\n" + privRepo = "github.com/SyslBot/a-private-repo" + privRepoREADME = privRepo + "/README.md" ) var ( From 99e9fe51032db9713fc8bacec4211bb0e40799f3 Mon Sep 17 00:00:00 2001 From: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com> Date: Thu, 1 Aug 2024 10:49:05 +1000 Subject: [PATCH 3/9] Create a valid cache directory in Windows --- retriever/git/cacher.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/retriever/git/cacher.go b/retriever/git/cacher.go index 5207627..a205cc4 100644 --- a/retriever/git/cacher.go +++ b/retriever/git/cacher.go @@ -2,6 +2,7 @@ package git import ( "path/filepath" + "strings" "sync" "github.com/go-git/go-billy/v5/osfs" @@ -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 @@ -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, ":", "") } From 27b72631af3143d52d31f3d76a0da4ba258a22b1 Mon Sep 17 00:00:00 2001 From: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com> Date: Thu, 1 Aug 2024 10:59:46 +1000 Subject: [PATCH 4/9] Test again without \r --- retriever/git/retriever_const_windows_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/retriever/git/retriever_const_windows_test.go b/retriever/git/retriever_const_windows_test.go index 7915cdb..11ee2ac 100644 --- a/retriever/git/retriever_const_windows_test.go +++ b/retriever/git/retriever_const_windows_test.go @@ -4,11 +4,11 @@ package git const ( - pubRepoInitContent = "# a-public-repo\r\nA public repo for modules testing\r\n" - pubRepoV1Content = "# a-public-repo v0.0.1\r\nA public repo for modules testing\r\n" - pubRepoV2Content = "# a-public-repo v0.0.2\r\nA public repo for modules testing\r\n" - pubRepoDevelopContent = "# a-public-repo-dev\r\nA public repo for modules testing\r\n" + pubRepoInitContent = "# a-public-repo\nA public repo for modules testing\n" + pubRepoV1Content = "# a-public-repo v0.0.1\nA public repo for modules testing\n" + pubRepoV2Content = "# a-public-repo v0.0.2\nA public repo for modules testing\n" + pubRepoDevelopContent = "# a-public-repo-dev\nA public repo for modules testing\n" pubRepoMainContent = pubRepoV2Content - privRepoContent = "# a-private-repo\r\nA private repo for modules testing\r\n" + privRepoContent = "# a-private-repo\nA private repo for modules testing\n" ) From 5f494ac42e1e2f80e2ed6c5096f23c04236a0187 Mon Sep 17 00:00:00 2001 From: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com> Date: Thu, 1 Aug 2024 12:41:05 +1000 Subject: [PATCH 5/9] Try just changing the 1 string --- retriever/git/retriever_const_windows_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/retriever/git/retriever_const_windows_test.go b/retriever/git/retriever_const_windows_test.go index 11ee2ac..9200aed 100644 --- a/retriever/git/retriever_const_windows_test.go +++ b/retriever/git/retriever_const_windows_test.go @@ -5,7 +5,7 @@ package git const ( pubRepoInitContent = "# a-public-repo\nA public repo for modules testing\n" - pubRepoV1Content = "# a-public-repo v0.0.1\nA public repo for modules testing\n" + pubRepoV1Content = "# a-public-repo v0.0.1\r\nA public repo for modules testing\r\n" pubRepoV2Content = "# a-public-repo v0.0.2\nA public repo for modules testing\n" pubRepoDevelopContent = "# a-public-repo-dev\nA public repo for modules testing\n" pubRepoMainContent = pubRepoV2Content From 420a98e10b4de645e960d8ec879aaeccf08c0869 Mon Sep 17 00:00:00 2001 From: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com> Date: Thu, 1 Aug 2024 15:06:27 +1000 Subject: [PATCH 6/9] Fix by setting core.autocrlf to false --- retriever/git/git_test.go | 11 +++++--- retriever/git/retriever_const_test.go | 14 ---------- retriever/git/retriever_const_windows_test.go | 14 ---------- retriever/git/retriever_test.go | 26 ++++++++++++------- 4 files changed, 24 insertions(+), 41 deletions(-) delete mode 100644 retriever/git/retriever_const_test.go delete mode 100644 retriever/git/retriever_const_windows_test.go diff --git a/retriever/git/git_test.go b/retriever/git/git_test.go index 6a9eef5..8a067de 100644 --- a/retriever/git/git_test.go +++ b/retriever/git/git_test.go @@ -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. @@ -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", "true") + 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) diff --git a/retriever/git/retriever_const_test.go b/retriever/git/retriever_const_test.go deleted file mode 100644 index 24fb34f..0000000 --- a/retriever/git/retriever_const_test.go +++ /dev/null @@ -1,14 +0,0 @@ -//go:build !windows -// +build !windows - -package git - -const ( - pubRepoInitContent = "# a-public-repo\nA public repo for modules testing\n" - pubRepoV1Content = "# a-public-repo v0.0.1\nA public repo for modules testing\n" - pubRepoV2Content = "# a-public-repo v0.0.2\nA public repo for modules testing\n" - pubRepoDevelopContent = "# a-public-repo-dev\nA public repo for modules testing\n" - pubRepoMainContent = pubRepoV2Content - - privRepoContent = "# a-private-repo\nA private repo for modules testing\n" -) diff --git a/retriever/git/retriever_const_windows_test.go b/retriever/git/retriever_const_windows_test.go deleted file mode 100644 index 9200aed..0000000 --- a/retriever/git/retriever_const_windows_test.go +++ /dev/null @@ -1,14 +0,0 @@ -//go:build windows -// +build windows - -package git - -const ( - pubRepoInitContent = "# a-public-repo\nA public repo for modules testing\n" - pubRepoV1Content = "# a-public-repo v0.0.1\r\nA public repo for modules testing\r\n" - pubRepoV2Content = "# a-public-repo v0.0.2\nA public repo for modules testing\n" - pubRepoDevelopContent = "# a-public-repo-dev\nA public repo for modules testing\n" - pubRepoMainContent = pubRepoV2Content - - privRepoContent = "# a-private-repo\nA private repo for modules testing\n" -) diff --git a/retriever/git/retriever_test.go b/retriever/git/retriever_test.go index d8f88e1..554285d 100644 --- a/retriever/git/retriever_test.go +++ b/retriever/git/retriever_test.go @@ -17,19 +17,25 @@ const ( pubRepo = "github.com/SyslBot/a-public-repo" pubRepoREADME = pubRepo + "/README.md" - pubRepoInitSHA = "1e7c4cecaaa8f76e3c668cebc411f1b03171501f" - pubRepoV1SHA = "f948d44b0d97dbbe019949c8b574b5f246b25dc2" - pubRepoV2SHA = "6a27bac5e5c379649c5b4574845744957cd6c749" - pubRepoMainSHA = pubRepoV2SHA - pubRepoV1Tag = "v0.0.1" - pubRepoV2Tag = "v0.0.2" - pubRepoDevelopBranch = "develop" - pubRepoMainBranch = "main" + pubRepoInitSHA = "1e7c4cecaaa8f76e3c668cebc411f1b03171501f" + pubRepoV1SHA = "f948d44b0d97dbbe019949c8b574b5f246b25dc2" + pubRepoV2SHA = "6a27bac5e5c379649c5b4574845744957cd6c749" + pubRepoMainSHA = pubRepoV2SHA + pubRepoV1Tag = "v0.0.1" + pubRepoV2Tag = "v0.0.2" + pubRepoDevelopBranch = "develop" + pubRepoMainBranch = "main" + pubRepoInitContent = "# a-public-repo\nA public repo for modules testing\n" + pubRepoV1Content = "# a-public-repo v0.0.1\nA public repo for modules testing\n" + pubRepoV2Content = "# a-public-repo v0.0.2\nA public repo for modules testing\n" + pubRepoDevelopContent = "# a-public-repo-dev\nA public repo for modules testing\n" + pubRepoMainContent = pubRepoV2Content ) const ( - privRepo = "github.com/SyslBot/a-private-repo" - privRepoREADME = privRepo + "/README.md" + privRepo = "github.com/SyslBot/a-private-repo" + privRepoREADME = privRepo + "/README.md" + privRepoContent = "# a-private-repo\nA private repo for modules testing\n" ) var ( From 54f44e32cab1730eb318fce8fa6a7a2d4c67ab0f Mon Sep 17 00:00:00 2001 From: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com> Date: Thu, 1 Aug 2024 15:08:09 +1000 Subject: [PATCH 7/9] Restore whitespace --- retriever/git/retriever_test.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/retriever/git/retriever_test.go b/retriever/git/retriever_test.go index 554285d..ec86af8 100644 --- a/retriever/git/retriever_test.go +++ b/retriever/git/retriever_test.go @@ -17,14 +17,15 @@ const ( pubRepo = "github.com/SyslBot/a-public-repo" pubRepoREADME = pubRepo + "/README.md" - pubRepoInitSHA = "1e7c4cecaaa8f76e3c668cebc411f1b03171501f" - pubRepoV1SHA = "f948d44b0d97dbbe019949c8b574b5f246b25dc2" - pubRepoV2SHA = "6a27bac5e5c379649c5b4574845744957cd6c749" - pubRepoMainSHA = pubRepoV2SHA - pubRepoV1Tag = "v0.0.1" - pubRepoV2Tag = "v0.0.2" - pubRepoDevelopBranch = "develop" - pubRepoMainBranch = "main" + pubRepoInitSHA = "1e7c4cecaaa8f76e3c668cebc411f1b03171501f" + pubRepoV1SHA = "f948d44b0d97dbbe019949c8b574b5f246b25dc2" + pubRepoV2SHA = "6a27bac5e5c379649c5b4574845744957cd6c749" + pubRepoMainSHA = pubRepoV2SHA + pubRepoV1Tag = "v0.0.1" + pubRepoV2Tag = "v0.0.2" + pubRepoDevelopBranch = "develop" + pubRepoMainBranch = "main" + pubRepoInitContent = "# a-public-repo\nA public repo for modules testing\n" pubRepoV1Content = "# a-public-repo v0.0.1\nA public repo for modules testing\n" pubRepoV2Content = "# a-public-repo v0.0.2\nA public repo for modules testing\n" From 37187af6c3dec31086502a456b2cdf200a2d138d Mon Sep 17 00:00:00 2001 From: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com> Date: Thu, 1 Aug 2024 15:10:26 +1000 Subject: [PATCH 8/9] Use input --- retriever/git/git_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/retriever/git/git_test.go b/retriever/git/git_test.go index 8a067de..85499d8 100644 --- a/retriever/git/git_test.go +++ b/retriever/git/git_test.go @@ -689,7 +689,7 @@ func TestGitSession_Set_Fetch(t *testing.T) { 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", "true") + 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. From 1460e865f60770c65a0657b783ef4d36ada4857c Mon Sep 17 00:00:00 2001 From: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com> Date: Thu, 1 Aug 2024 15:21:43 +1000 Subject: [PATCH 9/9] Update github actions while here --- .github/workflows/test.yaml | 5 +++-- .github/workflows/version.yaml | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index b5a5164..2b490b8 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -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' }} diff --git a/.github/workflows/version.yaml b/.github/workflows/version.yaml index 138fbf0..977031f 100644 --- a/.github/workflows/version.yaml +++ b/.github/workflows/version.yaml @@ -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' }}