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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: ci

on:
push:
branches-ignore: [master]
workflow_call:

concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version-file: go.mod
- name: Tool version
id: tools
run: echo "golangci=$(make -s print-GOLANGCI_VERSION)" >> "$GITHUB_OUTPUT"
- uses: golangci/golangci-lint-action@v9
with:
version: ${{ steps.tools.outputs.golangci }}
- name: Lint the workflows
run: |
set -euo pipefail
go install "github.com/rhysd/actionlint/cmd/actionlint@$(make -s print-ACTIONLINT_VERSION)"
"$(go env GOPATH)/bin/actionlint"
- name: go.mod and go.sum are tidy
run: |
go mod tidy
git diff --exit-code go.mod go.sum
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version-file: go.mod
- run: go build ./...
- run: go test -race -count=1 ./...
61 changes: 61 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: release

on:
push:
branches: [master]

concurrency:
group: release
cancel-in-progress: false

permissions:
contents: read

jobs:
ci:
uses: ./.github/workflows/ci.yml

tag:
needs: ci
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0

- name: Tag the merge
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail

git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

# A re-run of this workflow, or a tag pushed by hand, must not publish a
# second version of the same code.
existing=$(git tag --points-at HEAD --list 'v*' | head -1)
if [ -n "$existing" ]; then
echo "HEAD is already released as $existing, nothing to do"
exit 0
fi

latest=$(git tag --list 'v*' --sort=-v:refname \
| grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -1 || true)

if [ -z "$latest" ]; then
next=v0.1.0
elif git diff --quiet "$latest" HEAD; then
echo "unchanged since $latest, nothing to release"
exit 0
else
IFS=. read -r major minor patch <<<"${latest#v}"
next="v${major}.${minor}.$((patch + 1))"
fi

echo "releasing $next (previous: ${latest:-none})"
git tag -a "$next" -m "$next"
git push origin "$next"
gh release create "$next" --title "$next" --generate-notes
11 changes: 11 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "2"

linters:
default: standard # errcheck, govet, ineffassign, staticcheck, unused
enable:
- errorlint
- misspell # exported names have shipped as Critial and Falalf before

formatters:
enable:
- gofmt
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
GOLANGCI_VERSION ?= v2.13.2
ACTIONLINT_VERSION ?= v1.7.12

GOBIN ?= $(or $(shell go env GOBIN),$(shell go env GOPATH)/bin)

.PHONY: test lint install-tools

test:
go test -race -count=1 ./...

lint:
$(GOBIN)/golangci-lint run ./...
$(GOBIN)/actionlint

install-tools:
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_VERSION)
go install github.com/rhysd/actionlint/cmd/actionlint@$(ACTIONLINT_VERSION)

print-%:
@echo $($*)
Loading