Skip to content

Commit 1d8e736

Browse files
authored
Merge pull request #9 from tkc/feat/modernize-infrastructure
feat: Modernize project infrastructure and documentation
2 parents 857f3f8 + b90c2aa commit 1d8e736

File tree

21 files changed

+651
-310
lines changed

21 files changed

+651
-310
lines changed
Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,46 @@
1-
# For most projects, this workflow file will not need changing; you simply need
2-
# to commit it to your repository.
3-
#
4-
# You may wish to alter this file to override the set of languages analyzed,
5-
# or to provide custom queries or build logic.
61
name: "CodeQL"
72

83
on:
94
push:
10-
branches: [master]
5+
branches: [ main, master ]
116
pull_request:
12-
# The branches below must be a subset of the branches above
13-
branches: [master]
7+
branches: [ main, master ]
148
schedule:
15-
- cron: '0 1 * * 6'
9+
- cron: '0 1 * * 6' # Run every Saturday at 1 AM
1610

1711
jobs:
1812
analyze:
1913
name: Analyze
2014
runs-on: ubuntu-latest
15+
permissions:
16+
security-events: write
17+
actions: read
18+
contents: read
2119

2220
strategy:
2321
fail-fast: false
2422
matrix:
25-
# Override automatic language detection by changing the below list
26-
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
27-
language: ['go']
28-
# Learn more...
29-
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
23+
language: [ 'go' ]
3024

3125
steps:
3226
- name: Checkout repository
33-
uses: actions/checkout@v2
34-
with:
35-
# We must fetch at least the immediate parents so that if this is
36-
# a pull request then we can checkout the head.
37-
fetch-depth: 2
38-
39-
# If this run was triggered by a pull request event, then checkout
40-
# the head of the pull request instead of the merge commit.
41-
- run: git checkout HEAD^2
42-
if: ${{ github.event_name == 'pull_request' }}
27+
uses: actions/checkout@v4
4328

44-
# Initializes the CodeQL tools for scanning.
4529
- name: Initialize CodeQL
46-
uses: github/codeql-action/init@v1
30+
uses: github/codeql-action/init@v2
4731
with:
4832
languages: ${{ matrix.language }}
49-
# If you wish to specify custom queries, you can do so here or in a config file.
50-
# By default, queries listed here will override any specified in a config file.
51-
# Prefix the list here with "+" to use these queries and those in the config file.
52-
# queries: ./path/to/local/query, your-org/your-repo/queries@main
53-
54-
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
55-
# If this step fails, then you should remove it and run the build manually (see below)
56-
- name: Autobuild
57-
uses: github/codeql-action/autobuild@v1
5833

59-
# ℹ️ Command-line programs to run using the OS shell.
60-
# 📚 https://git.io/JvXDl
61-
62-
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
63-
# and modify them (or add more) to build your code if your project
64-
# uses a compiled language
34+
- name: Set up Go
35+
uses: actions/setup-go@v4
36+
with:
37+
go-version: '1.22'
38+
cache: true
6539

66-
#- run: |
67-
# make bootstrap
68-
# make release
40+
- name: Build
41+
run: go build ./...
6942

7043
- name: Perform CodeQL Analysis
71-
uses: github/codeql-action/analyze@v1
44+
uses: github/codeql-action/analyze@v2
45+
with:
46+
category: "/language:${{matrix.language}}"

.github/workflows/reviewdog.yml

