mirror of
https://github.com/grdl/git-get.git
synced 2026-02-11 05:59:15 +00:00
Set git user and email in tests helper instead of CI jobs. Simplify CI
This commit is contained in:
56
.github/workflows/ci.yml
vendored
56
.github/workflows/ci.yml
vendored
@@ -38,23 +38,13 @@ jobs:
|
|||||||
|
|
||||||
- name: Verify dependencies
|
- name: Verify dependencies
|
||||||
run: go mod verify
|
run: go mod verify
|
||||||
|
|
||||||
|
- name: Build binary
|
||||||
|
run: go build -v -o bin/git-get ./cmd/
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: go test -race ./...
|
||||||
|
|
||||||
- name: Set up Git (for tests)
|
|
||||||
run: |
|
|
||||||
git config --global user.email "test@example.com"
|
|
||||||
git config --global user.name "CI Test"
|
|
||||||
|
|
||||||
- name: Run tests with coverage
|
|
||||||
run: go test -race -coverprofile coverage.out -covermode=atomic ./...
|
|
||||||
|
|
||||||
- name: Upload coverage to Codecov
|
|
||||||
if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.24'
|
|
||||||
uses: codecov/codecov-action@v5
|
|
||||||
with:
|
|
||||||
file: ./coverage.out
|
|
||||||
flags: unittests
|
|
||||||
name: codecov-umbrella
|
|
||||||
fail_ci_if_error: false
|
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
name: Lint
|
name: Lint
|
||||||
@@ -104,37 +94,3 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
sarif_file: 'trivy-results.sarif'
|
sarif_file: 'trivy-results.sarif'
|
||||||
|
|
||||||
build:
|
|
||||||
name: Build
|
|
||||||
needs: [test, lint, security]
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v5
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Set up Go
|
|
||||||
uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: '1.24'
|
|
||||||
cache: true
|
|
||||||
|
|
||||||
- name: Build binary
|
|
||||||
run: |
|
|
||||||
go build -v -o bin/git-get ./cmd/
|
|
||||||
|
|
||||||
- name: Test binary and symlink behavior
|
|
||||||
run: |
|
|
||||||
./bin/git-get --version
|
|
||||||
# Test symlink functionality
|
|
||||||
ln -sf git-get bin/git-list
|
|
||||||
./bin/git-list --version
|
|
||||||
|
|
||||||
- name: Upload build artifacts
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: binary
|
|
||||||
path: bin/
|
|
||||||
retention-days: 30
|
|
||||||
|
|||||||
@@ -31,6 +31,17 @@ func TempDir(t *testing.T, parent string) string {
|
|||||||
func (r *Repo) init() {
|
func (r *Repo) init() {
|
||||||
err := run.Git("init", "--quiet", "--initial-branch=main", r.path).AndShutUp()
|
err := run.Git("init", "--quiet", "--initial-branch=main", r.path).AndShutUp()
|
||||||
checkFatal(r.t, err)
|
checkFatal(r.t, err)
|
||||||
|
|
||||||
|
r.setupGitConfig()
|
||||||
|
}
|
||||||
|
|
||||||
|
// setupGitConfig sets up local git config for test repository only.
|
||||||
|
func (r *Repo) setupGitConfig() {
|
||||||
|
err := run.Git("config", "user.name", "Test User").OnRepo(r.path).AndShutUp()
|
||||||
|
checkFatal(r.t, err)
|
||||||
|
|
||||||
|
err = run.Git("config", "user.email", "test@example.com").OnRepo(r.path).AndShutUp()
|
||||||
|
checkFatal(r.t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeFile writes the content string into a file. If file doesn't exists, it will create it.
|
// writeFile writes the content string into a file. If file doesn't exists, it will create it.
|
||||||
@@ -50,7 +61,7 @@ func (r *Repo) stageFile(path string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repo) commit(msg string) {
|
func (r *Repo) commit(msg string) {
|
||||||
err := run.Git("commit", "-m", fmt.Sprintf("%q", msg), "--author=\"user <user@example.com>\"").OnRepo(r.path).AndShutUp()
|
err := run.Git("commit", "-m", fmt.Sprintf("%q", msg)).OnRepo(r.path).AndShutUp()
|
||||||
checkFatal(r.t, err)
|
checkFatal(r.t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,6 +92,9 @@ func (r *Repo) clone() *Repo {
|
|||||||
t: r.t,
|
t: r.t,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set up git config in the cloned repository
|
||||||
|
clone.setupGitConfig()
|
||||||
|
|
||||||
return clone
|
return clone
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user