Skip to content

Commit 1d6b098

Browse files
committed
setup: initial import
Project I had lying around that was never actually put anywhere. Slightly rewritten and prettified to current standards. Signed-off-by: Simon de Vlieger <cmdr@supakeen.com>
0 parents  commit 1d6b098

51 files changed

Lines changed: 2107 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test:
14+
name: Test
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
go-version: ['1.26']
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Go
25+
uses: actions/setup-go@v5
26+
with:
27+
go-version: ${{ matrix.go-version }}
28+
29+
- name: Download dependencies
30+
run: go mod download
31+
32+
- name: Verify dependencies
33+
run: go mod verify
34+
35+
- name: Run tests
36+
run: go test -v -race -coverprofile=coverage.out ./...
37+
38+
- name: Upload coverage to Codecov
39+
if: matrix.go-version == '1.26'
40+
uses: codecov/codecov-action@v4
41+
with:
42+
file: ./coverage.out
43+
flags: unittests
44+
fail_ci_if_error: false
45+
46+
lint:
47+
name: Lint
48+
runs-on: ubuntu-latest
49+
50+
steps:
51+
- name: Checkout code
52+
uses: actions/checkout@v4
53+
54+
- name: Set up Go
55+
uses: actions/setup-go@v5
56+
with:
57+
go-version: '1.26'
58+
59+
- name: Download dependencies
60+
run: go mod download
61+
62+
- name: Run staticcheck
63+
run: go install honnef.co/go/tools/cmd/staticcheck@latest && staticcheck ./...
64+
65+
- name: Check for misspellings
66+
uses: reviewdog/action-misspell@v1
67+
with:
68+
locale: "US"
69+
70+
build:
71+
name: Build
72+
runs-on: ubuntu-latest
73+
74+
steps:
75+
- name: Checkout code
76+
uses: actions/checkout@v4
77+
78+
- name: Set up Go
79+
uses: actions/setup-go@v5
80+
with:
81+
go-version: '1.26'
82+
83+
- name: Build
84+
run: go build -v ./...
85+
86+
- name: Run go vet
87+
run: go vet ./...
88+
89+
- name: Check formatting
90+
run: |
91+
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
92+
echo "The following files are not formatted:"
93+
gofmt -s -l .
94+
exit 1
95+
fi

.github/workflows/release.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
name: Create Release
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Set up Go
23+
uses: actions/setup-go@v5
24+
with:
25+
go-version: '1.26'
26+
27+
- name: Run tests
28+
run: go test -v -race ./...
29+
30+
- name: Get version from tag
31+
id: get_version
32+
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
33+
34+
- name: Build binaries
35+
run: |
36+
VERSION=${{ steps.get_version.outputs.VERSION }}
37+
COMMIT=$(git rev-parse --short HEAD)
38+
LDFLAGS="-X main.version=${VERSION} -X main.commit=${COMMIT}"
39+
40+
for GOARCH in amd64 arm64 riscv64; do
41+
GOOS=linux GOARCH=$GOARCH go build -ldflags "$LDFLAGS" -o "dist/pgr-linux-${GOARCH}" ./cmd/pgr
42+
done
43+
44+
- name: Generate changelog
45+
id: changelog
46+
run: |
47+
PREV_TAG=$(git describe --abbrev=0 --tags $(git rev-list --tags --skip=1 --max-count=1) 2>/dev/null || echo "")
48+
if [ -z "$PREV_TAG" ]; then
49+
PREV_TAG=$(git rev-list --max-parents=0 HEAD)
50+
fi
51+
52+
{
53+
echo "CHANGELOG<<EOF"
54+
git log $PREV_TAG..HEAD --pretty=format:"- %s (%h)" --no-merges
55+
echo ""
56+
echo "EOF"
57+
} >> $GITHUB_OUTPUT
58+
59+
- name: Create Release
60+
uses: softprops/action-gh-release@v2
61+
with:
62+
name: Release ${{ steps.get_version.outputs.VERSION }}
63+
body: |
64+
## Changes in ${{ steps.get_version.outputs.VERSION }}
65+
66+
${{ steps.changelog.outputs.CHANGELOG }}
67+
68+
## Installation
69+
70+
```bash
71+
go install github.com/supakeen/pgr/cmd/pgr@${{ steps.get_version.outputs.VERSION }}
72+
```
73+
files: dist/*

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2026 Simon de Vlieger
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Makefile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
.PHONY: test test-coverage lint fmt vet clean help
2+
3+
# Default target
4+
.DEFAULT_GOAL := help
5+
6+
## test: Run all tests
7+
test:
8+
go test -v -race ./...
9+
10+
## test-coverage: Run tests with coverage report
11+
test-coverage:
12+
go test -v -race -coverprofile=coverage.out ./...
13+
go tool cover -html=coverage.out -o coverage.html
14+
@echo "Coverage report generated: coverage.html"
15+
@go tool cover -func=coverage.out | grep total
16+
17+
## lint: Run all linters (staticcheck + go vet)
18+
lint: staticcheck vet
19+
20+
## staticcheck: Run staticcheck
21+
staticcheck:
22+
staticcheck ./...
23+
24+
## fmt: Format all Go files
25+
fmt:
26+
gofmt -s -w .
27+
28+
## vet: Run go vet
29+
vet:
30+
go vet ./...
31+
32+
## check: Run all checks (fmt, vet, staticcheck, test)
33+
check: fmt vet staticcheck test
34+
35+
## clean: Remove build artifacts and coverage files
36+
clean:
37+
rm -f coverage.out coverage.html
38+
go clean -cache -testcache
39+
40+
## help: Display this help message
41+
help:
42+
@echo "Available targets:"
43+
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'

0 commit comments

Comments
 (0)