Skip to content

Commit

Permalink
update for go 1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Morelly committed Oct 25, 2022
1 parent ec65c5f commit 3ac3216
Show file tree
Hide file tree
Showing 20 changed files with 1,064 additions and 244 deletions.
31 changes: 21 additions & 10 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,34 @@ jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
- uses: actions/checkout@v3

- uses: actions/setup-go@v3
with:
go-version: '1.19'

- name: go get
run: go get ./...

- name: go mod tidy
run: go mod tidy

- name: Checkout
uses: actions/checkout@v2
-
name: Set up QEMU

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Login to DockerHub

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push

- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: 1.19
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
Expand Down
21 changes: 17 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,22 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: actions/setup-go@v3
with:
go-version: '1.19'

- name: go get
run: go get ./...

- name: go mod tidy
run: go mod tidy

- name: golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: v1.43.0
args: -c .golang-ci.yml
version: v1.50.0
args: -c .golang-ci.yml -v --timeout=5m
env:
GO111MODULES: off
29 changes: 0 additions & 29 deletions .github/workflows/semantic-releaser.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.16.x, 1.17.x]
go-version: [1.19.x]
os: [ubuntu-latest, macos-latest]

runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
image: tetafro/golang-gcc:1.15-alpine
image: tetafro/golang-gcc:1.19-alpine

stages:
- lint
Expand Down
13 changes: 12 additions & 1 deletion .golang-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,15 @@ linters:
- interfacer
- maligned
- scopelint
- golint
- golint
- varcheck
- nosnakecase
- deadcode
- ifshort
- structcheck
- rowserrcheck
- sqlclosecheck
- structcheck
- wastedassign
- exhaustruct
- nolintlint
7 changes: 1 addition & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
repos:
# golang pre commits
- repo: https://github.com/dnephin/pre-commit-golang
rev: master
rev: v0.5.1
hooks:
- id: go-fmt
- id: go-vet
- id: go-lint
- id: go-imports
- id: go-cyclo
args: [-over=15]
- id: no-go-testing
- id: golangci-lint
args: ["--skip-dirs=vendor -c .golang-ci.yml ."]
- id: go-critic
- id: go-unit-tests
- id: go-build
- id: go-mod-tidy
Expand Down
45 changes: 0 additions & 45 deletions .releaserrc.json

This file was deleted.

4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.16-alpine
FROM golang:1.19-alpine

WORKDIR /app

Expand All @@ -8,6 +8,6 @@ RUN go mod download

COPY . .

RUN go build -ldflags "-X main.version=1.0.0" -o golang-cli-template
RUN go build -ldflags "-s -w -X main.version=1.0.0" -o golang-cli-template

CMD [ "./golang-cli-template" ]
19 changes: 8 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ install: ## install golang binary
run: ## run the app
@go run -ldflags "-X main.version=$(shell git describe --abbrev=0 --tags)" main.go

.PHONY: fmtcheck
fmtcheck: ## run gofmt and print detected files
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"
.PHONY: bootstrap
bootstrap: ## install build deps
go generate -tags tools tools/tools.go

PHONY: test
test: ## run go tests
go test -v ./...
test: clean ## display test coverage
go test -json -v ./... | gotestfmt

PHONY: clean
clean: ## clean up environment
Expand All @@ -37,16 +37,13 @@ cover: ## display test coverage

PHONY: fmt
fmt: ## format go files
gofumpt -w -s .
gofumpt -w .
gci write .

PHONY: lint
lint: ## lint go files
golangci-lint run -c .golang-ci.yml

PHONY: lint-fix
lint-fix: ## fix
golangci-lint run -c .golang-ci.yml --fix

.PHONY: docker-build
docker-build: ## dockerize golang application
@docker build --tag $(projectname) .
Expand All @@ -57,5 +54,5 @@ docker-run:

.PHONY: pre-commit
pre-commit: ## run pre-commit hooks
pre-commit run
pre-commit run --all-files

12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ This template serves as a starting point for golang commandline applications it
- [Makefile](Makefile) - with various useful targets and documentation (see Makefile Targets)
- [Github Pages](_config.yml) using [jekyll-theme-minimal](https://github.com/pages-themes/minimal) (checkout [https://falcosuessgott.github.io/golang-cli-template/](https://falcosuessgott.github.io/golang-cli-template/))
- [pre-commit-hooks](https://pre-commit.com/) for formatting and validating code before committing
- [semantic-releaser](https://semantic-release.gitbook.io/semantic-release/)

# Project Layout
* [assets/](https://pkg.go.dev/github.com/FalcoSuessgott/golang-cli-template/assets) => docs, images, etc
* [cmd/](https://pkg.go.dev/github.com/FalcoSuessgott/golang-cli-template/cmd) => commandline configurartions (flags, subcommands)
* [pkg/](https://pkg.go.dev/github.com/FalcoSuessgott/golang-cli-template/pkg) => packages that are okay to import for other projects
* [internal/](https://pkg.go.dev/github.com/FalcoSuessgott/golang-cli-template/pkg) => packages that are only for project internal purposes
- [`tools/`](tools/) => for automatically shipping all required dependencies when running `go get` (or `make bootstrap`) such as `golang-ci-lint` (see: https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module)
)

# How to use this template
```sh
Expand Down Expand Up @@ -62,29 +63,28 @@ Use "golang-cli-template [command] --help" for more information about a command.
```

```sh
$> golang-cli-template example 2 5 -a
$> golang-cli-template example 2 5 --add
7

$> golang-cli-template example 2 5 -m
$> golang-cli-template example 2 5 --multiply
10
```

# Makefile Targets
```sh
$> make
bootstrap install build deps
build build golang binary
clean clean up environment
cover display test coverage
docker-build dockerize golang application
fmtcheck run gofmt and print detected files
fmt format go files
help list makefile targets
install install golang binary
lint-fix fix
lint lint go files
pre-commit run pre-commit hooks
run run the app
test run go tests
test display test coverage
```

# Contribute
Expand Down
4 changes: 2 additions & 2 deletions cmd/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"bytes"
"io/ioutil"
"io"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -49,7 +49,7 @@ func TestExampleCommand(t *testing.T) {
cmd.SetOut(b)

err := cmd.Execute()
out, _ := ioutil.ReadAll(b)
out, _ := io.ReadAll(b)

if tc.err {
assert.Error(t, err, tc.name)
Expand Down
4 changes: 2 additions & 2 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"bytes"
"io/ioutil"
"io"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -19,7 +19,7 @@ func TestRootCommandOutput(t *testing.T) {
cmdErr := cmd.Execute()
require.NoError(t, cmdErr)

out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
require.NoError(t, err)

assert.Equal(t, "golang-cli project template demo application\n\n"+cmd.UsageString(), string(out))
Expand Down
4 changes: 2 additions & 2 deletions cmd/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -19,7 +19,7 @@ func TestVersionCommand(t *testing.T) {
err := cmd.Execute()
require.NoError(t, err)

out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
require.NoError(t, err)

assert.Equal(t, fmt.Sprintln(version), string(out))
Expand Down
Loading

0 comments on commit 3ac3216

Please sign in to comment.