Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: ci
on:
push:
branches: [main]
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- run: go build ./...
- run: go vet ./...
# preen drives a real git, so the tests need an identity to commit with
# and a runner whose git is not carrying a stale default branch name.
- name: Configure git for the tests
run: |
git config --global user.name "preen ci"
git config --global user.email "ci@example.com"
git config --global init.defaultBranch main
- run: go test ./...
- name: Check formatting
run: |
unformatted="$(gofmt -l .)"
if [ -n "$unformatted" ]; then
echo "::error::gofmt would change these files:"
echo "$unformatted"
exit 1
fi
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# preen

[![ci](https://github.com/dcadolph/preen/actions/workflows/ci.yml/badge.svg)](https://github.com/dcadolph/preen/actions/workflows/ci.yml)
[![Latest release](https://img.shields.io/github/v/release/dcadolph/preen)](https://github.com/dcadolph/preen/releases/latest)
[![License](https://img.shields.io/github/license/dcadolph/preen)](LICENSE)

Expand Down
20 changes: 20 additions & 0 deletions run/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ import (
"github.com/dcadolph/preen/repo"
)

// TestMain isolates the package from the developer's git configuration.
//
// The harness already passes GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM to the
// commands it runs itself, but the engine under test spawns git on its own, and
// those children inherit the process environment rather than the harness's. A
// developer who installs shared hooks the usual way, by pointing core.hooksPath
// at a directory in their global config, would watch the hook tests fail against
// hooks they never wrote: the repository-local hook the test installs is ignored
// while core.hooksPath is set, so a hook that is supposed to reject a rewrite
// never runs at all.
func TestMain(m *testing.M) {
if err := os.Setenv("GIT_CONFIG_GLOBAL", os.DevNull); err != nil {
panic(err)
}
if err := os.Setenv("GIT_CONFIG_SYSTEM", os.DevNull); err != nil {
panic(err)
}
os.Exit(m.Run())
}

// harness is a real repository plus an engine wired to it.
type harness struct {
// Engine is the engine under test.
Expand Down
Loading