Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nhatthm committed Aug 29, 2022
0 parents commit b2831ec
Show file tree
Hide file tree
Showing 23 changed files with 1,794 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
insert_final_newline = true
max_line_length = 160
tab_width = 4
trim_trailing_whitespace = true

[Makefile]
indent_style = space

[*.feature]
indent_style = space
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "gomod" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
49 changes: 49 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: lint

on:
push:
branches:
- master
pull_request:

env:
GO_VERSION: "1.19.x"

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

- uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}

- id: get-lint-version
run: |
make golangci-lint-version
- name: lint
uses: golangci/golangci-lint-action@v3
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

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
60 changes: 60 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: test

on:
push:
branches:
- master
pull_request:

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

jobs:
test:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest ]
go-version: [ 1.17.x, 1.18.x, 1.19.x ]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v3

- name: Go cache
uses: actions/cache@v3
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
- 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
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
with:
files: ./features.coverprofile
flags: featuretests-${{ runner.os }}
29 changes: 29 additions & 0 deletions .github/workflows/update-registry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
name: 'update-registry'

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

env:
MODULE_NAME: surveysteps

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@v1
with:
workflow: build
repo: nhatthm/${{ matrix.registry }}
token: ${{ secrets.REGISTRY_TOKEN }}
inputs: '{"modules": "${{ env.MODULE_NAME }}"}'
ref: 'master'
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
vendor/

*.coverprofile
56 changes: 56 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# See https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml
run:
tests: true

linters-settings:
errcheck:
check-type-assertions: true
check-blank: true
gocyclo:
min-complexity: 20
dupl:
threshold: 100
misspell:
locale: US
unused:
check-exported: false
unparam:
check-exported: true

linters:
enable-all: true
disable:
- exhaustivestruct
- exhaustruct
- forbidigo
- forcetypeassert
- gci
- gochecknoglobals
- golint
- gomnd
- ifshort
- interfacer
- ireturn
- lll
- maligned
- nonamedreturns
- nosnakecase
- nolintlint # https://github.com/golangci/golangci-lint/issues/3063
- paralleltest
- scopelint
- tagliatelle
- testpackage
- varnamelen
- wrapcheck

issues:
exclude-use-default: false
exclude-rules:
- linters:
- dupl
- funlen
- goconst
- goerr113
- gomnd
- noctx
path: "_test.go"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Nhat

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
VENDOR_DIR = vendor

GOLANGCI_LINT_VERSION ?= v1.48.0

GO ?= go
GOLANGCI_LINT ?= $(shell go env GOPATH)/bin/golangci-lint-$(GOLANGCI_LINT_VERSION)

.PHONY: $(VENDOR_DIR)
$(VENDOR_DIR):
@mkdir -p $(VENDOR_DIR)
@$(GO) mod vendor

.PHONY: lint
lint: $(GOLANGCI_LINT) $(VENDOR_DIR)
@$(GOLANGCI_LINT) run -c .golangci.yaml

.PHONY: test
test: test-unit test-integration

## Run unit tests
.PHONY: test-unit
test-unit:
@echo ">> unit test"
@$(GO) test -gcflags=-l -coverprofile=unit.coverprofile -covermode=atomic -race ./...

.PHONY: test-integration
test-integration:
@echo ">> integration test"
@$(GO) test ./features/... -gcflags=-l -coverprofile=features.coverprofile -coverpkg ./... -godog -race

.PHONY: golangci-lint-version
golangci-lint-version:
@echo "::set-output name=GOLANGCI_LINT_VERSION::$(GOLANGCI_LINT_VERSION)"

$(GOLANGCI_LINT):
@echo "$(OK_COLOR)==> Installing golangci-lint $(GOLANGCI_LINT_VERSION)$(NO_COLOR)"; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./bin "$(GOLANGCI_LINT_VERSION)"
@mv ./bin/golangci-lint $(GOLANGCI_LINT)
Loading

0 comments on commit b2831ec

Please sign in to comment.