Lines changed: 31 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,40 @@
11
name: reviewdog
2-
on: [push,pull_request]
3-
jobs:
4-
# NOTE: golangci-lint doesn't report multiple errors on the same line from
5-
# different linters and just report one of the errors?
6-
7-
golangci-lint:
8-
name: runner / golangci-lint
9-
runs-on: ubuntu-latest
10-
steps:
11-
- name: Check out code into the Go module directory
12-
uses: actions/checkout@v1
13-
- name: golangci-lint
14-
uses: docker://reviewdog/action-golangci-lint:v1.0.4 # Pre-built image
15-
# uses: reviewdog/action-golangci-lint@v1 # Build with Dockerfile
16-
# uses: docker://reviewdog/action-golangci-lint:v1.0.2 # Can use specific version.
17-
# uses: reviewdog/[email protected] # Can use specific version.
18-
with:
19-
github_token: ${{ secrets.github_token }}
20-
# Can pass --config flag to change golangci-lint behavior and target
21-
# directory.
22-
golangci_lint_flags: "--config=.github/.golangci.yml ./testdata"
2+
on:
3+
push:
4+
branches: [ main, master ]
5+
pull_request:
6+
branches: [ main, master ]
237

24-
# Use golint via golangci-lint binary with "warning" level.
25-
golint:
26-
name: runner / golint
8+
jobs:
9+
go-test:
10+
name: runner / go test
2711
runs-on: ubuntu-latest
2812
steps:
29-
- name: Check out code into the Go module directory
30-
uses: actions/checkout@v1
31-
- name: golint
32-
uses: docker://reviewdog/action-golangci-lint:v1.0.4 # Pre-built image
13+
- name: Check out code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v4
3318
with:
34-
github_token: ${{ secrets.github_token }}
35-
golangci_lint_flags: "--disable-all -E golint --exclude-use-default=false"
36-
tool_name: golint # Change reporter name.
37-
level: warning # GitHub Status Check won't become failure with this level.
19+
go-version: '1.22'
20+
cache: true
21+
22+
- name: Run tests
23+
run: go test -v ./...
3824

39-
# You can add more and more supported linters with different config.
40-
errcheck:
41-
name: runner / errcheck
25+
format-check:
26+
name: runner / format check
4227
runs-on: ubuntu-latest
4328
steps:
44-
- name: Check out code into the Go module directory
45-
uses: actions/checkout@v1
46-
- name: errcheck
47-
uses: docker://reviewdog/action-golangci-lint:v1.0.4 # Pre-built image
29+
- name: Check out code
30+
uses: actions/checkout@v4
31+
32+
- name: Set up Go
33+
uses: actions/setup-go@v4
4834
with:
49-
github_token: ${{ secrets.github_token }}
50-
golangci_lint_flags: "--disable-all -E errcheck"
51-
tool_name: errcheck
52-
level: info
35+
go-version: '1.22'
36+
cache: true
37+
38+
- name: Check formatting
39+
run: |
40+
gofmt -l . | grep -v vendor/ | tee /dev/stderr | (! grep .)

.github/workflows/test.yml

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,62 @@
11
name: sql-dog
2-
on: [push]
2+
on:
3+
push:
4+
branches: [ main, master ]
5+
pull_request:
6+
branches: [ main, master ]
37

48
jobs:
59
test:
10+
name: Build and Test
611
runs-on: ubuntu-latest
712
services:
813
mysql:
9-
image: mysql:5.7
14+
image: mysql:8.0
1015
env:
11-
MYSQL_USER: root
1216
MYSQL_ROOT_PASSWORD: admin
1317
MYSQL_DATABASE: sql-dog
1418
ports:
15-
- 3306
19+
- 3306:3306
20+
options: >-
21+
--health-cmd "mysqladmin ping -h localhost"
22+
--health-interval 10s
23+
--health-timeout 5s
24+
--health-retries 5
1625
1726
steps:
18-
- name: Set up Go 1.13
19-
uses: actions/setup-go@v1
27+
- name: Set up Go
28+
uses: actions/setup-go@v4
2029
with:
21-
go-version: 1.13.4
22-
id: go
23-
- name: Check out code into the Go module directory
24-
uses: actions/checkout@v2
25-
- name: Get dependencies
26-
run: go mod download
27-
- name: Test
28-
run: go test ./...
30+
go-version: '1.22'
31+
cache: true
32+
33+
- name: Check out code
34+
uses: actions/checkout@v4
35+
36+
- name: Install dependencies
37+
run: |
38+
go mod download
39+
go get github.com/goccy/go-yaml
40+
go get github.com/bxcodec/faker/v3
41+
42+
- name: Run tests and linting
43+
run: |
44+
# Basic format check instead of using golangci-lint
45+
gofmt -l . | grep -v vendor/ | tee /dev/stderr | (! grep .)
46+
47+
# Run tests
48+
go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
49+
env:
50+
DB_HOST: localhost
51+
DB_PORT: 3306
52+
DB_USER: root
53+
DB_PASSWORD: admin
54+
DB_NAME: sql-dog
55+
56+
- name: Upload coverage report
57+
uses: codecov/codecov-action@v3
58+
with:
59+
files: ./coverage.txt
60+
flags: unittests
61+
name: codecov-umbrella
62+
fail_ci_if_error: false

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.idea/
22
config.yaml
3-
linter.yaml
3+
linter.yaml
4+
/bin/
5+
coverage.txt

