Skip to content

Commit

Permalink
Use generic gorelease fork in CI (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop authored May 26, 2022
1 parent 4a5f115 commit 7ca847b
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cloc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Count Lines Of Code
id: loc
run: |
curl -sLO https://github.com/vearutop/sccdiff/releases/download/v1.0.1/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz
curl -sLO https://github.com/vearutop/sccdiff/releases/download/v1.0.2/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz && echo "b17e76bede22af0206b4918d3b3c4e7357f2a21b57f8de9e7c9dc0eb56b676c0 sccdiff" | shasum -c
OUTPUT=$(cd pr && ../sccdiff -basedir ../base)
echo "${OUTPUT}"
OUTPUT="${OUTPUT//$'\n'/%0A}"
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ jobs:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.18.x
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.0.0
uses: golangci/golangci-lint-action@v3.1.0
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.44.2
version: v1.46.2

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
57 changes: 57 additions & 0 deletions .github/workflows/gorelease.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# This script is provided by github.com/bool64/dev.
name: gorelease
on:
pull_request:

# Cancel the workflow in progress in newer build is about to start.
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

env:
GO_VERSION: 1.18.x
jobs:
gorelease:
runs-on: ubuntu-latest
steps:
- name: Install Go stable
if: env.GO_VERSION != 'tip'
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
- name: Install Go tip
if: env.GO_VERSION == 'tip'
run: |
curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz
ls -lah gotip.tar.gz
mkdir -p ~/sdk/gotip
tar -C ~/sdk/gotip -xzf gotip.tar.gz
~/sdk/gotip/bin/go version
echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
- name: Checkout code
uses: actions/checkout@v2
- name: Gorelease cache
uses: actions/cache@v2
with:
path: |
~/go/bin/gorelease
key: ${{ runner.os }}-gorelease-fork
- name: Gorelease
id: gorelease
run: |
test -e ~/go/bin/gorelease || (rm -rf /tmp/gorelease && mkdir -p /tmp/gorelease && cd /tmp/gorelease && go mod init foo && go mod edit -replace golang.org/x/exp=github.com/vearutop/golang-exp@gorelease-generic && go get golang.org/x/exp/cmd/gorelease && go install golang.org/x/exp/cmd/gorelease)
OUTPUT=$(gorelease 2>&1 || exit 0)
echo "${OUTPUT}"
OUTPUT="${OUTPUT//$'\n'/%0A}"
echo "::set-output name=report::$OUTPUT"
- name: Comment Report
continue-on-error: true
uses: marocchino/sticky-pull-request-comment@v2
with:
header: gorelease
message: |
### Go API Changes
<pre>
${{ steps.gorelease.outputs.report }}
</pre>
7 changes: 3 additions & 4 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ jobs:
test:
strategy:
matrix:
go-version: [ 1.13.x, 1.14.x, 1.15.x, 1.16.x, 1.17.x, 1.18.0-rc1, tip ]
go-version: [ 1.13.x, 1.14.x, 1.15.x, 1.16.x, 1.17.x, 1.18.x ]
runs-on: ubuntu-latest
steps:
- name: Install Go
- name: Install Go stable
if: matrix.go-version != 'tip'
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
stable: false
go-version: ${{ matrix.go-version }}
- name: Install Go tip
if: matrix.go-version == 'tip'
Expand Down
9 changes: 5 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# See https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml
run:
tests: true
skip-files:
- "go1.18"
skip-dirs:
- "../"

linters-settings:
errcheck:
Expand Down Expand Up @@ -41,6 +37,8 @@ linters:
- tagliatelle
- errname
- ireturn
- exhaustruct
- nonamedreturns

issues:
exclude-use-default: false
Expand All @@ -54,4 +52,7 @@ issues:
- dupl
- errorlint
path: "_test.go"
- linters:
- gocritic
text: "newDeref: replace `\\*new"

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#GOLANGCI_LINT_VERSION := "v1.44.2" # Optional configuration to pinpoint golangci-lint version.
#GOLANGCI_LINT_VERSION := "v1.46.2" # Optional configuration to pinpoint golangci-lint version.

# The head of Makefile determines location of dev-go to include standard targets.
GO ?= go
Expand Down
6 changes: 6 additions & 0 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ func (e Error) Unwrap() error {

return e.Value
}

type sentinelError string

func (s sentinelError) Error() string {
return string(s)
}
8 changes: 6 additions & 2 deletions generic_go1.18.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
"fmt"
)

// ErrInvalidType is returned on port type assertion error.
const ErrInvalidType = sentinelError("invalid type")

// IOInteractorOf is an IOInteractor with parametrized input/output types.
type IOInteractorOf[i, o any] struct {
IOInteractor

Expand All @@ -30,12 +34,12 @@ func NewInteractor[i, o any](interact func(ctx context.Context, input i, output
u.Interactor = Interact(func(ctx context.Context, input, output any) error {
inp, ok := input.(i)
if !ok {
return fmt.Errorf("invalid input type received: %T, expected: %T", input, u.Input)
return fmt.Errorf("%w of input: %T, expected: %T", ErrInvalidType, input, u.Input)
}

out, ok := output.(*o)
if !ok {
return fmt.Errorf("invalid output type received: %T, expected: %T", output, u.Output)
return fmt.Errorf("%w f output: %T, expected: %T", ErrInvalidType, output, u.Output)
}

return interact(ctx, inp, out)
Expand Down
13 changes: 10 additions & 3 deletions generic_go1.18_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ import (
)

func TestNewIOI_classic(t *testing.T) {
u := usecase.NewIOI(*new(int), new(string), func(ctx context.Context, input, output interface{}) error {
in := input.(int)
out := output.(*string)
u := usecase.NewIOI(0, new(string), func(ctx context.Context, input, output interface{}) error {
in, ok := input.(int)
assert.True(t, ok)

out, ok := output.(*string)
assert.True(t, ok)

*out = strconv.Itoa(in)

Expand All @@ -25,6 +28,7 @@ func TestNewIOI_classic(t *testing.T) {
ctx := context.Background()

var out string

assert.NoError(t, u.Interact(ctx, 123, &out))
assert.Equal(t, "123", out)
}
Expand All @@ -41,10 +45,13 @@ func TestNewInteractor(t *testing.T) {
ctx := context.Background()

var out string

assert.NoError(t, u.Interact(ctx, 123, &out))
assert.Equal(t, "123", out)

out = ""
assert.NoError(t, u.Invoke(ctx, 123, &out))
assert.Equal(t, "123", out)

assert.Equal(t, "invalid type", usecase.ErrInvalidType.Error())
}
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ module github.com/swaggest/usecase
go 1.18

require (
github.com/bool64/dev v0.2.7
github.com/stretchr/testify v1.7.0
github.com/bool64/dev v0.2.12
github.com/stretchr/testify v1.7.1
)

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
gopkg.in/yaml.v3 v3.0.0 // indirect
)
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
github.com/bool64/dev v0.2.7 h1:Zs1mCSJJwe8zBGLrlQ6pjuVUJjQtYbQslvxBwlzrYqo=
github.com/bool64/dev v0.2.7/go.mod h1:/csLrm+4oDSsKJRIVS0mrywAonLnYKFG8RvGT7Jh9b8=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/bool64/dev v0.2.12 h1:XXXE1Eh2//Dmp1hr+SqjxIXOEjq6D3Y5SwbGowpIK4I=
github.com/bool64/dev v0.2.12/go.mod h1:/csLrm+4oDSsKJRIVS0mrywAonLnYKFG8RvGT7Jh9b8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 comments on commit 7ca847b

Please sign in to comment.