Skip to content

Commit

Permalink
Use nhatthm/gh-actions (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhatthm authored Jan 18, 2024
1 parent 57e15bd commit 60502fd
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 75 deletions.
44 changes: 9 additions & 35 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
40 changes: 19 additions & 21 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
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 @@ -29,6 +29,7 @@ linters-settings:
linters:
enable-all: true
disable:
- depguard
- deadcode
- exhaustivestruct
- exhaustruct
Expand All @@ -49,6 +50,7 @@ linters:
- scopelint
- structcheck
- tagliatelle
- testifylint
- varcheck
- varnamelen
- wastedassign
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 60502fd

Please sign in to comment.