Skip to content
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
65 changes: 20 additions & 45 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,71 +1,46 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
name: "CodeQL"

on:
push:
branches: [master]
branches: [ main, master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
branches: [ main, master ]
schedule:
- cron: '0 1 * * 6'
- cron: '0 1 * * 6' # Run every Saturday at 1 AM

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
security-events: write
actions: read
contents: read

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

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2

# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'
cache: true

#- run: |
# make bootstrap
# make release
- name: Build
run: go build ./...

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
74 changes: 31 additions & 43 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,40 @@
name: reviewdog
on: [push,pull_request]
jobs:
# NOTE: golangci-lint doesn't report multiple errors on the same line from
# different linters and just report one of the errors?

golangci-lint:
name: runner / golangci-lint
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: golangci-lint
uses: docker://reviewdog/action-golangci-lint:v1.0.4 # Pre-built image
# uses: reviewdog/action-golangci-lint@v1 # Build with Dockerfile
# uses: docker://reviewdog/action-golangci-lint:v1.0.2 # Can use specific version.
# uses: reviewdog/action-golangci-lint@v1.0.2 # Can use specific version.
with:
github_token: ${{ secrets.github_token }}
# Can pass --config flag to change golangci-lint behavior and target
# directory.
golangci_lint_flags: "--config=.github/.golangci.yml ./testdata"
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]

# Use golint via golangci-lint binary with "warning" level.
golint:
name: runner / golint
jobs:
go-test:
name: runner / go test
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: golint
uses: docker://reviewdog/action-golangci-lint:v1.0.4 # Pre-built image
- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
github_token: ${{ secrets.github_token }}
golangci_lint_flags: "--disable-all -E golint --exclude-use-default=false"
tool_name: golint # Change reporter name.
level: warning # GitHub Status Check won't become failure with this level.
go-version: '1.22'
cache: true

- name: Run tests
run: go test -v ./...

# You can add more and more supported linters with different config.
errcheck:
name: runner / errcheck
format-check:
name: runner / format check
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: errcheck
uses: docker://reviewdog/action-golangci-lint:v1.0.4 # Pre-built image
- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
github_token: ${{ secrets.github_token }}
golangci_lint_flags: "--disable-all -E errcheck"
tool_name: errcheck
level: info
go-version: '1.22'
cache: true

- name: Check formatting
run: |
gofmt -l . | grep -v vendor/ | tee /dev/stderr | (! grep .)
62 changes: 48 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,62 @@
name: sql-dog
on: [push]
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]

jobs:
test:
name: Build and Test
runs-on: ubuntu-latest
services:
mysql:
image: mysql:5.7
image: mysql:8.0
env:
MYSQL_USER: root
MYSQL_ROOT_PASSWORD: admin
MYSQL_DATABASE: sql-dog
ports:
- 3306
- 3306:3306
options: >-
--health-cmd "mysqladmin ping -h localhost"
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Set up Go 1.13
uses: actions/setup-go@v1
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.13.4
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Get dependencies
run: go mod download
- name: Test
run: go test ./...
go-version: '1.22'
cache: true

- name: Check out code
uses: actions/checkout@v4

- name: Install dependencies
run: |
go mod download
go get github.com/goccy/go-yaml
go get github.com/bxcodec/faker/v3

- name: Run tests and linting
run: |
# Basic format check instead of using golangci-lint
gofmt -l . | grep -v vendor/ | tee /dev/stderr | (! grep .)

# Run tests
go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
env:
DB_HOST: localhost
DB_PORT: 3306
DB_USER: root
DB_PASSWORD: admin
DB_NAME: sql-dog

- name: Upload coverage report
uses: codecov/codecov-action@v3
with:
files: ./coverage.txt
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea/
config.yaml
linter.yaml
linter.yaml
/bin/
coverage.txt
30 changes: 11 additions & 19 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
linters-settings:
# depguard:
# list-type: blacklist
# packages:
# - github.com/sirupsen/logrus
# packages-with-error-message:
# - {github.com/sirupsen/logrus: 'logging is allowed only by logutils.Log'}
# dupl:
# threshold: 100
funlen:
lines: 500
statements: 80
depguard:
list-type: denylist
include-go-root: false
packages:
# 特定の禁止したいパッケージがあればここに記述
packages-with-error-message:
# メッセージ付きで禁止したいパッケージがあればここに記述
funlen:
lines: 500
statements: 80
# goconst:
# min-len: 2
# min-occurrences: 2
Expand Down Expand Up @@ -52,7 +51,6 @@ linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
Expand All @@ -64,28 +62,22 @@ linters:
- gocyclo
- gofmt
- goimports
- golint
- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- interfacer
# - lll
- misspell
- nakedret
- rowserrcheck
- scopelint
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace
- revive # replaces golint

# issues:
# exclude-rules:
Expand Down
34 changes: 33 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,34 @@
# Formatting tasks
fmt:
go fmt ./...

# Linting tasks
lint:
golangci-lint run
$(HOME)/go/bin/golangci-lint run --no-config --disable-all --enable=gofmt,govet,errcheck

# Testing tasks
test:
go test -v ./...

test-race:
go test -v -race ./...

test-cover:
go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...

# Build tasks
build:
go build -o bin/sql-dog-lint ./cmd/lint/main.go
go build -o bin/sql-dog-clean ./cmd/clean/main.go
@echo "Binaries built in ./bin/"

# Installation task
install:
go install ./cmd/lint
go install ./cmd/clean

# Clean up tasks
clean:
rm -rf bin/

.PHONY: fmt lint test test-race test-cover build install clean
Loading
Loading