-
Notifications
You must be signed in to change notification settings - Fork 20
/
tasks
executable file
·218 lines (207 loc) · 7.49 KB
/
tasks
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
#!/bin/bash
set -Ee
RELEASER_VERSION="2.1.3"
RELEASER_FILE="ops/releaser-${RELEASER_VERSION}"
mkdir -p ops
if [[ ! -f $RELEASER_FILE ]];then
wget --quiet -O $RELEASER_FILE https://github.com/kudulab/releaser/releases/download/${RELEASER_VERSION}/releaser
fi
source $RELEASER_FILE
function check_flavor {
if [ -z "$1" ]; then
echo "Must specify flavor: alpine or ubuntu"
exit 2
fi
}
function setup_github_credentials {
if [ -z "$GITHUB_CREDENTIALS" ]; then
echo "Error: GITHUB_CREDENTIALS not set" >&2
exit 1
fi
# GITHUB_CREDENTIALS should be in format of account-name:api-key
# example HTTPS URL: https://github.com/user/repo.git
# example SSH URL: [email protected]:user/repo.git
OLD_URL=$(git remote get-url origin)
NEW_URL=$(echo $OLD_URL | sed "s|[email protected]:|https://[email protected]/|g")
git remote set-url origin $NEW_URL
echo "GitHub new remote was set"
}
command="$1"
case "${command}" in
_build)
rm -rf bin/dojo
# disable the use of cgo with: CGO_ENABLED=0
(set -x; GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -o bin/dojo_darwin_amd64 ./; )
(set -x; GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o bin/dojo_linux_amd64 ./; )
# to get a list supported golang platforms: go tool dist list
;;
build)
dojo -c Dojofile.build "./tasks _build"
;;
symlink)
if [[ -n "$2" ]]; then
os_suffix=$2
else
echo "Please provide OS prefix: linux or darwin"
exit 5;
fi
# this binary is used in e2e tests
rm -f bin/dojo
ln -s dojo_${os_suffix}_amd64 ./bin/dojo
chmod +x ./bin/dojo
;;
_unit)
(set -x; go test -v -race ./... | sed ''/PASS/s//$(printf "\033[32mPASS\033[0m")/'' | sed ''/FAIL/s//$(printf "\033[31mFAIL\033[0m")/''; )
;;
unit)
dojo -c Dojofile.build "./tasks _unit"
;;
_e2e)
echo "Running task: e2e"
if [[ ! -f "bin/dojo" ]]; then
echo "Error: File bin/dojo not found. Please run either './tasks symlink linux' or ./tasks symlink darwin' depending on your OS"
exit 1
fi
python3 -m venv venv
source venv/bin/activate
pip3 install -r test/requirements.txt
pytest test -vv
;;
e2e)
check_flavor $2
dojo -c Dojofile.e2e-$2 "./tasks _e2e"
;;
test_signals)
check_flavor $2
dojo -c Dojofile.e2e-$2 ./test/signal/signals-tests.sh
;;
set_version)
if [[ -n "$2" ]]; then
next_version="$2"
else
last_version="$(releaser::get_last_version_from_whole_changelog ${changelog_file})"
next_version="$(releaser::bump_patch_version ${last_version})"
fi
releaser::set_version_in_changelog "${changelog_file}" "${next_version}"
echo "package main
const DojoVersion = \"${next_version}\"
" > "./version.go"
releaser::log_info "Set version: ${next_version}"
;;
verify_version)
version="$(releaser::get_last_version_from_whole_changelog ${changelog_file})"
if git tag | grep "${version}"; then
releaser::log_error "The version: ${version} was already git tagged"
exit 1
fi
changelog_first_line=$(cat ${changelog_file} | head -1)
if [[ "${changelog_first_line}" == "#"*"Unreleased"* ]] || [[ "${changelog_first_line}" == "#"*"unreleased"* ]] || [[ "${changelog_first_line}" == "#"*"UNRELEASED"* ]];then
releaser::log_error "Top of changelog has 'Unreleased' flag"
exit 1
fi
if ! grep "${version}" ./version.go >/dev/null; then
releaser::log_error "The file version.go does not contain: ${version}"
exit 1
fi
releaser::log_info "Version: ${version} verified successfully"
;;
release)
version="$(releaser::get_last_version_from_whole_changelog ${changelog_file})"
setup_github_credentials
git tag "${version}"
git push origin "${version}"
;;
release_gh)
if [ ! -f bin/dojo_linux_amd64 ]; then echo "dojo_linux_amd64 binary does not exist"; exit 1; fi
if [ ! -f bin/dojo_darwin_amd64 ]; then echo "dojo_darwin_amd64 binary does not exist"; exit 1; fi
setup_github_credentials
export GITHUB_TOKEN=$(echo $GITHUB_CREDENTIALS | cut -d ":" -f 2)
releaser::prepare_github_release_bin
VERSION="$(releaser::get_last_version_from_whole_changelog ${changelog_file})"
echo "Releasing version ${VERSION}"
GH_USER=kudulab
echo "Creating a GitHub release"
$GHRELEASE_BIN release \
--user $GH_USER \
--repo dojo \
--tag $VERSION \
--name $VERSION \
--description "$(./tasks generate_release_notes ${VERSION})"
echo "Uploading assets (1/2)"
$GHRELEASE_BIN upload \
--user $GH_USER \
--repo dojo \
--tag $VERSION \
--name "dojo_linux_amd64" \
--file bin/dojo_linux_amd64
echo "Uploading assets (2/2)"
$GHRELEASE_BIN upload \
--user $GH_USER \
--repo dojo \
--tag $VERSION \
--name "dojo_darwin_amd64" \
--file bin/dojo_darwin_amd64
echo "Success"
;;
homebrew_tap)
if [ ! -f bin/dojo_darwin_amd64 ]; then echo "dojo_darwin_amd64 binary does not exist"; exit 1; fi
if [ ! -f bin/dojo_linux_amd64 ]; then echo "dojo_linux_amd64 binary does not exist"; exit 1; fi
DARWIN_SHA256=$(sha256sum bin/dojo_darwin_amd64 | awk '{printf $1}')
LINUX_SHA256=$(sha256sum bin/dojo_linux_amd64 | awk '{printf $1}')
VERSION="$(releaser::get_last_version_from_whole_changelog ${changelog_file})"
setup_github_credentials
git clone https://${GITHUB_CREDENTIALS}@github.com/kudulab/homebrew-dojo-osx.git homebrew-dojo-osx
cd homebrew-dojo-osx
cat << EOF > dojo.rb
class Dojo < Formula
desc "Containerize your development and operations environment"
homepage "https://github.com/kudulab/dojo"
version "${VERSION}"
if OS.mac?
url "https://github.com/kudulab/dojo/releases/download/${VERSION}/dojo_darwin_amd64"
sha256 "${DARWIN_SHA256}"
def install
bin.install "dojo_darwin_amd64"
mv bin/"dojo_darwin_amd64", bin/"dojo"
end
elsif OS.linux?
if Hardware::CPU.intel?
url "https://github.com/kudulab/dojo/releases/download/${VERSION}/dojo_linux_amd64"
sha256 "${LINUX_SHA256}"
def install
bin.install "dojo_linux_amd64"
mv bin/"dojo_linux_amd64", bin/"dojo"
end
end
end
end
EOF
git add dojo.rb
echo "Creating a new git commit"
git commit -m "Updated homebrew tap to ${VERSION}"
git push origin master
;;
generate_release_notes)
version=${2?version not set}
changelog="CHANGELOG.md"
start_line_number=$(awk "/${version}/{ print NR; exit }" ${changelog})
# now let's read the file, line by line, starting from start_line_number+1
# up to "###" or the end of file
line_read=0
while read line; do
line_read=$((line_read+1))
if [ "${line_read}" -gt "${start_line_number}" ]; then
if [[ "${line}" == "### "* ]]; then
# stop reading
exit 0
fi
echo "${line}"
fi
done < "${changelog}"
;;
*)
echo "Invalid command: '${command}'"
exit 1
;;
esac
set +e