Skip to content

Commit

Permalink
Run tests in pipeline
Browse files Browse the repository at this point in the history
Always set a fake identity and disable commit signing inside of
temporary repos used in tests.

Authored-by: Owen Nelson <[email protected]>
  • Loading branch information
tw-owen-nelson committed Jan 24, 2024
1 parent 636d996 commit d36d166
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/test-and-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]"
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/[email protected]

1 change: 0 additions & 1 deletion .go-version

This file was deleted.

23 changes: 12 additions & 11 deletions git_testing/git_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@ 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", "[email protected]")
testingRepo.ExecCommand("git", "config", "--global", "user.name", "Talisman Test User")
}
testingRepo.ExecCommand("git", "config", "user.email", "[email protected]")
testingRepo.ExecCommand("git", "config", "user.name", "Talisman Test User")
testingRepo.ExecCommand("git", "config", "commit.gpgsign", "false")
return testingRepo
}

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", "[email protected]")
clone.ExecCommand("git", "config", "user.name", "Talisman Test User")
clone.ExecCommand("git", "config", "commit.gpgsign", "false")
return clone
}

func (git *GitTesting) SetupBaselineFiles(filenames ...string) {
Expand Down Expand Up @@ -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 := ""
Expand All @@ -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() {
Expand Down Expand Up @@ -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/")
}

0 comments on commit d36d166

Please sign in to comment.