Skip to content

Commit

Permalink
Use nhatthm/gh-actions (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhatthm authored Jan 22, 2024
1 parent def6338 commit 0a5f620
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 78 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ indent_style = space

[*.feature]
indent_style = space

[.github/workflows/*.{yml,yaml}]
indent_style = space
indent_size = 2
42 changes: 10 additions & 32 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: lint

on:
Expand All @@ -6,44 +7,21 @@ on:
- master
pull_request:

env:
GO_VERSION: 1.19.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 }}
- name: Checkout code
uses: nhatthm/gh-actions/checkout@master

- id: vars
run: |
make $GITHUB_OUTPUT
- 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.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
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
48 changes: 25 additions & 23 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: test

on:
Expand All @@ -8,53 +9,54 @@ on:

env:
GO111MODULE: "on"
GO_LATEST_VERSION: 1.19.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 ]
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@v4
- 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 }}

- name: Upload code coverage (features)
if: matrix.go-version == env.GO_LATEST_VERSION
uses: codecov/codecov-action@v3
uses: nhatthm/gh-actions/codecov@master
with:
files: ./features.coverprofile
file: ./features.coverprofile
flags: featurestests-${{ runner.os }}
23 changes: 6 additions & 17 deletions .github/workflows/update-registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,20 @@ name: 'update-registry'

on:
push:
branches:
- master
tags:
- v*
workflow_dispatch:

env:
MODULE_NAME: consolesteps

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: Checkout code
uses: nhatthm/gh-actions/checkout@master

- name: notify ${{ matrix.registry }}
uses: benc-uk/workflow-dispatch@v121
- 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'
5 changes: 5 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ linters-settings:
linters:
enable-all: true
disable:
- deadcode
- depguard
- exhaustivestruct
- exhaustruct
- forbidigo
Expand All @@ -38,12 +40,15 @@ linters:
- nolintlint # https://github.com/golangci/golangci-lint/issues/3063
- paralleltest
- scopelint
- structcheck
- tagliatelle
- testpackage
- varcheck
- varnamelen
- wrapcheck

issues:
max-same-issues: 20
exclude-use-default: false
exclude-rules:
- linters:
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
MODULE_NAME = consolesteps

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
4 changes: 2 additions & 2 deletions assertions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package consolesteps
import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestTestingT_LastError(t *testing.T) {
Expand All @@ -12,5 +12,5 @@ func TestTestingT_LastError(t *testing.T) {
tee := teeError()
tee.Errorf("error: %s", "unknown")

assert.EqualError(t, tee.LastError(), `error: unknown`)
require.EqualError(t, tee.LastError(), `error: unknown`)
}
3 changes: 2 additions & 1 deletion features/bootstrap/godog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/cucumber/godog"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.nhat.io/consolesteps"
)
Expand Down Expand Up @@ -66,7 +67,7 @@ func RunSuite(t *testing.T, path string, featureContext func(t *testing.T, ctx *
var paths []string

files, err := os.ReadDir(filepath.Clean(path))
assert.NoError(t, err)
require.NoError(t, err)

paths = make([]string, 0, len(files))

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-memdb v1.3.4 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b
github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2IGE=
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c=
github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hinshun/vt10x v0.0.0-20220301184237-5011da428d02 h1:AgcIVYPa6XJnU3phs104wLj8l5GEththEw6+F79YsIY=
github.com/hinshun/vt10x v0.0.0-20220301184237-5011da428d02/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
Expand Down

0 comments on commit 0a5f620

Please sign in to comment.