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
16 changes: 13 additions & 3 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ First off, glad you're here and want to contribute! :heart:

## Getting Started

It's always good to start simple. Clone the repo and `make test` to make sure you're starting from a good place.
This project uses [mise](https://mise.jdx.dev) to manage its toolchain (Go, golangci-lint, goreleaser, and Task) and [Task](https://taskfile.dev) as the command runner. Once mise is installed, it reads the pinned versions from `mise.toml` so everyone builds against the same tools.

1. [Install mise](https://mise.jdx.dev/getting-started.html)
1. Clone the repo
1. Run `mise install` to install the pinned tool versions
1. Run `task test` to make sure you're starting from a good place

Run `task --list` to see everything that's available.

## Submitting a PR

Expand All @@ -13,8 +20,9 @@ Here are some general guidelines for making PRs for this repo.
1. [Fork this repo](https://github.com/pseudomuto/protokit/fork)
1. Make a branch off of master (`git checkout -b <your_branch_name>`)
1. Make focused commits with descriptive messages
1. Add tests that fail without your code, and pass with it (`make test` is your friend)
1. Add tests that fail without your code, and pass with it (`task test` is your friend)
1. GoFmt your code! (see <https://blog.golang.org/go-fmt-your-code> to setup your editor to do this for you)
1. Run `task lint` before pushing (`task lint:fix` fixes what it can automatically)
1. **Ping someone on the PR** (Lots of people, including myself, won't get a notification unless pinged directly)

Every PR should have a well detailed summary of the changes being made and the reasoning behind them. I've added a
Expand All @@ -31,5 +39,7 @@ I don't want to be too dogmatic about this, but here are some general things I t

## Tagging a Release

Releases are cut from a signed git tag. Pushing the tag triggers the release workflow, which runs goreleaser.

* Ensure you're on a clean master
* Run `make release`
* Run `task tag:patch` (or `task tag:minor` / `task tag:major`) to bump, sign, and push the tag
14 changes: 14 additions & 0 deletions .github/actions/setup/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: setup
description: Install mise toolchain and restore Go module/build caches

runs:
using: composite
steps:
- uses: jdx/mise-action@dad1bfd3df957f44999b559dd69dc1671cb4e9ea # v4.2.1
- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('go.sum', 'dev/tools.sum') }}
restore-keys: ${{ runner.os }}-go-
50 changes: 15 additions & 35 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,21 @@ on:
pull_request:
branches: [master]

# this ensures that the old run is abandoned when we have a new push to the PR branch
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v5

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v20

- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v13
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: ./.github/actions/setup
- run: task test:ci

- name: Run tests
run: nix develop -c task test:ci

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
- uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
with:
file: ./coverage.out
flags: unittests
Expand All @@ -36,31 +32,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v5

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v20

- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v13

- name: Run linter
run: nix develop -c task lint
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: ./.github/actions/setup
- run: task lint

build:
name: Build
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v5

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v20

- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v13

- name: Run GoReleaser (no publish)
run: nix develop -c task build
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: ./.github/actions/setup
- run: task build
13 changes: 3 additions & 10 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,11 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- uses: ./.github/actions/setup

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v20

- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v13

- name: Run GoReleaser
run: nix develop -c goreleaser release --clean
- run: goreleaser release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
107 changes: 11 additions & 96 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,103 +1,18 @@
version: "2"
# https://golangci-lint.run/usage/configuration/

run:
modules-download-mode: readonly
version: "2"

linters:
default: none
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- contextcheck
- depguard
- durationcheck
- errcheck
- errchkjson
- errorlint
- exhaustive
- funlen
- gocheckcompilerdirectives
- gochecksumtype
- gocognit
- gocyclo
- gomoddirectives
- gomodguard
- gosec
- gosmopolitan
- govet
- ineffassign
- loggercheck
- maintidx
- makezero
- musttag
- nestif
- nilerr
- nilnesserr
- noctx
- perfsprint
- prealloc
- reassign
- recvcheck
- rowserrcheck
- spancheck
- sqlclosecheck
- staticcheck
- testifylint
- unparam
- unused
- zerologlint

settings:
depguard:
rules:
main:
list-mode: lax
deny:
- pkg: reflect
funlen:
ignore-comments: true
lines: 100
statements: 60

gocognit:
min-complexity: 50

testifylint:
disable:
- go-require

exclusions:
generated: lax
paths:
- "examples/(.+).go$"
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- gomoddirectives
path: go.mod
- linters:
- funlen
path: (.+)main.go
- linters:
- tagalign
path: (.+).go
- linters:
- funlen
path: (.+)_test.go
- linters:
- errcheck
- gocognit
path: examples/(.+).go
default: standard
settings: {}

formatters:
enable:
- gci
- gofmt
- gofumpt
- goimports
settings:
gci:
sections:
- standard
- default
- localmodule
custom-order: true
3 changes: 2 additions & 1 deletion comments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"fmt"
"testing"

"github.com/stretchr/testify/require"

"github.com/pseudomuto/protokit"
"github.com/pseudomuto/protokit/utils"
"github.com/stretchr/testify/require"
)

func TestComments(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"context"
"testing"

"github.com/pseudomuto/protokit"
"github.com/stretchr/testify/require"

"github.com/pseudomuto/protokit"
)

func TestContextWithFileDescriptor(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions example_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package protokit_test
import (
"log"

"github.com/pseudomuto/protokit"
"google.golang.org/protobuf/proto"
pluginpb "google.golang.org/protobuf/types/pluginpb"

"github.com/pseudomuto/protokit"
)

type plugin struct{}
Expand All @@ -16,8 +16,8 @@ func (p *plugin) Generate(r *pluginpb.CodeGeneratorRequest) (*pluginpb.CodeGener

for _, desc := range descriptors {
resp.File = append(resp.File, &pluginpb.CodeGeneratorResponse_File{
Name: proto.String(desc.GetName() + ".out"),
Content: proto.String("Some relevant output"),
Name: new(desc.GetName() + ".out"),
Content: new("Some relevant output"),
})
}

Expand Down
8 changes: 4 additions & 4 deletions examples/jsonator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"fmt"
"log"

"google.golang.org/protobuf/proto"
"google.golang.org/genproto/googleapis/api/annotations"
pluginpb "google.golang.org/protobuf/types/pluginpb"

"github.com/pseudomuto/protokit"
"google.golang.org/genproto/googleapis/api/annotations"
)

func main() {
Expand Down Expand Up @@ -38,8 +38,8 @@ func (p *plugin) Generate(req *pluginpb.CodeGeneratorRequest) (*pluginpb.CodeGen

resp := new(pluginpb.CodeGeneratorResponse)
resp.File = append(resp.File, &pluginpb.CodeGeneratorResponse_File{
Name: proto.String("output.json"),
Content: proto.String(buf.String()),
Name: new("output.json"),
Content: new(buf.String()),
})

return resp, nil
Expand Down
61 changes: 0 additions & 61 deletions flake.lock

This file was deleted.

Loading
Loading