Skip to content

Commit

Permalink
build: replace GNU make with go-task (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 authored Jun 24, 2022
1 parent 1335d71 commit b404a8e
Show file tree
Hide file tree
Showing 17 changed files with 828 additions and 172 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ jobs:
go-cache-1-${{ hashFiles('**/go.sum') }}-
go-cache-1-
- name: Install Task
uses: arduino/setup-task@v1

- run: go get ./...

- name: Build
run: make build
run: task build

- run: docker build -f etc/Dockerfile .
12 changes: 8 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ jobs:

- run: echo "TAG=${GITHUB_REF##*/}" >> $GITHUB_ENV

- run: make build
- name: Install Task
uses: arduino/setup-task@v1

- run: task build

- uses: docker/login-action@v2
with:
Expand Down Expand Up @@ -75,9 +78,10 @@ jobs:

- run: echo "TAG=${GITHUB_REF##*/}" >> $GITHUB_ENV

- run: go build -o dist/archive.exe ./internal/cmd/archive/
env:
CGO_ENABLED: "0"
- name: Install Task
uses: arduino/setup-task@v1

- run: task build-archive

- uses: docker/login-action@v2
with:
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ jobs:
with:
go-version: "~1.17.8"

- name: Install Task
uses: arduino/setup-task@v1

- name: Go Build Cache (test)
uses: actions/cache@v3
with:
Expand All @@ -51,12 +54,10 @@ jobs:
- run: go get -t ./...

- run: make install

- run: bash $HOME/dev-env/wait_mysql_ready.sh

- name: Run tests
run: make coverage
run: task coverage
env:
GORACE: halt_on_error=1
MYSQL_HOST: 127.0.0.1
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ tmp/
node_modules/
pnpm-lock.yaml
yarn.lock
.task/
95 changes: 0 additions & 95 deletions Makefile

This file was deleted.

113 changes: 113 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
version: "3"

dotenv: [".env", ".envrc"]

includes:
mock: "./etc/mock.task.yaml"

tasks:
default:
silent: true
cmds:
- task --list

build:
desc: Build Web Server Binary
sources:
- ./**/*.go
- go.mod
generates:
- ./dist/chii.exe
cmds:
- go build -o dist/chii.exe main.go
env:
CGO_ENABLED: "0"

build-archive:
desc: Build Web Server Binary
sources:
- ./**/*.go
- go.mod
generates:
- ./dist/archive.exe
cmds:
- go build -o ./dist/archive.exe ./internal/cmd/archive/
env:
CGO_ENABLED: "0"

lint:
silent: true
desc: Run 'golangci-lint'
cmds:
- golangci-lint run --fix

test:
desc: Run tests without mysql and redis.
deps:
- gotestfmt
cmds:
- go test -timeout 1s -json -tags test ./... 2>&1 | .bin/gotestfmt.exe -hide empty-packages,successful-packages
env:
CGO_ENABLED: "0"

bench:
desc: Run benchmark
cmds:
- go test -bench=. -benchmem ./pkg/wiki

test-all:
desc: Run all tests, need mysql and redis, alias for `TEST_MYSQL=1 TEST_REDIS=1 task test`
deps:
- gotestfmt
cmds:
- go test -timeout 1s -json -tags test -race ./... 2>&1 | .bin/gotestfmt.exe -hide empty-packages,successful-packages
env:
TEST_MYSQL: "1"
TEST_REDIS: "1"

coverage:
desc: Run tests with coverage report, used in CI.
deps:
- gotestfmt
cmds:
- go test -json -tags test -race -coverpkg=./... -covermode=atomic -coverprofile=coverage.out -count=1 ./... 2>&1 | .bin/gotestfmt.exe -hide empty-packages
env:
TEST_MYSQL: "1"
TEST_REDIS: "1"

# generated files
gen:
desc: Generate all generated GO files
deps:
- gorm
- mock

mock:
desc: Generate Mocks.
deps:
- mock:all

gorm:
desc: Run gorm-gen to generate go struct from mysql database.
generates:
- ./dal/query/gen.go
sources:
- ./internal/cmd/gen/gorm/main.go
- go.mod
cmds:
- go run ./internal/cmd/gen/gorm/main.go

# binary tools
gotestfmt:
silent: true
sources:
- go.mod
generates:
- .bin/gotestfmt.exe
cmds:
- go build -o .bin/gotestfmt.exe github.com/haveyoudebuggedit/gotestfmt/v2/cmd/gotestfmt

clean:
cmds:
- rm -rf .task
- rm -rf .bin
Loading

0 comments on commit b404a8e

Please sign in to comment.