Skip to content

Commit

Permalink
Bring setup steps back to README.
Browse files Browse the repository at this point in the history
  • Loading branch information
schmonz committed Jul 5, 2024
1 parent 709d175 commit 1fe42ba
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
[![Build status](https://github.com/schmonz/junit-greencently/actions/workflows/main-build.yml/badge.svg)](https://github.com/schmonz/junit-greencently/actions/workflows/main-build.yml)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.schmonz/junit-greencently/badge.svg?gav=true)](https://central.sonatype.com/artifact/com.schmonz/junit-greencently)

# Greencently

For teams whose commits fail on red tests, Greencently offers an optimization:
the pre-commit hook can know when you've run all tests green "recently enough".
Team chooses policy.

## Benefits (immediate)

- Lower-friction commits
- Time and energy saved

## Benefits (speculative)

Probably you'll lean into smaller, more frequent commits.
Maybe you'll also feel more able to invest in further test speedups.

## Usage

Nobody needs to learn anything.
The pre-commit hook still has your back when you forget to...

- Run any tests
- Run all tests
- Attend to red tests

With Greencently, the pre-commit hook also has your back when you _remember_.

All tests green, recently?
Commit quickly and stay in flow.
# [Greencently](https://schmonz.com/software/greencently)

## Setup

- [Documentation](https://schmonz.com/software/greencently)
For JUnit 5:

1. Update `build.gradle.kts`:
```gradle
dependencies {
testRuntimeOnly("com.schmonz:junit-greencently:VERSION_NUMBER_HERE")
}
tasks.withType<Test> {
jvmArgs("-Djunit.jupiter.extensions.autodetection.enabled=true")
maxParallelForks = 1 // see #4
}
```
2. Run all tests for project
3. If green, observe top-level `.when-all-tests-were-green-junit5`
4. Append to top-level `.gitignore`: `*when-all-tests-were-green*`
5. In pre-commit hook, inspect file modification time. Example:
```sh
#!/bin/sh
all_tests_were_recently_green() {
thenstamp=$(date -r .when-all-tests-were-green-junit5 '+%s' 2>/dev/null || echo 0)
nowstamp=$(date '+%s')
secondsago=$(expr ${nowstamp} - ${thenstamp})
[ ${secondsago} -lt 30 ]
}
if all_tests_were_recently_green; then
./gradlew clean build -x test
else
./gradlew clean build
fi
```

0 comments on commit 1fe42ba

Please sign in to comment.