Skip to content

Commit

Permalink
Use nhatthm/gh-actions (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhatthm authored Jan 18, 2024
1 parent 0b12cc0 commit 504c23f
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 83 deletions.
44 changes: 9 additions & 35 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,49 +1,23 @@
name: lint

on:
push:
branches:
- master
pull_request:

env:
GO_VERSION: "1.20.x"

jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Checkout code
uses: nhatthm/gh-actions/checkout@master
- name: Setup
uses: nhatthm/gh-actions/find-go-version@master
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

- id: vars
run: |
make $GITHUB_OUTPUT
- name: lint
uses: golangci/golangci-lint-action@v3
uses: nhatthm/gh-actions/setup-go@master
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: ${{ steps.vars.outputs.GOLANGCI_LINT_VERSION }}

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the action will use pre-installed Go.
# skip-go-installation: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
go-version: ${{ env.GO_LATEST_VERSION }}
- name: Lint
uses: nhatthm/gh-actions/golangci-lint@master
39 changes: 19 additions & 20 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,36 @@ on:

env:
GO111MODULE: "on"
GO_LATEST_VERSION: "1.20.x"

jobs:
setup:
runs-on: ubuntu-latest
outputs:
go-latest-version: ${{ steps.find-go-version.outputs.go-latest-version }}
go-supported-versions: ${{ steps.find-go-version.outputs.go-supported-versions }}
steps:
- uses: nhatthm/gh-actions/checkout@master
- id: find-go-version
uses: nhatthm/gh-actions/find-go-version@master

test:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest ]
go-version: [ 1.18.x, 1.19.x , 1.20.x ]
go-version: ${{ fromJson(needs.setup.outputs.go-supported-versions) }}
runs-on: ${{ matrix.os }}
needs: [setup]
env:
GO_LATEST_VERSION: ${{ needs.setup.outputs.go-latest-version }}
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v4
uses: nhatthm/gh-actions/checkout@master

- name: Go cache
uses: actions/cache@v3
- name: Install Go
uses: nhatthm/gh-actions/setup-go@master
with:
# In order:
# * Module download cache
# * Build cache (Linux)
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ matrix.go-version }}-cache-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-cache
go-version: ${{ matrix.go-version }}

- name: Test
id: test
Expand All @@ -47,7 +46,7 @@ jobs:
- name: Upload code coverage
if: matrix.go-version == env.GO_LATEST_VERSION
uses: codecov/codecov-action@v3
uses: nhatthm/gh-actions/codecov@master
with:
files: ./unit.coverprofile
flags: unittests-${{ runner.os }}
19 changes: 4 additions & 15 deletions .github/workflows/update-registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,10 @@ on:
jobs:
notify:
runs-on: ubuntu-latest
strategy:
matrix:
registry: [ go.nhat.io, go-staging.nhat.io ]
steps:
- uses: actions/checkout@v4

- id: vars
run: |
make $GITHUB_OUTPUT
- name: notify ${{ matrix.registry }}
uses: benc-uk/workflow-dispatch@v121
- name: Checkout code
uses: nhatthm/gh-actions/checkout@master
- name: Notify registries
uses: nhatthm/gh-actions/notify-go-registries@master
with:
workflow: build
repo: nhatthm/${{ matrix.registry }}
token: ${{ secrets.REGISTRY_TOKEN }}
inputs: '{"modules": "${{ steps.vars.outputs.MODULE_NAME }}"}'
ref: 'master'
2 changes: 2 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ linters-settings:
linters:
enable-all: true
disable:
- depguard
- deadcode
- exhaustivestruct
- exhaustruct
Expand All @@ -41,6 +42,7 @@ linters:
- scopelint
- structcheck
- tagliatelle
- testifylint
- testpackage
- varcheck
- varnamelen
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ MODULE_NAME=httpmock

VENDOR_DIR = vendor

GOLANGCI_LINT_VERSION ?= v1.51.1
GOLANGCI_LINT_VERSION ?= v1.55.2

GO ?= go
GOLANGCI_LINT ?= $(shell go env GOPATH)/bin/golangci-lint-$(GOLANGCI_LINT_VERSION)
Expand Down
2 changes: 1 addition & 1 deletion expectation.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ type Expectation interface {

// ExpectationHandler handles the expectation.
type ExpectationHandler interface {
Handle(http.ResponseWriter, *http.Request, map[string]string) error
Handle(w http.ResponseWriter, r *http.Request, defaultHeaders map[string]string) error
}

var (
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ require (
github.com/bool64/shared v0.1.5 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/iancoleman/orderedmap v0.2.0 // indirect
github.com/iancoleman/orderedmap v0.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/swaggest/assertjson v1.7.0 // indirect
github.com/stretchr/objx v0.5.1 // indirect
github.com/swaggest/assertjson v1.9.0 // indirect
github.com/yudai/gojsondiff v1.0.0 // indirect
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
Expand Down
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
github.com/bool64/dev v0.2.17 h1:jE+T92oazAIV8fvMDJrKjsF1bzfr5XezZ8bM5GS1Cl0=
github.com/bool64/dev v0.2.29 h1:x+syGyh+0eWtOzQ1ItvLzOGIWyNWnyjXpHIcpF2HvL4=
github.com/bool64/shared v0.1.5 h1:fp3eUhBsrSjNCQPcSdQqZxxh9bBwrYiZ+zOKFkM0/2E=
github.com/bool64/shared v0.1.5/go.mod h1:081yz68YC9jeFB3+Bbmno2RFWvGKv1lPKkMP6MHJlPs=
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/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
github.com/iancoleman/orderedmap v0.2.0 h1:sq1N/TFpYH++aViPcaKjys3bDClUEU7s5B+z6jq8pNA=
github.com/iancoleman/orderedmap v0.2.0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA=
github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc=
github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand All @@ -24,15 +24,17 @@ github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.1 h1:4VhoImhV/Bm0ToFkXFi8hXNXwpDRZ/ynw3amt82mzq0=
github.com/stretchr/objx v0.5.1/go.mod h1:/iHQpkQwBD6DLUmQ4pE+s1TXdob1mORJ4/UFdrifcy0=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/swaggest/assertjson v1.7.0 h1:SKw5Rn0LQs6UvmGrIdaKQbMR1R3ncXm5KNon+QJ7jtw=
github.com/swaggest/assertjson v1.7.0/go.mod h1:vxMJMehbSVJd+dDWFCKv3QRZKNTpy/ktZKTz9LOEDng=
github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ=
github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU=
github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA=
github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg=
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M=
Expand Down
2 changes: 1 addition & 1 deletion test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package test
type T interface {
Errorf(format string, args ...any)
FailNow()
Cleanup(func())
Cleanup(f func())
}

type noOp struct{}
Expand Down
2 changes: 1 addition & 1 deletion value/value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestString_Success(t *testing.T) {
},
{
scenario: "fmt.Stringer",
input: bytes.NewBuffer([]byte(expected)),
input: bytes.NewBufferString(expected),
},
}

Expand Down

0 comments on commit 504c23f

Please sign in to comment.