/
Taskfile.yml
138 lines (134 loc) · 4.46 KB
/
Taskfile.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# https://taskfile.dev
version: '3'
vars:
FULL_VERSION:
sh: git describe --long --dirty --always
SHORT_VERSION:
sh: git describe --abbrev=0 --always
LDFLAGS: >
-w -s
-X github.com/marco-m/timeit/pkg/timeit.fullVersion={{.FULL_VERSION}}
-X github.com/marco-m/timeit/pkg/timeit.shortVersion={{.SHORT_VERSION}}
GOTESTSUM:
sh: if which gotestsum > /dev/null; then echo gotestsum; fi
TESTRUNNER: "{{if .GOTESTSUM}}{{.GOTESTSUM}} --{{else}}go test{{end}}"
tasks:
default:
deps: [test]
clean:
desc: Delete build artifacts
cmds: [rm -rf bin/*]
build:
desc: Build all the executables
deps: [timeit, sleepit, understand-script, pytestsim]
timeit:
desc: Build the timeit executable
dir: bin
cmds:
- go build -v -ldflags="{{.LDFLAGS}}" ../cmd/timeit
sleepit:
desc: Build the sleepit executable
dir: bin
cmds:
- go build -v -ldflags="{{.LDFLAGS}}" ../cmd/sleepit
understand-script:
desc: Build the understand-script executable
dir: bin
cmds:
- go build -v -ldflags="{{.LDFLAGS}}" ../cmd/understand-script
pytestsim:
desc: Build the pytestsim executable
dir: bin
cmds:
- go build -v -ldflags="{{.LDFLAGS}}" ../cmd/pytestsim
test:
desc: Run all the tests
cmds:
- "{{.TESTRUNNER}} -coverprofile=bin/cover.out ./..."
- task: test:version
test:script:
desc: Run only the testscript tests
cmds:
- "{{.TESTRUNNER}} -coverprofile=bin/cover.out -run=^TestScript ./..."
test:unit:
desc: Run only the unit tests. Requires Go >= 1.20 for -skip
cmds:
- "{{.TESTRUNNER}} -coverprofile=bin/cover.out -skip=^TestScript ./..."
browser:
go tool cover -html=bin/cover.out
test:version:
deps: [timeit]
cmds:
- './bin/timeit --version | grep " version: v0\."'
#
# usage: env RELEASE_TAG=v0.1.0 summon task release
#
release:
desc: Build a release and upload to GitHub as draft. You need to transition
from draft to published in the web UI.
preconditions:
- sh: test -n "$RELEASE_TAG"
msg: "error: missing environment variable RELEASE_TAG"
- sh: test -z $(git status --porcelain)
msg: "error: git dirty"
- sh: test -z $(git status --branch --porcelain | grep ahead)
msg: "error: git local branch ahead"
cmds:
# - task: unit-test
# We create the (local) git tag now, after having ran the unit tests and
# before building the executables, so that we can embed this information
# in the binaries.
# To recover: delete local tag: git tag --delete tagname
- git tag -a {{.RELEASE_TAG}} -m ''
- task: release-linux
- task: release-darwin
# - task: system-test
- task: test
# We create the release as a draft (that is: not visible to the public).
# The act of "publishing" the release is left to a human from the web UI.
- >
github-release release
--tag {{.RELEASE_TAG}}
--draft
--description
"See the [CHANGELOG](https://github.com/$GITHUB_USER/$GITHUB_REPO/blob/{{.RELEASE_TAG}}/CHANGELOG.md)"
# Upload the artifacts.
- >
github-release upload
--tag {{.RELEASE_TAG}}
--name timeit-linux-amd64.zip
--file bin/linux/timeit-linux-amd64.zip
- >
github-release upload
--tag {{.RELEASE_TAG}}
--name timeit-darwin-amd64.zip
--file bin/darwin/timeit-darwin-amd64.zip
# We don't push the git tag. Instead, in the web UI, the act of
# transitioning the release from draft to published will create the
# corresponding tag in the remote repository. This is safer, because it
# reduces the situations when one might be tempted to delete a public tag
# due to a mistake in the release.
- cmd: |
echo "Draft release $RELEASE_TAG created successfully."
echo "Remember to publish it in the GitHub web UI https://github.com/$GITHUB_USER/$GITHUB_REPO/releases"
silent: true
env:
GITHUB_USER: marco-m
GITHUB_REPO: timeit
# GITHUB_TOKEN expected to be set securely via `summon` or equivalent
release-linux:
dir: bin/linux
cmds: &release-cmds
- go build -v -ldflags="{{.LDFLAGS}}" ../../cmd/timeit
- zip timeit-$GOOS-$GOARCH.zip timeit
env:
CGO_ENABLED: 0
GOOS: linux
GOARCH: amd64
release-darwin:
dir: bin/darwin
cmds: *release-cmds
env:
CGO_ENABLED: 0
GOOS: darwin
GOARCH: amd64