-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
135 lines (118 loc) · 3.44 KB
/
Taskfile.yml
File metadata and controls
135 lines (118 loc) · 3.44 KB
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
version: "3"
vars:
RELEASE_BRANCH: '{{default "main" .RELEASE_BRANCH}}'
CURRENT_VERSION:
sh: git describe --tags --match 'v*.*.*' --abbrev=0 2>/dev/null || echo "v0.0.0"
MAJOR:
sh: echo "{{.CURRENT_VERSION}}" | sed -E 's/v([0-9]+)\.[0-9]+\.[0-9]+/\1/'
MINOR:
sh: echo "{{.CURRENT_VERSION}}" | sed -E 's/v[0-9]+\.([0-9]+)\.[0-9]+/\1/'
PATCH:
sh: echo "{{.CURRENT_VERSION}}" | sed -E 's/v[0-9]+\.[0-9]+\.([0-9]+)/\1/'
NEXT_PATCH:
sh: echo $(({{.PATCH}} + 1))
NEXT_MINOR:
sh: echo $(({{.MINOR}} + 1))
NEXT_MAJOR:
sh: echo $(({{.MAJOR}} + 1))
NEW_PATCH_VERSION: "v{{.MAJOR}}.{{.MINOR}}.{{.NEXT_PATCH}}"
NEW_MINOR_VERSION: "v{{.MAJOR}}.{{.NEXT_MINOR}}.0"
NEW_MAJOR_VERSION: "v{{.NEXT_MAJOR}}.0.0"
tasks:
_preflight:
internal: true
desc: Validate branch and remote state before releasing
cmds:
- |
branch=$(git symbolic-ref --quiet --short HEAD) || {
echo "Refusing to release from detached HEAD"; exit 1
}
[ "$branch" = "{{.RELEASE_BRANCH}}" ] || {
echo "Refusing to release from '$branch' (expected {{.RELEASE_BRANCH}})"; exit 1
}
- git fetch origin --tags --prune
- |
[ "$(git rev-parse HEAD)" = "$(git rev-parse origin/{{.RELEASE_BRANCH}})" ] || {
echo "Refusing to release: HEAD is not at origin/{{.RELEASE_BRANCH}}"; exit 1
}
_tag:create:
internal: true
desc: Helper to create and push a git tag
cmds:
- git tag -s "{{.TAG}}" -m "{{.MESSAGE}}"
- git push origin "{{.TAG}}"
version:patch:
desc: Create a new patch version tag
cmds:
- task: _preflight
- task: _tag:create
vars:
TAG: "{{.NEW_PATCH_VERSION}}"
MESSAGE: "Release {{.NEW_PATCH_VERSION}}"
version:minor:
desc: Create a new minor version tag
cmds:
- task: _preflight
- task: _tag:create
vars:
TAG: "{{.NEW_MINOR_VERSION}}"
MESSAGE: "Release {{.NEW_MINOR_VERSION}}"
version:major:
desc: Create a new major version tag
cmds:
- task: _preflight
- task: _tag:create
vars:
TAG: "{{.NEW_MAJOR_VERSION}}"
MESSAGE: "Release {{.NEW_MAJOR_VERSION}}"
release:tag:
desc: Create a GitHub release for a specific tag
requires:
vars: [TAG]
cmds:
- gh release create "{{.TAG}}" --verify-tag --title "{{.TAG}}" --generate-notes
release:latest:
desc: Create a GitHub release for the latest tag
vars:
LATEST_TAG:
sh: git describe --tags --match 'v*.*.*' --abbrev=0
cmds:
- task: release:tag
vars:
TAG: "{{.LATEST_TAG}}"
release:patch:
desc: Create a new patch version and release it on GitHub
cmds:
- task: version:patch
- task: release:latest
release:minor:
desc: Create a new minor version and release it on GitHub
cmds:
- task: version:minor
- task: release:latest
release:major:
desc: Create a new major version and release it on GitHub
cmds:
- task: version:major
- task: release:latest
fmt:
desc: Format Go packages
cmds:
- golangci-lint fmt
lint:
desc: Run golangci-lint
cmds:
- golangci-lint run
fix:
desc: Run golangci-lint with automatic fixes
cmds:
- golangci-lint run --fix
test:
desc: Run tests
cmds:
- go test ./...
ci:
desc: Run lint and test checks
cmds:
- task: lint
- task: test