From 60502fd369c53051807fba01338944f7167bd9c3 Mon Sep 17 00:00:00 2001 From: Nhat Date: Thu, 18 Jan 2024 15:52:41 +0100 Subject: [PATCH] Use `nhatthm/gh-actions` (#17) --- .github/workflows/lint.yaml | 44 ++++++-------------------- .github/workflows/test.yaml | 40 +++++++++++------------ .github/workflows/update-registry.yaml | 19 +++-------- .golangci.yaml | 2 ++ Makefile | 4 +-- go.mod | 2 +- go.sum | 4 ++- 7 files changed, 40 insertions(+), 75 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 1bd612f..d0c8dab 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -7,44 +7,18 @@ on: - master pull_request: -env: - GO_VERSION: "1.20.x" - jobs: lint: name: lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - - 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 + - name: Checkout code + uses: nhatthm/gh-actions/checkout@master + - name: Setup + uses: nhatthm/gh-actions/find-go-version@master + - 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.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 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e3e9965..e0aa835 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -9,46 +9,44 @@ 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.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 run: | make test - 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 }} diff --git a/.github/workflows/update-registry.yaml b/.github/workflows/update-registry.yaml index d3cc60a..8a34643 100644 --- a/.github/workflows/update-registry.yaml +++ b/.github/workflows/update-registry.yaml @@ -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' diff --git a/.golangci.yaml b/.golangci.yaml index 09bf887..ccb44de 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -29,6 +29,7 @@ linters-settings: linters: enable-all: true disable: + - depguard - deadcode - exhaustivestruct - exhaustruct @@ -49,6 +50,7 @@ linters: - scopelint - structcheck - tagliatelle + - testifylint - varcheck - varnamelen - wastedassign diff --git a/Makefile b/Makefile index d36e324..8057728 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ -MODULE_NAME=cookiejar +MODULE_NAME = cookiejar VENDOR_DIR = vendor GITHUB_OUTPUT ?= /dev/null -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) diff --git a/go.mod b/go.mod index a08ded4..6f4da7a 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/nxadm/tail v1.4.8 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/sergi/go-diff v1.1.0 // indirect - github.com/stretchr/objx v0.5.0 // indirect + github.com/stretchr/objx v0.5.1 // indirect github.com/yudai/gojsondiff v1.0.0 // indirect github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/go.sum b/go.sum index b554918..7bfed34 100644 --- a/go.sum +++ b/go.sum @@ -33,11 +33,13 @@ 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= 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.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ=