Skip to content

Commit

Permalink
chore(taskfile): add Taskfiles for project
Browse files Browse the repository at this point in the history
  • Loading branch information
Icikowski committed Nov 14, 2022
1 parent eb1a4bf commit 8e55807
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '3'

vars:
BUILD_TIME:
sh: date -u +"%Y-%m-%dT%H:%M:%SZ"
GIT_COMMIT:
sh: git rev-parse --short HEAD || echo "unknown"
GIT_TAG:
sh: (git describe --abbrev=0 || echo "unknown") | sed "s/v//"

includes:
build:
taskfile: ./tasks/build.yaml
dir: ./src
test:
taskfile: ./tasks/test.yaml
dir: ./src
dist:
taskfile: ./tasks/dist.yaml
dir: ./dist
101 changes: 101 additions & 0 deletions tasks/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
version: '3'

vars:
flag_buildTime: -X 'github.com/Icikowski/GoosyMock/meta.BuildTime={{ .BUILD_TIME }}'
flag_version: -X 'github.com/Icikowski/GoosyMock/meta.Version={{ .GIT_TAG }}'
flag_commit: -X 'github.com/Icikowski/GoosyMock/meta.GitCommit={{ .GIT_COMMIT }}'
flag_buildType_dynamic: -X 'github.com/Icikowski/GoosyMock/meta.BinaryType=dynamic'
flag_buildType_static: -X 'github.com/Icikowski/GoosyMock/meta.BinaryType=static' -w -extldflags '-static'
flags_base: "{{ .flag_version }} {{ .flag_commit }} {{ .flag_buildTime }}"

tasks:
_parametrized_build:
label: "{{ .goos | default OS }}_{{ .goarch | default ARCH }}"
internal: true
env:
CGO_ENABLED: '{{ .cgo_enabled | default "1" }}'
GOOS: "{{ .goos | default OS }}"
GOARCH: "{{ .goarch | default ARCH }}"
cmds:
- go build -ldflags "{{ .flags_base }} {{ .flags_extra }}" -o ../target/goosymock_${GOOS}_${GOARCH}{{ .extension }} .
sources:
- "**/*.go"
- go.mod
- go.sum
generates:
- ../target/goosymock_{{ .goos | default OS }}_{{ .goarch | default ARCH }}{{ .extension }}
dynamic:
desc: Build a dynamic binary
cmds:
- task: _parametrized_build
vars:
flags_extra: "{{ .flag_buildType_dynamic }}"
static:
desc: Build a static binary
cmds:
- task: _parametrized_build
vars:
flags_extra: "{{ .flag_buildType_static }}"
cgo_enabled: "0"
crossplatform:
desc: Build multiple binaries for different platforms
cmds:
- task: _parametrized_build
vars:
flags_extra: "{{ .flag_buildType_static }}"
cgo_enabled: "0"
goos: linux
goarch: amd64
- task: _parametrized_build
vars:
flags_extra: "{{ .flag_buildType_static }}"
cgo_enabled: "0"
goos: linux
goarch: "386"
- task: _parametrized_build
vars:
flags_extra: "{{ .flag_buildType_static }}"
cgo_enabled: "0"
goos: linux
goarch: arm
- task: _parametrized_build
vars:
flags_extra: "{{ .flag_buildType_static }}"
cgo_enabled: "0"
goos: linux
goarch: arm64
- task: _parametrized_build
vars:
flags_extra: "{{ .flag_buildType_static }}"
cgo_enabled: "0"
goos: linux
goarch: ppc64le
- task: _parametrized_build
vars:
flags_extra: "{{ .flag_buildType_static }}"
cgo_enabled: "0"
goos: darwin
goarch: amd64
- task: _parametrized_build
vars:
flags_extra: "{{ .flag_buildType_static }}"
cgo_enabled: "0"
goos: darwin
goarch: arm64
- task: _parametrized_build
vars:
flags_extra: "{{ .flag_buildType_static }}"
cgo_enabled: "0"
goos: windows
goarch: amd64
extension: .exe
- task: _parametrized_build
vars:
flags_extra: "{{ .flag_buildType_static }}"
cgo_enabled: "0"
goos: windows
goarch: "386"
extension: .exe



11 changes: 11 additions & 0 deletions tasks/dist.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3'

vars:
image_tag: ghcr.io/icikowski/goosymock:{{ .GIT_TAG }}

tasks:
image:
desc: Build a Docker image
dir: container
cmds:
- docker build ../../src --file Containerfile --tag {{ .image_tag }} --build-arg version={{ .GIT_TAG }} --build-arg gitCommit={{ .GIT_COMMIT }} --build-arg buildTime={{ .BUILD_TIME }} --label org.opencontainers.image.version={{ .GIT_TAG }} --label org.opencontainers.image.created={{ .BUILD_TIME }}
35 changes: 35 additions & 0 deletions tasks/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: '3'

tasks:
standard:
desc: Run tests with standard output verbosity
aliases:
- "std"
cmds:
- go test ./... -race -p 1
sources:
- "**/*.go"
- go.mod
- go.sum
full:
desc: Run tests with increased output verbosity
cmds:
- go test ./... -race -p 1 -v
sources:
- "**/*.go"
- go.mod
- go.sum
cover:
desc: Run tests and build coverage report
cmds:
- mkdir -p ../target
- go test ./... -race -p 1 -v -covermode atomic -coverprofile ../target/cover.out
- go tool cover -html ../target/cover.out -o ../target/cover.html
sources:
- "**/*.go"
- go.mod
- go.sum
generates:
- ../target/cover.out
- ../target/cover.html

0 comments on commit 8e55807

Please sign in to comment.