diff --git a/.golangci.yml b/.golangci.yml index 36afccc..37cc2b8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,6 @@ linters-settings: goimports: - local-prefixes: github.com/golang-templates/library + local-prefixes: github.com/golang-templates/seed golint: min-confidence: 0 misspell: diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 1404991..0d739d6 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -4,36 +4,36 @@ "version": "2.0.0", "tasks": [ { - "label": "All", + "label": "all", "type": "shell", - "command": "mage -v all", + "command": "make all", "problemMatcher": [ "$go" ], "group": "build" }, { - "label": "Build", + "label": "build", "type": "shell", - "command": "mage -v build", + "command": "make build", "problemMatcher": [ "$go" ], "group": "build" }, { - "label": "Lint", + "label": "lint", "type": "shell", - "command": "mage -v lint", + "command": "make lint", "problemMatcher": [ "$go" ], "group": "build" }, { - "label": "Test", + "label": "test", "type": "shell", - "command": "mage -v test", + "command": "make test", "problemMatcher": [ "$go" ], diff --git a/Dockerfile b/Dockerfile index 1d4bc53..8cd4b2e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,4 @@ # go FROM golang:1.14.2 -# mage -RUN GO111MODULE=on go get github.com/magefile/mage@v1.9.0 # golangci-lint RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.26.0 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bfc8ee5 --- /dev/null +++ b/Makefile @@ -0,0 +1,28 @@ +.DEFAULT_GOAL := help + +.PHONY: all +all: ## full build: build, lint, test +all: build lint test + +.PHONY: build +build: ## go build + $(call print-target) + go build ./... + +.PHONY: lint +lint: ## golangci-lint + $(call print-target) + golangci-lint run + +.PHONY: test +test: ## go test with race detector and code covarage + $(call print-target) + go test -race -covermode=atomic + +.PHONY: help +help: + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +define print-target + @echo "Executing target: \033[36m$@\033[0m" +endef diff --git a/README.md b/README.md index e63a6b0..d60c871 100644 --- a/README.md +++ b/README.md @@ -1,51 +1,63 @@ -# Go Library Template +# Go Project Template -[![Build Status](https://github.com/golang-templates/library/workflows/build/badge.svg)](https://github.com/golang-templates/library/actions?query=workflow%3Abuild) -[![GoDoc](https://godoc.org/github.com/golang-templates/library?status.svg)](https://godoc.org/github.com/golang-templates/library) -[![GitHub Release](https://img.shields.io/github/release/golang-templates/library.svg)](https://github.com/golang-templates/library/releases) -[![Go Report Card](https://goreportcard.com/badge/github.com/golang-templates/library)](https://goreportcard.com/report/github.com/golang-templates/library) +[![Build Status](https://github.com/golang-templates/seed/workflows/build/badge.svg)](https://github.com/golang-templates/seed/actions?query=workflow%3Abuild) +[![GoDoc](https://godoc.org/github.com/golang-templates/seed?status.svg)](https://godoc.org/github.com/golang-templates/seed) +[![GitHub Release](https://img.shields.io/github/release/golang-templates/seed.svg)](https://github.com/golang-templates/seed/releases) +[![Go Report Card](https://goreportcard.com/badge/github.com/golang-templates/seed)](https://goreportcard.com/report/github.com/golang-templates/seed) -This is GitHub project template for a Go library. It has been created for ease-of-use for anyone who wants to: +This is GitHub project template for Go. It has been created for ease-of-use for anyone who wants to: - quickly get into Go without losing too much time on environment setup, -- create a new repoisitory with basic Continous Integration, -- write Go code on Linux, MacOS, Windows. +- create a new repoisitory with basic Continous Integration. It includes: - [Visual Studio Code](https://code.visualstudio.com) configuration with [Go](https://code.visualstudio.com/docs/languages/go) and [Remote Container](https://code.visualstudio.com/docs/remote/containers) support, - dependency management using [Go Modules](https://github.com/golang/go/wiki/Modules), - linting with [GolangCI-Lint](https://github.com/golangci/golangci-lint), -- build automation via [Mage](https://magefile.org), [Docker](https://docs.docker.com/engine), [Docker Compose](https://docs.docker.com/compose), [GitHub Actions](https://github.com/features/actions). +- build automation via [Make](https://www.gnu.org/software/make), [Docker](https://docs.docker.com/engine), [Docker Compose](https://docs.docker.com/compose), [GitHub Actions](https://github.com/features/actions). `Star` this project if you find it valuable and worth maintaining. ## Usage 1. Click the `Use this template` button (alt. clone or download this repository). -1. Replace all occurences of `golang-templates/library` to `your_org/repo_name` in all files. +1. Replace all occurences of `golang-templates/seed` to `your_org/repo_name` in all files. 1. Change [LICENSE](LICENSE) and [README.md](README.md). -### Setup Development Environment +### Setup Development Environment - Visual Studio Code -Take notice that this project is build in a way that gives developers a lot of freedom on development environments setup. Below you can find proposals when using Visual Studio Code. +#### Visual Studio Code - Bare-metal -- **Bare metal:** See [Dockerfile](Dockerfile) for Mage and GolangCI-Lint installation commands. -- **Containers:** [Instructions](https://code.visualstudio.com/docs/remote/containers). -- **Remote via SSH**: [Instructions](https://code.visualstudio.com/docs/remote/ssh). +1. Install [Go](https://golang.org/doc/install) and [Go extension](https://code.visualstudio.com/docs/languages/go). +1. Visual Studio Code: `View` → `Command Pallete... (F1)` → Select `Go: Install/Update Tools`. +1. See [Dockerfile](Dockerfile) for GolangCI-Lint installation command. + +#### Visual Studio Code - Development Container + +1. [Setup Development inside a Container](https://code.visualstudio.com/docs/remote/containers#_getting-started). +1. Visual Studio Code inside Container: `View` → `Command Pallete... (F1)` → Select `Go: Install/Update Tools`. +1. See [Dockerfile](Dockerfile) for GolangCI-Lint installation command. + +#### Visual Studio Code - SSH + +1. [Setup Remote Development using SSH](https://code.visualstudio.com/docs/remote/ssh#_getting-started). +1. On remote machine: install [Go](https://golang.org/doc/install) and [Go extension](https://code.visualstudio.com/docs/languages/go). +1. Visual Studio Code: `View` → `Command Pallete... (F1)` → Select `Go: Install/Update Tools`. +1. See [Dockerfile](Dockerfile) for GolangCI-Lint installation command. ### Build -- Terminal: `mage -v all`. +- Terminal: `make all`. - Visual Studio Code: `Terminal` → `Run Build Task... (CTRL+ALT+B)` → Select `All`. - Terminal: `docker-compose up --abort-on-container-exit`. This command is executed by CI build (GitHub Action workflow). ### Maintainance 1. `Watch` this project to get notified about new releases, issues, etc. -1. Update Go, Mage and GolangCI-Lint version in [Dockerfile](Dockerfile). Take notice that when working on bare metal or via SSH, then you should also to do it manually on your machine. +1. Update Go and GolangCI-Lint version in [Dockerfile](Dockerfile). 1. Configure linters via [.golangci.yml](.golangci.yml). -1. Develop Mage targets in [magefile.go](magefile.go) and assosiated tasks in [.vscode/tasks.json](.vscode/tasks.json). +1. Develop Make targets in [Makefile](Makefile) and assosiated tasks in [.vscode/tasks.json](.vscode/tasks.json). Notable files: @@ -55,49 +67,17 @@ Notable files: - [.golangci.yml](.golangci.yml) - GolangCI-Lint configuration - [docker-compose.yml](docker-compose.yml) - Compose file used in [CI build](.github/workflows/build.yml) - [Dockerfile](Dockerfile) - Builder image used in [docker-compose.yml](docker-compose.yml) and [devcontainer.json](.devcontainer/devcontainer.json) -- [magefile.go](magefile.go) - Mage targets used in [docker-compose.yml](docker-compose.yml) and [.vscode/tasks.json](.vscode/tasks.json) +- [Makefile](Makefile) - Make targets used in [docker-compose.yml](docker-compose.yml) and [.vscode/tasks.json](.vscode/tasks.json) ## FAQ -### Why Mage instead of Make - -Here is [why](https://github.com/magefile/mage#why). -However, updating to Make is pretty straightforward. - -1. Replace [magefile.go](magefile.go) with a `Makefile` file: - -```make -.DEFAULT_GOAL := help - -.PHONY: all -all: ## full build: build, lint, test -all: build lint test - -.PHONY: build -build: ## go build - go build ./... - -.PHONY: lint -lint: ## golangci-lint - golangci-lint run - -.PHONY: test -test: ## go test with race detector and code covarage - go test -race -covermode=atomic - -.PHONY: help -help: - @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' -``` - -2. Remove Mage installation from [Dockerfile](Dockerfile). -1. Update [docker-compose.yml](docker-compose.yml) and [.vscode/tasks.json](.vscode/tasks.json) to use `make`. +### Make does not work on Windows -If you want to use Make on bare-metal Windows, then you can use [WSL (Windows Subsystem for Linux)](https://docs.microsoft.com/en-us/windows/wsl/install-win10) or install [Make Windows port to Git Bash](https://gist.github.com/evanwill/0207876c3243bbb6863e65ec5dc3f058). +You can use [WSL (Windows Subsystem for Linux)](https://docs.microsoft.com/en-us/windows/wsl/install-win10) or try [Make Windows port](https://gist.github.com/evanwill/0207876c3243bbb6863e65ec5dc3f058). ### Why nothing for GoLand -The maintainer does not use GoLand. Fell free to create a pull request for [#2](https://github.com/golang-templates/library/issues/2). +The maintainer does not use GoLand. Fell free to create a pull request for [#2](https://github.com/golang-templates/seed/issues/2). ### Why GitHub Actions, not any other CI server diff --git a/docker-compose.yml b/docker-compose.yml index 14fc5d3..76dbdba 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,6 @@ services: container_name: builder build: . working_dir: /app - command: mage -v all + command: make all volumes: - $PWD:/app - \ No newline at end of file diff --git a/foo.go b/foo.go index a85407e..3c83b07 100644 --- a/foo.go +++ b/foo.go @@ -1,5 +1,5 @@ -// Package library has a dummy function covered by a unit test. -package library +// Package seed has a dummy function covered by a unit test. +package seed // Foo returns "Bar". func Foo() string { diff --git a/foo_test.go b/foo_test.go index 152cf49..3b54a46 100644 --- a/foo_test.go +++ b/foo_test.go @@ -1,9 +1,9 @@ -package library_test +package seed_test import ( "testing" - . "github.com/golang-templates/library" + . "github.com/golang-templates/seed" ) func TestFoo(t *testing.T) { diff --git a/go.mod b/go.mod index 3a1cf93..4e6d0c5 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,3 @@ -module github.com/golang-templates/library +module github.com/golang-templates/seed go 1.14 - -require github.com/magefile/mage v1.9.0 diff --git a/go.sum b/go.sum index 7eb0fc9..e69de29 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +0,0 @@ -github.com/magefile/mage v1.9.0 h1:t3AU2wNwehMCW97vuqQLtw6puppWXHO+O2MHo5a50XE= -github.com/magefile/mage v1.9.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= diff --git a/magefile.go b/magefile.go deleted file mode 100644 index 99ca5ee..0000000 --- a/magefile.go +++ /dev/null @@ -1,28 +0,0 @@ -//+build mage - -package main - -import ( - "github.com/magefile/mage/mg" - "github.com/magefile/mage/sh" -) - -// All full build: build, lint, test. -func All() { - mg.SerialDeps(Build, Lint, Test) -} - -// Build go build. -func Build() error { - return sh.RunV("go", "build", "./...") -} - -// Lint golangci-lint. -func Lint() error { - return sh.RunV("golangci-lint", "run") -} - -// Test go test with race detector and code covarage. -func Test() error { - return sh.RunV("go", "test", "-race", "-covermode=atomic") -}