-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.yml
287 lines (246 loc) · 8.02 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
version: '3'
vars:
PACKAGE_SRC_DIR: manifest
tasks:
download-binary:
desc: Download a binary from GitHub releases
cmds:
- |
if [ -z "{{.REPO}}" ] || [ -z "{{.TAG}}" ] || [ -z "{{.BINARY}}" ]; then
echo "REPO TAG, and BINARY are required"
exit 1
fi
if [ -z "{{.DEBUG}}" ]; then
DEBUG="false"
else
DEBUG="{{.DEBUG}}"
fi
if [ -z "{{.EXTRACT_PATH}}" ]; then
EXTRACT_PATH="/usr/local/bin"
else
EXTRACT_PATH=$(echo "{{.EXTRACT_PATH}}" | sed 's:/*$::')
fi
if [ -z "{{.BINARY}}" ]; then
BASENAME=$(basename "{{.REPO}}")
else
BASENAME="{{.BINARY}}"
fi
if [ -z "{{.SKIP_CHECK}}" ]; then
if ! command -v $BASENAME > /dev/null; then
if [ "$DEBUG" != "false" ]; then
echo "No $BASENAME found, downloading"
fi
else
exit 0
fi
fi
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case $ARCH in
x86_64)
if [ "{{.PREFER_X86}}" = "true" ]; then
ARCH="x86_64"
else
ARCH="amd64"
fi
;;
aarch64) ARCH="arm64" ;;
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
esac
# Determine whether to use curl or wget
DOWNLOAD_CMD=""
if command -v curl > /dev/null; then
DOWNLOAD_CMD="curl -s -L -o"
elif command -v wget > /dev/null; then
DOWNLOAD_CMD="wget -O"
else
if [ "$DEBUG" != "false" ]; then
echo "Neither curl nor wget is available, please install one and retry."
fi
exit 1
fi
# Fetch the release information
if [ "{{.TAG}}" = "latest" ]; then
TAG=$(curl -s "https://api.github.com/repos/{{.REPO}}/releases/latest" | grep "tag_name" | cut -d '"' -f 4)
else
TAG="{{.TAG}}"
fi
RELEASE_INFO=$(curl -s "https://api.github.com/repos/{{.REPO}}/releases/tags/$TAG")
URL=$(echo $RELEASE_INFO | grep -o '"browser_download_url": *"[^"]*"' | grep -E "${OS}_${ARCH}\.(tar\.gz|gz|zip)" | cut -d '"' -f 4)
if [ -z "$URL" ]; then
URL=$(echo $RELEASE_INFO | grep -o '"browser_download_url": *"[^"]*"' | grep -E "${OS}_${ARCH}" | cut -d '"' -f 4)
fi
# Check if a URL was found
if [ -z "$URL" ]; then
echo "Failed to find a release for tag '$TAG' with filename '$FILENAME'."
exit 1
fi
if [[ "$URL" =~ \.tar.gz$ ]]; then
FILETYPE="tar.gz"
elif [[ "$URL" =~ \.zip$ ]]; then
FILETYPE="zip"
elif [[ "$URL" =~ \.gz$ ]]; then
FILETYPE="gz"
else
FILETYPE="binary"
fi
# Construct the download URL and filename
if [ "$FILETYPE" = "binary" ]; then
FILENAME="${BASENAME}_${TAG}_${OS}_${ARCH}"
else
FILENAME="${BASENAME}_${TAG}_${OS}_${ARCH}.${FILETYPE}"
fi
# Download and extract the tar.gz file
if [ "$DEBUG" != "false" ]; then
echo "Downloading $FILENAME from $URL"
fi
$DOWNLOAD_CMD $FILENAME $URL
# Extract the binary
if [ "$DEBUG" != "false" ]; then
echo "Extracting $BASENAME to $EXTRACT_PATH"
fi
if [ "$FILETYPE" = "tar.gz" ]; then
tar -xzf $FILENAME -C . $BASENAME
elif [ "$FILETYPE" = "zip" ]; then
unzip -o $FILENAME -d . $BASENAME
elif [ "$FILETYPE" = "gz" ]; then
gunzip -c $FILENAME > $BASENAME
elif [ "$FILETYPE" = "binary" ]; then
mv $FILENAME $BASENAME
else
echo "Unsupported filetype: $FILETYPE"
exit 1
fi
# Make the binary executable
chmod +x $BASENAME
# Move the binary to the desired location
if [ "{{.CI}}" = "true" ] || [ -w $EXTRACT_PATH ] || ! command -v sudo > /dev/null; then
mv $BASENAME $EXTRACT_PATH/$BASENAME
else
sudo mv $BASENAME $EXTRACT_PATH/$BASENAME
fi
# Cleanup the downloaded tar.gz file if it exists
if [ -f $FILENAME ]; then
rm $FILENAME
fi
install-devtools:
desc: Install development tools
cmds:
- task: download-binary
vars:
REPO: git-chglog/git-chglog
TAG: latest
BINARY: git-chglog
- task: download-binary
vars:
REPO: caarlos0/svu
TAG: latest
BINARY: svu
version:
desc: Print the version
deps: [install-devtools]
cmds:
- svu current --strip-prefix {{.CLI_ARGS}}
next-version:
desc: Get the next version given SemVer
deps: [install-devtools]
cmds:
- |
NEXT=$(svu next --strip-prefix {{.CLI_ARGS}})
if [ -n "{{.PRE_RELEASE}}" ]; then
NEXT="$NEXT-{{.PRE_RELEASE}}"
fi
if [ -n "{{.BUILD_NUMBER}}" ]; then
NEXT="$NEXT+{{.BUILD_NUMBER}}"
fi
echo $NEXT
update-version-file:
desc: Update the version in a specified file
cmds:
- |
NEXT_VERSION="{{.NEXT_VERSION}}"
VERSION_FILE="{{.VERSION_FILE}}"
LANGUAGE="{{.LANGUAGE}}"
if [ -z "$NEXT_VERSION" ] || [ -z "$VERSION_FILE" ] || [ -z "$LANGUAGE" ]; then
echo "CURRENT_VERSION, NEXT_VERSION, VERSION_FILE and LANGUAGE are required"
exit 1
fi
if [ -z "{{.DEBUG}}" ]; then
DEBUG="false"
else
DEBUG="{{.DEBUG}}"
fi
case $LANGUAGE in
python)
VERSION_PATTERN='^version = ".*"'
NEW_VERSION_FORMAT="version = \"$NEXT_VERSION\""
;;
nodejs)
VERSION_PATTERN='^\s*"version": ".*",'
NEW_VERSION_FORMAT="\"version\": \"$NEXT_VERSION\","
;;
rust)
VERSION_PATTERN='^version = ".*"'
NEW_VERSION_FORMAT="version = \"$NEXT_VERSION\""
;;
*)
echo "Unsupported language: $LANGUAGE"
exit 1
;;
esac
# Using sed to replace the line with more precise targeting
sed -i "/$VERSION_PATTERN/c\\$NEW_VERSION_FORMAT" $VERSION_FILE
if [ "$DEBUG" != "false" ]; then
echo "Updated version in $VERSION_FILE to $NEXT_VERSION"
fi
changelog:
desc: Generate the changelog
deps: [install-devtools]
cmds:
- git-chglog {{.CLI_ARGS}}
bump-version:
desc: Bump the version
deps: [install-devtools]
cmds:
- |
CURRENT_VERSION=$(svu current --strip-prefix)
NEXT_VERSION=$(svu next --strip-prefix)
if [ "$CURRENT_VERSION" == "$NEXT_VERSION" ]; then
echo "No new version found, skipping bump"
exit 1
fi
git-chglog -o CHANGELOG.md --next-tag $NEXT_VERSION || true
git add CHANGELOG.md
if [ -n "{{.VERSION_FILE}}" ]; then
if ! task update-version-file NEXT_VERSION=$NEXT_VERSION VERSION_FILE="{{.VERSION_FILE}}" LANGUAGE="{{.LANGUAGE}}"; then
echo "Failed to update version in {{.VERSION_FILE}}"
exit 1
fi
git add "{{.VERSION_FILE}}"
fi
git commit -m "chore(release): Release $NEXT_VERSION"
git tag "$NEXT_VERSION" -m "chore(release): Release $NEXT_VERSION"
exit 0
lint:
cmds:
- |
if [ -n "{{.SRC_DIR}}" ]; then
export SRC_DIR="{{.SRC_DIR}}"
else
export SRC_DIR="{{.PACKAGE_SRC_DIR}}"
fi
- poetry run ruff check $SRC_DIR {{.CLI_ARGS}}
- poetry run ruff format $SRC_DIR {{.CLI_ARGS}}
unit-tests:
cmds:
- coverage run -m pytest --junitxml=report.xml {{.CLI_ARGS}}
- coverage report
- coverage xml
- coverage html -d coverage-report
build:
cmds:
- poetry build --format wheel
publish:
cmds:
- poetry config pypi-token.pypi {{.PYPI_TOKEN}}
- poetry publish