Skip to content

Commit

Permalink
various improvements (#10)
Browse files Browse the repository at this point in the history
* update README
* bump golangci-lint version
* add gitlab-ci lint to pre-commit config
  • Loading branch information
FalcoSuessgott authored Aug 10, 2021
1 parent 533c028 commit bf5e638
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.29
version: v1.41.1
args: -c .golang-ci.yml
8 changes: 7 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@ image: tetafro/golang-gcc:1.15-alpine

stages:
- lint
- build
- test
- release

lint:
stage: lint
before_script:
- wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.35.2
- wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.41.1
script:
- ./bin/golangci-lint run -c .golang-ci.yml
allow_failure: true

build:
stage: build
script:
- go build

test:
stage: test
script:
Expand Down
5 changes: 4 additions & 1 deletion .golang-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ linters-settings:
linters:
enable-all: true
disable:
- testpackage
- testpackage
- forbidigo
- paralleltest
- exhaustivestruct
38 changes: 23 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
repos:
- repo: git://github.com/dnephin/pre-commit-golang
rev: master
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
- id: go-critic
- id: go-unit-tests
- id: go-build
- id: go-mod-tidy
# golang pre commits
- repo: git://github.com/dnephin/pre-commit-golang
rev: master
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

# gitlab ci lint
- repo: https://github.com/FalcoSuessgott/lint-gitlab-ci
rev: v0.0.4
hooks:
- id: gitlab-ci
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ A general purpose project template for golang CLI applications
* [Demo Application](#demo-application)
* [Makefile Targets](#makefile-targets)
* [Contribute](#contribute)
* [Ideas](#ideas)

<!-- Added by: morelly_t1, at: Mon 12 Jul 2021 11:28:04 AM CEST -->
<!-- Added by: morelly_t1, at: Tue 10 Aug 2021 08:54:24 AM CEST -->

<!--te-->

Expand All @@ -22,11 +21,11 @@ This template serves as a starting point for golang commandline applications it
# Features
- [goreleaser](https://goreleaser.com/) with `deb.` and `.rpm` package releasing
- [golangci-lint](https://golangci-lint.run/) for linting and formatting
- [Github Actions](.github/worflows) Stages (Linting, Testing, Releasing)
- [Gitlab CI](.gitlab-ci.yml) Configuration (Linting, Testing, Releasing)
- [Github Actions](.github/worflows) Stages (Lint, Test, Build, Release)
- [Gitlab CI](.gitlab-ci.yml) Configuration (Lint, Test, Build, Release)
- [cobra](https://cobra.dev/) example setup including tests
- [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/)
- [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

# Project Layout
Expand Down Expand Up @@ -62,30 +61,30 @@ 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 -a
7

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

# Makefile Targets
```
```sh
$> make
build build golang binary
clean clean up environment
cover display test coverage
deps clean go.mod
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
```

# Contribute
If you find issues in that setup or have some nice features / improvements, I would welcome an issue or a PR :)


# Ideas
- [ ] implement a `create` subcommand that preconfigures this project setup and all its dependencies
- [ ] introduce viper config examples
4 changes: 2 additions & 2 deletions cmd/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ func (o *exampleOptions) run(cmd *cobra.Command, args []string) error {
}

func (o *exampleOptions) parseArgs(args []string) ([]int, error) {
values := make([]int, 2)
values := make([]int, 2) //nolint: gomnd

for i, a := range args {
v, err := convert.ToInteger(a)
if err != nil {
return nil, err
return nil, fmt.Errorf("error converting to integer: %w", err)
}

values[i] = v
Expand Down
7 changes: 6 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func newRootCmd(version string) *cobra.Command {
Short: "golang-cli project template demo application",
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Println(cmd.UsageString())

return nil
},
}
Expand All @@ -24,5 +25,9 @@ func newRootCmd(version string) *cobra.Command {

// Execute invokes the command.
func Execute(version string) error {
return newRootCmd(version).Execute()
if err := newRootCmd(version).Execute(); err != nil {
return fmt.Errorf("error executing root command: %w", err)
}

return nil
}
4 changes: 3 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ read -rp "GitHub Username: " user
read -rp "Projectname: " projectname

git clone git@github.com:FalcoSuessgott/golang-cli-template.git "$projectname"
cd $projectname
cd "$projectname"
rm -rf .git
find . -type f -exec sed -i "s/FalcoSuessgott\/golang-cli-template/$user\/$projectname/g" {} +
git init
git add .
git commit -m "initial commit"
git remote add origin "git@github.com:$user/$projectname.git"

echo "template successfully installed."

0 comments on commit bf5e638

Please sign in to comment.