Skip to content

Commit

Permalink
Setup hello world and lint workflow (#1)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Antti Harju authored Jul 19, 2024
1 parent a9e53b1 commit 6e54d82
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# https://editorconfig.org
root = true

[*]
indent_style = tab
tab_width = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yml]
indent_style = space
indent_size = 2
27 changes: 27 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Lint
on:
push:
branches:
- main
pull_request:

permissions:
contents: read

jobs:
golangci-lint:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- run: echo "GOLANGCI_LINT_VERSION=$(cat .golangci.version)" >> $GITHUB_ENV
- uses: golangci/golangci-lint-action@v6
with:
version: ${{ env.GOLANGCI_LINT_VERSION }}
shellcheck:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: scripts/shellcheck.sh
1 change: 1 addition & 0 deletions .golangci.version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.59.1
99 changes: 99 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
linters:
enable:
- copyloopvar
- intrange
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
- contextcheck
- cyclop
- decorder
- dogsled
- dupl
- dupword
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- exhaustive
- exportloopref
- forcetypeassert
- funlen
- gci
- ginkgolinter
- gocheckcompilerdirectives
- gochecksumtype
- gocognit
- goconst
- gocritic
- gocyclo
- goheader
- gomodguard
- goprintffuncname
- gosec
- gosimple
- gosmopolitan
- govet
- grouper
- importas
- inamedparam
- ineffassign
- interfacebloat
- ireturn
- lll
- loggercheck
- maintidx
- makezero
- mirror
- musttag
- nakedret
- nestif
- nilerr
- nilnil
- nlreturn
- noctx
- nolintlint
- nonamedreturns
- nosprintfhostport
- paralleltest
- perfsprint
- prealloc
- predeclared
- promlinter
- reassign
- revive
- rowserrcheck
- sloglint
- spancheck
- sqlclosecheck
- staticcheck
- stylecheck
- tagliatelle
- tenv
- testableexamples
- testifylint
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- varnamelen
- wastedassign
- wrapcheck
- wsl
- zerologlint
# https://peter.bourgon.org/blog/2017/06/09/theory-of-modern-go.html
- gochecknoglobals
- gochecknoinits
# use make lint-fix
- gofmt
- gofumpt
- goimports
- misspell
- protogetter
- whitespace
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
SHELL := bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c
MAKEFLAGS += --warn-undefined-variables

GOLANGCI_LINT_VERSION=$(shell cat .golangci.version)
GOLANGCI_LINT_INSTALL_DIR=$(shell go env GOPATH)/bin

.PHONY: install-pre-commit-hook
install-pre-commit-hook:
rm -f .git/hooks/pre-commit
cp scripts/pre-commit.sh .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

.PHONY: install-lint
install-lint:
VERSION=$(GOLANGCI_LINT_VERSION) INSTALL_DIR=$(GOLANGCI_LINT_INSTALL_DIR) scripts/install-lint.sh

.PHONY: lint
lint:
$(GOLANGCI_LINT_INSTALL_DIR)/golangci-lint run

.PHONY: lint-fix
lint-fix:
$(GOLANGCI_LINT_INSTALL_DIR)/golangci-lint run --fix

.PHONY: shellcheck
shellcheck:
scripts/shellcheck.sh

.PHONY: ci
ci: lint shellcheck
7 changes: 7 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "fmt"

func main() {
fmt.Println("Hello world!")
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/anttiharju/golangci-lint-updater

go 1.22.5
5 changes: 5 additions & 0 deletions scripts/install-lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

mkdir -p "$INSTALL_DIR"
cd "$INSTALL_DIR" || exit
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b . "$VERSION"
5 changes: 5 additions & 0 deletions scripts/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
#
# To not be surprised by CI failures.

make ci
3 changes: 3 additions & 0 deletions scripts/shellcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

find . -iname "*.sh" -exec shellcheck {} +

0 comments on commit 6e54d82

Please sign in to comment.