-
Notifications
You must be signed in to change notification settings - Fork 5
/
Taskfile.yml
150 lines (138 loc) · 4.86 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
139
140
141
142
143
144
145
146
147
148
149
150
# Install `task` from https://taskfile.dev
# Run `task --list` to start.
version: '3'
vars:
GOTESTSUM:
sh: "echo $(which gotestsum 2> /dev/null)"
TESTRUNNER: "{{if .GOTESTSUM}}{{base .GOTESTSUM}} --{{else}}go test{{end}}"
#
GOLANGCI_VERSION: v1.55.2
GOTESTSUM_VERSION: v1.11.0
GOLINES_VERSION: v0.12.2
tasks:
install:deps:
desc: Install tool dependencies.
cmds:
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@{{.GOLANGCI_VERSION}}
- go install gotest.tools/gotestsum@{{.GOTESTSUM_VERSION}}
- go install github.com/segmentio/golines@{{.GOLINES_VERSION}}
- go install github.com/github-release/github-release@latest
lint:
desc: Lint the code.
cmds:
- golangci-lint run ./...
lint:linelength:
desc: Enforce max line length. Use the tool output only as a hint, sometimes it makes wrong decisions.
cmds:
- golines --max-len=99 --write-output .
test:
desc: Run all the tests (unit + integration). Use this target to get total coverage.
cmds:
- "{{.TESTRUNNER}} -count=1 -coverprofile=coverage.out ./..."
browser:
desc: "Show code coverage in browser (usage: task test:<subtarget> browser)"
cmds:
- go tool cover -html=coverage.out
build:
desc: Build the terravalet executable.
cmds:
- go build -o bin/terravalet -v -ldflags="{{.LDFLAGS}}" .
vars: &build-vars
FULL_VERSION:
sh: git describe --tags --long --dirty --always
LDFLAGS: -w -s -X main.fullVersion={{.FULL_VERSION}}
#
# usage: RELEASE_TAG=v0.1.0 gopass env gh/terravalet 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 --annotate {{.RELEASE_TAG}} -m 'Release {{.RELEASE_TAG}}'
- task: release-linux
- task: release-darwin-amd
- task: release-darwin-arm
# - 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)"
#
# Since 2024, if we upload immeditately after having created the draft release,
# we get:
#
# error: could not find the release corresponding to tag vX.Y.Z
#
# to avoid this, we sleep a moment :-/
- sleep 2
# Upload the artifacts.
- >
github-release upload
--tag {{.RELEASE_TAG}}
--name terravalet-linux-amd64.zip
--file bin/linux/terravalet-linux-amd64.zip
- >
github-release upload
--tag {{.RELEASE_TAG}}
--name terravalet-darwin-amd64.zip
--file bin/darwin/terravalet-darwin-amd64.zip
- >
github-release upload
--tag {{.RELEASE_TAG}}
--name terravalet-darwin-arm64.zip
--file bin/darwin/terravalet-darwin-arm64.zip
# Push the tag.
- cmd: git push origin {{.RELEASE_TAG}}
# Create a draft 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: pix4d
GITHUB_REPO: terravalet
# GITHUB_TOKEN expected to be set securely via `gopass` or equivalent
release-linux:
cmds:
- go build -o bin/$GOOS/terravalet -v -ldflags="{{.LDFLAGS}}" .
- cd bin/$GOOS && zip terravalet-$GOOS-$GOARCH.zip terravalet
env:
CGO_ENABLED: 0
GOOS: linux
GOARCH: amd64
vars: *build-vars
release-darwin-amd:
cmds:
- go build -o bin/$GOOS/terravalet -v -ldflags="{{.LDFLAGS}}" .
- cd bin/$GOOS && zip terravalet-$GOOS-$GOARCH.zip terravalet
env:
CGO_ENABLED: 0
GOOS: darwin
GOARCH: amd64
vars: *build-vars
release-darwin-arm:
cmds:
- go build -o bin/$GOOS/terravalet -v -ldflags="{{.LDFLAGS}}" .
- cd bin/$GOOS && zip terravalet-$GOOS-$GOARCH.zip terravalet
env:
CGO_ENABLED: 0
GOOS: darwin
GOARCH: arm64
vars: *build-vars