Skip to content

Commit 6e54d82

Browse files
authored
Setup hello world and lint workflow (#1)
* Init Go module `go mod init github.com/anttharju/golangci-lint-updater` * Add hello world https://go.dev/play/ * Add golangci-lint workflow * Improve naming * Add .editorconfig * Read golangci-lint version from a file * Remove unnecessary names * Add a makefile target for installing the linter * Rename workflow to be more generic * Add make shellcheck and workflow step * Fix shellcheck issues * Separate shellcheck from golangci-lint job * Debug shellcheck * Remove which shellcheck It exists. Using find's -exex instead of xargs seemingly fixed the issue. * See if shellcheck catches issues in the action run * Revert "See if shellcheck catches issues in the action run" This reverts commit b8b5ae0. * Rename .golangci-version to .golangci.version Matches .golangci.yml better * Add make lint target See https://tech.davis-hansson.com/p/make/ * Add lint-fix target and rename install-linter to lint-install * Add golangci-lint config file This is not its final form, just something to start with. Pulled from an older (currently private) project of mine. * Remove forbidigo Wanted to see the golangci-lint job fail. I think this is enough for this PR. * Satisfy gosmopolitan Caught me off-guard. Oh well. * Add make ci for use with a pre-commit hook Don't like being caught off-guard. Tighter feedback loop. * Add make install-pre-commit-hook Easier for anyone using the repo to install it now.
1 parent a9e53b1 commit 6e54d82

File tree

10 files changed

+196
-0
lines changed

10 files changed

+196
-0
lines changed

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# https://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = tab
6+
tab_width = 4
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.yml]
13+
indent_style = space
14+
indent_size = 2

.github/workflows/lint.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Lint
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
golangci-lint:
13+
runs-on: ubuntu-22.04
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-go@v5
17+
with:
18+
go-version-file: 'go.mod'
19+
- run: echo "GOLANGCI_LINT_VERSION=$(cat .golangci.version)" >> $GITHUB_ENV
20+
- uses: golangci/golangci-lint-action@v6
21+
with:
22+
version: ${{ env.GOLANGCI_LINT_VERSION }}
23+
shellcheck:
24+
runs-on: ubuntu-22.04
25+
steps:
26+
- uses: actions/checkout@v4
27+
- run: scripts/shellcheck.sh

.golangci.version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v1.59.1

.golangci.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
linters:
2+
enable:
3+
- copyloopvar
4+
- intrange
5+
- asasalint
6+
- asciicheck
7+
- bidichk
8+
- bodyclose
9+
- containedctx
10+
- contextcheck
11+
- cyclop
12+
- decorder
13+
- dogsled
14+
- dupl
15+
- dupword
16+
- durationcheck
17+
- errcheck
18+
- errchkjson
19+
- errname
20+
- errorlint
21+
- exhaustive
22+
- exportloopref
23+
- forcetypeassert
24+
- funlen
25+
- gci
26+
- ginkgolinter
27+
- gocheckcompilerdirectives
28+
- gochecksumtype
29+
- gocognit
30+
- goconst
31+
- gocritic
32+
- gocyclo
33+
- goheader
34+
- gomodguard
35+
- goprintffuncname
36+
- gosec
37+
- gosimple
38+
- gosmopolitan
39+
- govet
40+
- grouper
41+
- importas
42+
- inamedparam
43+
- ineffassign
44+
- interfacebloat
45+
- ireturn
46+
- lll
47+
- loggercheck
48+
- maintidx
49+
- makezero
50+
- mirror
51+
- musttag
52+
- nakedret
53+
- nestif
54+
- nilerr
55+
- nilnil
56+
- nlreturn
57+
- noctx
58+
- nolintlint
59+
- nonamedreturns
60+
- nosprintfhostport
61+
- paralleltest
62+
- perfsprint
63+
- prealloc
64+
- predeclared
65+
- promlinter
66+
- reassign
67+
- revive
68+
- rowserrcheck
69+
- sloglint
70+
- spancheck
71+
- sqlclosecheck
72+
- staticcheck
73+
- stylecheck
74+
- tagliatelle
75+
- tenv
76+
- testableexamples
77+
- testifylint
78+
- thelper
79+
- tparallel
80+
- typecheck
81+
- unconvert
82+
- unparam
83+
- unused
84+
- usestdlibvars
85+
- varnamelen
86+
- wastedassign
87+
- wrapcheck
88+
- wsl
89+
- zerologlint
90+
# https://peter.bourgon.org/blog/2017/06/09/theory-of-modern-go.html
91+
- gochecknoglobals
92+
- gochecknoinits
93+
# use make lint-fix
94+
- gofmt
95+
- gofumpt
96+
- goimports
97+
- misspell
98+
- protogetter
99+
- whitespace

Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
SHELL := bash
2+
.ONESHELL:
3+
.SHELLFLAGS := -eu -o pipefail -c
4+
MAKEFLAGS += --warn-undefined-variables
5+
6+
GOLANGCI_LINT_VERSION=$(shell cat .golangci.version)
7+
GOLANGCI_LINT_INSTALL_DIR=$(shell go env GOPATH)/bin
8+
9+
.PHONY: install-pre-commit-hook
10+
install-pre-commit-hook:
11+
rm -f .git/hooks/pre-commit
12+
cp scripts/pre-commit.sh .git/hooks/pre-commit
13+
chmod +x .git/hooks/pre-commit
14+
15+
.PHONY: install-lint
16+
install-lint:
17+
VERSION=$(GOLANGCI_LINT_VERSION) INSTALL_DIR=$(GOLANGCI_LINT_INSTALL_DIR) scripts/install-lint.sh
18+
19+
.PHONY: lint
20+
lint:
21+
$(GOLANGCI_LINT_INSTALL_DIR)/golangci-lint run
22+
23+
.PHONY: lint-fix
24+
lint-fix:
25+
$(GOLANGCI_LINT_INSTALL_DIR)/golangci-lint run --fix
26+
27+
.PHONY: shellcheck
28+
shellcheck:
29+
scripts/shellcheck.sh
30+
31+
.PHONY: ci
32+
ci: lint shellcheck

cmd/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
fmt.Println("Hello world!")
7+
}

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/anttiharju/golangci-lint-updater
2+
3+
go 1.22.5

scripts/install-lint.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
mkdir -p "$INSTALL_DIR"
4+
cd "$INSTALL_DIR" || exit
5+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b . "$VERSION"

scripts/pre-commit.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
#
3+
# To not be surprised by CI failures.
4+
5+
make ci

scripts/shellcheck.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
find . -iname "*.sh" -exec shellcheck {} +

0 commit comments

Comments
 (0)