From 8e55807801e0607e2f04b271927109cad071b196 Mon Sep 17 00:00:00 2001 From: Piotr Icikowski Date: Mon, 14 Nov 2022 23:21:13 +0100 Subject: [PATCH] chore(taskfile): add Taskfiles for project --- Taskfile.yaml | 20 ++++++++++ tasks/build.yaml | 101 +++++++++++++++++++++++++++++++++++++++++++++++ tasks/dist.yaml | 11 ++++++ tasks/test.yaml | 35 ++++++++++++++++ 4 files changed, 167 insertions(+) create mode 100644 Taskfile.yaml create mode 100644 tasks/build.yaml create mode 100644 tasks/dist.yaml create mode 100644 tasks/test.yaml diff --git a/Taskfile.yaml b/Taskfile.yaml new file mode 100644 index 0000000..3ded199 --- /dev/null +++ b/Taskfile.yaml @@ -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 diff --git a/tasks/build.yaml b/tasks/build.yaml new file mode 100644 index 0000000..d2b4d1b --- /dev/null +++ b/tasks/build.yaml @@ -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 + + + diff --git a/tasks/dist.yaml b/tasks/dist.yaml new file mode 100644 index 0000000..0a40fc6 --- /dev/null +++ b/tasks/dist.yaml @@ -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 }} diff --git a/tasks/test.yaml b/tasks/test.yaml new file mode 100644 index 0000000..4aa0e2b --- /dev/null +++ b/tasks/test.yaml @@ -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 +