From 1d5220c4b5f9eecbb6fbc35f83593bf4865a803b Mon Sep 17 00:00:00 2001 From: Nhat Date: Sun, 21 Jan 2024 11:59:06 +0100 Subject: [PATCH] Use `nhatthm/gh-actions` (#35) --- .github/workflows/lint.yaml | 45 ++++++---------------- .github/workflows/test.yaml | 53 +++++++++++++++----------- .github/workflows/update-registry.yaml | 19 ++++----- .golangci.yaml | 11 ++---- Makefile | 9 +++-- go.mod | 3 ++ go.sum | 5 ++- 7 files changed, 64 insertions(+), 81 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index a4d1e38..adc1718 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -1,50 +1,27 @@ +--- name: lint + on: push: branches: - master pull_request: -env: - GO111MODULE: "on" - GO_VERSION: "1.21.x" - jobs: lint: name: lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - - name: Install Go - uses: actions/setup-go@v5 - with: - go-version: ${{ env.GO_VERSION }} + - name: Checkout code + uses: nhatthm/gh-actions/checkout@master - - id: get-lint-version - run: | - make golangci-lint-version + - name: Setup + uses: nhatthm/gh-actions/find-go-version@master - - name: lint - uses: golangci/golangci-lint-action@v3 + - name: Install Go + 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.get-lint-version.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 + go-version: ${{ env.GO_LATEST_VERSION }} - # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. - # skip-build-cache: true + - name: Lint + uses: nhatthm/gh-actions/golangci-lint@master diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 28825e6..6de658c 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,3 +1,4 @@ +--- name: test on: @@ -8,46 +9,54 @@ on: env: GO111MODULE: "on" - GO_LATEST_VERSION: "1.21.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: + - name: Checkout code + uses: nhatthm/gh-actions/checkout@master + + - id: find-go-version + name: 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.17.x, 1.18.x, 1.19.x, 1.20.x, 1.21.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 run: | make test - - name: Upload code coverage + - name: Upload code coverage (unit) 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 }} + + #- name: Upload code coverage (features) + # if: matrix.go-version == env.GO_LATEST_VERSION + # uses: nhatthm/gh-actions/codecov@master + # with: + # file: ./features.coverprofile + # flags: featurestests-${{ runner.os }} diff --git a/.github/workflows/update-registry.yaml b/.github/workflows/update-registry.yaml index dae38b6..013492f 100644 --- a/.github/workflows/update-registry.yaml +++ b/.github/workflows/update-registry.yaml @@ -3,25 +3,20 @@ name: 'update-registry' on: push: + branches: + - master tags: - v* workflow_dispatch: -env: - MODULE_NAME: aferomock - jobs: notify: runs-on: ubuntu-latest - strategy: - matrix: - registry: [ go.nhat.io, go-staging.nhat.io ] steps: - - 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": "${{ env.MODULE_NAME }}"}' - ref: 'master' diff --git a/.golangci.yaml b/.golangci.yaml index d9adf3f..f2732b0 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -3,13 +3,6 @@ run: tests: true linters-settings: - depguard: - rules: - Main: - files: - - "!**.go" - allow: - - $gostd errcheck: check-type-assertions: true check-blank: true @@ -28,6 +21,7 @@ linters: enable-all: true disable: - deadcode + - depguard - exhaustivestruct - exhaustruct - forbidigo @@ -41,9 +35,9 @@ linters: - ireturn - lll - maligned - - nolintlint # https://github.com/golangci/golangci-lint/issues/3063 - nonamedreturns - nosnakecase + - nolintlint # https://github.com/golangci/golangci-lint/issues/3063 - paralleltest - scopelint - structcheck @@ -55,6 +49,7 @@ linters: - wrapcheck issues: + max-same-issues: 20 exclude-use-default: false exclude-rules: - linters: diff --git a/Makefile b/Makefile index a1a1c54..0b36074 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +MODULE_NAME=aferomock + BIN_DIR = bin VENDOR_DIR = vendor @@ -24,9 +26,10 @@ test-unit: @echo ">> unit test" @$(GO) test -gcflags=-l -coverprofile=unit.coverprofile -covermode=atomic -race ./... -.PHONY: golangci-lint-version -golangci-lint-version: - @echo "::set-output name=GOLANGCI_LINT_VERSION::$(GOLANGCI_LINT_VERSION)" +.PHONY: $(GITHUB_OUTPUT) +$(GITHUB_OUTPUT): + @echo "MODULE_NAME=$(MODULE_NAME)" >>"$@" + @echo "GOLANGCI_LINT_VERSION=$(GOLANGCI_LINT_VERSION)" >>"$@" $(GOLANGCI_LINT): @echo "$(OK_COLOR)==> Installing golangci-lint $(GOLANGCI_LINT_VERSION)$(NO_COLOR)"; \ diff --git a/go.mod b/go.mod index b38d595..59b67b9 100644 --- a/go.mod +++ b/go.mod @@ -9,8 +9,11 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect + github.com/kr/pretty v0.3.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/rogpeppe/go-internal v1.9.0 // indirect github.com/stretchr/objx v0.5.1 // indirect golang.org/x/text v0.14.0 // indirect + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 8a8a29c..1ec1cb9 100644 --- a/go.sum +++ b/go.sum @@ -1354,9 +1354,11 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02 github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lyft/protoc-gen-star v0.6.0/go.mod h1:TGAoBVkt8w7MPG72TrKIu85MIdXwDuzJYeZuUPFPNwA= github.com/lyft/protoc-gen-star v0.6.1/go.mod h1:TGAoBVkt8w7MPG72TrKIu85MIdXwDuzJYeZuUPFPNwA= @@ -1390,6 +1392,7 @@ github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qq github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58/go.mod h1:6lfFZQK844Gfx8o5WFuvpxWRwnSoipWe/p622j1v06w= github.com/ruudk/golang-pdf417 v0.0.0-20201230142125-a7e3863a1245/go.mod h1:pQAZKsJ8yyVxGRWYNEm9oFB8ieLgKFnamEyDmSA0BRk= @@ -1401,7 +1404,6 @@ github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= 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= @@ -2180,7 +2182,6 @@ google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw google.golang.org/protobuf v1.29.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -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/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=