Skip to content
Open
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
99 changes: 99 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: CI

on:
push:
branches: [master]
pull_request:

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v5
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: "go.mod"

- name: golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: latest
only-new-issues: true

- name: Install mandoc
run: sudo apt-get install -y mandoc

- name: Lint man page
run: mandoc -T lint -W warning moor.1

validate:
name: Validate
permissions:
contents: write
pull-requests: write
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Check out repository code
uses: actions/checkout@v5

- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: "go.mod"

- name: Install mandoc
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get install -y mandoc

- name: Install mandoc
if: matrix.os == 'macos-latest'
run: brew install mandoc

- name: Run tests (Linux/macOS)
if: matrix.os != 'windows-latest'
env:
SKIP_LINT: 1
run: ./test.sh

- name: Run tests (Windows)
if: matrix.os == 'windows-latest'
run: |
go build -race ./...
go test -race -timeout 60s ./...

- name: Run Benchmarks
shell: bash
run: |
# We always run benchmarks on all platforms to catch runtime issues.
# However, we only capture output for analysis on ubuntu-latest to:
# 1. Ensure a consistent baseline (comparing across OSes is unreliable).
# 2. Prevent PR comment spam (avoiding 3 separate bot comments).
if [ "${{ matrix.os }}" == "ubuntu-latest" ] && [ "${{ github.event_name }}" == "pull_request" ]; then
./benchmark.sh output.txt
else
./benchmark.sh
fi

- name: Store benchmark result
# Only analyze and comment on Ubuntu runs to maintain a stable performance baseline
# and avoid multiple redundant comments in Pull Requests.
if: matrix.os == 'ubuntu-latest' && github.event_name == 'pull_request'
uses: benchmark-action/github-action-benchmark@v1
with:
name: Go Benchmark
tool: 'go'
output-file-path: output.txt
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: false
comment-always: true
alert-threshold: '120%'
fail-on-alert: true
33 changes: 0 additions & 33 deletions .github/workflows/linux-ci.yml

This file was deleted.

21 changes: 0 additions & 21 deletions .github/workflows/windows-ci.yml

This file was deleted.

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,14 @@ Launch the manual test suite:
To run tests in 32 bit mode, either do `GOARCH=386 ./test.sh` if you're on
Linux, or `docker build . -f Dockerfile-test-386` (tested on macOS).

Run microbenchmarks:
Run microbenchmarks (results are saved to `benchmarks/<os>-<arch>-<cpu>`):

```bash
go test -benchmem -run='^$' -bench=. ./...
./benchmark.sh
```

*(You can also run them using `./test.sh --bench`)*

Profiling `BenchmarkPlainTextSearch()`. Try replacing `-alloc_objects` with
`-alloc_space` or change the `-focus` function:

Expand Down
33 changes: 33 additions & 0 deletions benchmark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

set -e -o pipefail

mkdir -p benchmarks

GOOS=$(go env GOOS)
GOARCH=$(go env GOARCH)

# Extract CPU model safely across platforms
if [ "$GOOS" = "darwin" ] && command -v sysctl >/dev/null 2>&1; then
CPU_RAW=$(sysctl -n machdep.cpu.brand_string)
elif [ -f /proc/cpuinfo ]; then
CPU_RAW=$(awk -F: '/model name/ {print $2; exit}' /proc/cpuinfo)
elif command -v wmic >/dev/null 2>&1; then
CPU_RAW=$(wmic cpu get name | sed -n '2p' | tr -d '\r')
else
CPU_RAW="unknown"
fi

# Format: lowercase, strip "apple ", replace non-alphanumeric with underscores, trim leading/trailing underscores
CPU=$(echo "$CPU_RAW" | tr '[:upper:]' '[:lower:]' | sed -E 's/apple //g; s/[^a-z0-9]+/_/g; s/^_|_$//g')
OUT="benchmarks/${GOOS}-${GOARCH}-${CPU}"

echo "Running microbenchmarks..."
echo "Results will be saved to ${OUT}"

if [ -n "$1" ]; then
go test -benchmem -run='^$' -bench=. ./... | tee "${OUT}" "$1"
else
go test -benchmem -run='^$' -bench=. ./... | tee "${OUT}"
fi

2 changes: 2 additions & 0 deletions benchmarks/darwin-arm64-m4_pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PASS
ok github.com/walles/moor/v2/cmd/moor 0.223s
21 changes: 15 additions & 6 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

set -e -o pipefail

if [[ "$1" == "--bench" || "$1" == "--benchmark" ]]; then
./benchmark.sh
exit 0
fi

# Test that we only pass twin colors to these methods, not numbers
grep -En 'Foreground\([1-9]' ./**/*.go && exit 1
grep -En 'Background\([1-9]' ./**/*.go && exit 1
Expand All @@ -10,12 +15,16 @@ grep -En 'Background\([1-9]' ./**/*.go && exit 1
echo Building sources...
./build.sh

# Linting
echo 'Linting, repro any errors locally using "golangci-lint run"...'
echo ' Linting without tests...'
golangci-lint run --tests=false
echo ' Linting with tests...'
golangci-lint run --tests=true
if [[ -z "${SKIP_LINT}" ]]; then
# Linting
echo 'Linting, repro any errors locally using "golangci-lint run"...'
echo ' Linting without tests...'
golangci-lint run --tests=false
echo ' Linting with tests...'
golangci-lint run --tests=true
else
echo "Skipping golangci-lint (SKIP_LINT is set)..."
fi

# Unit tests
echo "Running unit tests..."
Expand Down
Loading