Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update linter and makefile #73

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
version: 2
updates:
- package-ecosystem: gomod
directory: "/"
schedule:
interval: daily
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "1.x"
go-version: "1.20.1" # update together with Dockerfile.dev
- name: Debug with tmate SSH if enabled
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_ssh }}
uses: mxschmitt/action-tmate@v3
Expand All @@ -38,10 +38,10 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "1.x"
go-version: "1.20.1" # update together with Dockerfile.dev
- uses: golangci/golangci-lint-action@v3
with:
version: "v1.48.0"
version: "v1.51.1" # update together with Dockerfile.dev

check-tidy:
name: go mod tidy
Expand All @@ -50,7 +50,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "1.x"
go-version: "1.20.1" # update together with Dockerfile.dev
- run: make check-tidy

typos:
Expand Down
253 changes: 150 additions & 103 deletions .golangci.yml

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# update together with .github/workflows/ci.yml
FROM golang:1.20.1 AS go

# update together with .github/workflows/ci.yml
FROM golangci/golangci-lint:v1.51.2 AS linter

FROM go AS dev
ENV INSIDE_DEV_CONTAINER 1
WORKDIR /app
COPY --from=linter /usr/bin/golangci-lint /usr/bin/
58 changes: 40 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
ci: test lint check-tidy
.PHONY: ci
help: ## show this message
@echo "All commands can be run on local machine as well as inside dev container."
@echo ""
@sed -nE 's/^ *([^[:blank:]]+)[[:blank:]]*:[^#]*##[[:blank:]]*(.+)/\1\n\2/p' $(MAKEFILE_LIST) | tr '\n' '\0' | xargs -0 -n 2 printf '%-25s%s\n'
.PHONY: help

test:
go test -race ./...
.DEFAULT_GOAL := help

test: ## run all tests
@echo "+ $@"
go test -race -count 1 -p 8 -parallel 8 -timeout 1m ./...
.PHONY: test

lint:
docker run --rm --name lint -v `pwd`:/app -w /app golangci/golangci-lint:v1.48.0 golangci-lint run
.PHONY: lint
test-cover: ## run all tests with code coverage
@echo "+ $@"
go test -race -count 1 -p 8 -parallel 8 -timeout 1m -coverpkg ./... -coverprofile coverage.out ./...
.PHONY: test-cover

tidy:
go mod tidy
.PHONY: tidy
lint: build-docker-dev ## run linter
@echo "+ $@"
$(RUN_IN_DOCKER) golangci-lint run
.PHONY: lint

update-deps:
go get -u -t ./...
go mod tidy
.PHONY: update-deps
bash: build-docker-dev ## run bash inside container for development
ifndef INSIDE_DEV_CONTAINER
@echo "+ $@"
$(RUN_IN_DOCKER) bash
endif
.PHONY: bash

check-tidy:
check-tidy: ## ensure go.mod is tidy
@echo "+ $@"
cp go.mod go.check.mod
cp go.sum go.check.sum
go mod tidy -modfile=go.check.mod
Expand All @@ -27,6 +38,17 @@ check-tidy:
rm go.check.mod go.check.sum
.PHONY: check-tidy

test-cover:
go test -race -coverpkg ./... -coverprofile=coverage.out ./...
.PHONY: test-cover
build-docker-dev: ## build development image from Dockerfile.dev
ifndef INSIDE_DEV_CONTAINER
@echo "+ $@"
DOCKER_BUILDKIT=1 docker build --tag pairedbrackets:dev - < Dockerfile.dev
endif
.PHONY: build-docker-dev

ifndef INSIDE_DEV_CONTAINER
RUN_IN_DOCKER = docker run --rm \
-it \
-w /app \
--mount type=bind,consistency=delegated,source="`pwd`",target=/app \
pairedbrackets:dev
endif
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ Flags:

## Changelog

### [v1.1.1] - 2023-03-07

#### Changed
* Update golang to 1.20
* Update dependencies
* Update golangci-lint to v1.51.2
* Update Makefile

### [v1.1.0] - 2022-06-22

#### Changed
Expand Down Expand Up @@ -150,4 +158,4 @@ Flags:
[license-img]: https://img.shields.io/github/license/maratori/testpackage.svg
[license-url]: /LICENSE
[godoc-img]: https://pkg.go.dev/badge/github.com/maratori/testpackage.svg
[godoc-url]: https://pkg.go.dev/github.com/maratori/testpackage
[godoc-url]: https://pkg.go.dev/github.com/maratori/testpackage
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/maratori/testpackage

go 1.19
go 1.20

require golang.org/x/tools v0.6.0

Expand Down