.golangci.yml

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
linters-settings:
2-
# depguard:
3-
# list-type: blacklist
4-
# packages:
5-
# - github.com/sirupsen/logrus
6-
# packages-with-error-message:
7-
# - {github.com/sirupsen/logrus: 'logging is allowed only by logutils.Log'}
8-
# dupl:
9-
# threshold: 100
10-
funlen:
11-
lines: 500
12-
statements: 80
2+
depguard:
3+
list-type: denylist
4+
include-go-root: false
5+
packages:
6+
# 特定の禁止したいパッケージがあればここに記述
7+
packages-with-error-message:
8+
# メッセージ付きで禁止したいパッケージがあればここに記述
9+
funlen:
10+
lines: 500
11+
statements: 80
1312
# goconst:
1413
# min-len: 2
1514
# min-occurrences: 2
@@ -52,7 +51,6 @@ linters:
5251
disable-all: true
5352
enable:
5453
- bodyclose
55-
- deadcode
5654
- depguard
5755
- dogsled
5856
- dupl
@@ -64,28 +62,22 @@ linters:
6462
- gocyclo
6563
- gofmt
6664
- goimports
67-
- golint
68-
- gomnd
6965
- goprintffuncname
7066
- gosec
7167
- gosimple
7268
- govet
7369
- ineffassign
74-
- interfacer
75-
# - lll
7670
- misspell
7771
- nakedret
7872
- rowserrcheck
79-
- scopelint
8073
- staticcheck
81-
- structcheck
8274
- stylecheck
8375
- typecheck
8476
- unconvert
8577
- unparam
8678
- unused
87-
- varcheck
8879
- whitespace
80+
- revive # replaces golint
8981

9082
# issues:
9183
# exclude-rules:

Makefile

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,34 @@
1+
# Formatting tasks
2+
fmt:
3+
go fmt ./...
4+
5+
# Linting tasks
16
lint:
2-
golangci-lint run
7+
$(HOME)/go/bin/golangci-lint run --no-config --disable-all --enable=gofmt,govet,errcheck
8+
9+
# Testing tasks
10+
test:
11+
go test -v ./...
12+
13+
test-race:
14+
go test -v -race ./...
15+
16+
test-cover:
17+
go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
18+
19+
# Build tasks
20+
build:
21+
go build -o bin/sql-dog-lint ./cmd/lint/main.go
22+
go build -o bin/sql-dog-clean ./cmd/clean/main.go
23+
@echo "Binaries built in ./bin/"
24+
25+
# Installation task
26+
install:
27+
go install ./cmd/lint
28+
go install ./cmd/clean
29+
30+
# Clean up tasks
31+
clean:
32+
rm -rf bin/
33+
34+
.PHONY: fmt lint test test-race test-cover build install clean

0 commit comments

Comments
 (0)