From d36d1663fabd4e5c9559c7b9ee5e269b828f704f Mon Sep 17 00:00:00 2001 From: Owen Nelson Date: Wed, 24 Jan 2024 15:57:59 -0600 Subject: [PATCH] Run tests in pipeline Always set a fake identity and disable commit signing inside of temporary repos used in tests. Authored-by: Owen Nelson --- .github/workflows/test-and-coverage.yml | 12 +++++------- .go-version | 1 - git_testing/git_testing.go | 23 ++++++++++++----------- 3 files changed, 17 insertions(+), 19 deletions(-) delete mode 100644 .go-version diff --git a/.github/workflows/test-and-coverage.yml b/.github/workflows/test-and-coverage.yml index 23f993e4..f82776d9 100644 --- a/.github/workflows/test-and-coverage.yml +++ b/.github/workflows/test-and-coverage.yml @@ -2,30 +2,28 @@ name: Build on: push: - branches: [ master ] pull_request: - branches: [ master ] + branches: [ main ] jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v4 with: - go-version: 1.16 + go-version-file: go.mod - name: Test run: | git config user.email "talisman-maintainers@thoughtworks.com" git config user.name "Talisman Maintainers" go test -covermode=count -coverprofile=coverage.out -v ./... - + - name: Codecov # You may pin to the exact commit or the version. # uses: codecov/codecov-action@e156083f13aff6830c92fc5faa23505779fbf649 uses: codecov/codecov-action@v1.2.1 - diff --git a/.go-version b/.go-version deleted file mode 100644 index 0150af13..00000000 --- a/.go-version +++ /dev/null @@ -1 +0,0 @@ -1.18.10 diff --git a/git_testing/git_testing.go b/git_testing/git_testing.go index 291ebea3..f0aa6631 100644 --- a/git_testing/git_testing.go +++ b/git_testing/git_testing.go @@ -23,11 +23,9 @@ func Init(gitRoot string) *GitTesting { testingRepo := &GitTesting{gitRoot} output := testingRepo.ExecCommand("git", "init", ".") logrus.Debugf("Git init result %v", string(output)) - if os.Getenv("CI") != "" { - fmt.Println("Setting up git_repo") - testingRepo.ExecCommand("git", "config", "--global", "user.email", "talisman-test-user@example.com") - testingRepo.ExecCommand("git", "config", "--global", "user.name", "Talisman Test User") - } + testingRepo.ExecCommand("git", "config", "user.email", "talisman-test-user@example.com") + testingRepo.ExecCommand("git", "config", "user.name", "Talisman Test User") + testingRepo.ExecCommand("git", "config", "commit.gpgsign", "false") return testingRepo } @@ -35,8 +33,11 @@ func (git *GitTesting) GitClone(cloneName string) *GitTesting { result := git.ExecCommand("git", "clone", git.gitRoot, cloneName) Logger.Debugf("Clone result : %s\n", result) Logger.Debugf("GitRoot :%s \t CloneRoot: %s\n", git.gitRoot, cloneName) - retval := &GitTesting{cloneName} - return retval + clone := &GitTesting{cloneName} + clone.ExecCommand("git", "config", "user.email", "talisman-test-user@example.com") + clone.ExecCommand("git", "config", "user.name", "Talisman Test User") + clone.ExecCommand("git", "config", "commit.gpgsign", "false") + return clone } func (git *GitTesting) SetupBaselineFiles(filenames ...string) { @@ -125,7 +126,7 @@ func (git *GitTesting) Commit(fileName string, message string) { git.ExecCommand("git", "commit", "-m", message) } -//GetBlobDetails returns git blob details for a path +// GetBlobDetails returns git blob details for a path func (git *GitTesting) GetBlobDetails(fileName string) string { var output []byte objectHashAndFilename := "" @@ -145,7 +146,7 @@ func (git *GitTesting) GetBlobDetails(fileName string) string { return objectHashAndFilename } -//ExecCommand executes a command with given arguments in the git repo directory +// ExecCommand executes a command with given arguments in the git repo directory func (git *GitTesting) ExecCommand(commandName string, args ...string) string { var output []byte git.doInGitRoot(func() { @@ -176,12 +177,12 @@ func (git *GitTesting) doInGitRoot(operation func()) { operation() } -//GetRoot returns the root directory of the git-testing repo +// GetRoot returns the root directory of the git-testing repo func (git *GitTesting) GetRoot() string { return git.gitRoot } -//RemoveHooks removes all file-system hooks from git-test repo +// RemoveHooks removes all file-system hooks from git-test repo func (git *GitTesting) RemoveHooks() { git.ExecCommand("rm", "-rf", ".git/hooks/") }