forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrigger-pr-roachtest.sh
More file actions
executable file
·119 lines (101 loc) · 3.09 KB
/
trigger-pr-roachtest.sh
File metadata and controls
executable file
·119 lines (101 loc) · 3.09 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
#!/usr/bin/env bash
# Copyright 2016 The Cockroach Authors.
#
# Use of this software is governed by the CockroachDB Software License
# included in the /LICENSE file.
set -euo pipefail
token=${TEAMCITY_TOKEN-}
if [ -z $token ]; then
cat <<EOF
TEAMCITY_TOKEN not set. Get one here:
https://teamcity.cockroachdb.com/profile.html?item=accessTokens
Usage: $0 <pr-number-or-branch> <test-regex> [sha]
Examples:
$0 12345 'perturbation/full/intents'
$0 my-branch-name 'kv/splits.*' a1b2c3d4
Note: PR numbers work for all cases (recommended). Branch names only work
for branches pushed directly to cockroachdb/cockroach, not personal forks.
For fork branches, use the PR number instead.
Environment variables:
COUNT - number of test iterations (default: 1)
DEBUG - enable debug mode (default: false)
USE_SPOT - use spot VMs: never, auto, always (default: never)
The "auto" default in nightly scripts uses spot for the
first attempt, which causes preemptions on single-iteration
PR-triggered runs. Override here defaults to "never".
EOF
exit 1
fi
pr=${1-}
while [ -z $pr ]; do
read -p 'PR number or branch name (PR number recommended): ' pr
done
tests=${2-}
while [ -z "$tests" ]; do
read -p 'Test Regexp (defaults to second arg): ' tests
done
sha=${3-}
if [ -z "${sha}" ]; then
read -p 'Long Commit SHA (defaults to third arg, empty for latest changes): ' sha
fi
dump_json() {
if echo "$1" | jq '.' >/dev/null 2>&1; then
echo "$1" | jq '.'
else
echo "$1"
fi
}
# NB: if you're trying to trigger a weekly roachtest, need to use
# 'Cockroach_Nightlies_RoachtestWeeklyBazel' as the buildType below.
json_payload=$(jq -n \
--arg branch_name "$pr" \
--arg tests "$tests" \
--arg envDebug "${DEBUG-false}" \
--arg envCount "${COUNT-1}" \
--arg envUseSpot "${USE_SPOT-never}" \
'{
buildType: {id: "Cockroach_Nightlies_RoachtestNightlyGceBazel"},
branchName: $branch_name,
properties: {
property: [
{name: "env.ARM_PROBABILITY", value: "0"},
{name: "env.COCKROACH_EA_PROBABILITY", value: "0"},
{name: "env.SELECT_PROBABILITY", value: "1.0"},
{name: "env.DEBUG", value: $envDebug},
{name: "env.COUNT", value: $envCount},
{name: "env.TESTS", value: $tests},
{name: "env.USE_SPOT", value: $envUseSpot}
]
}
}')
if [ -n "${sha}" ]; then
json_payload=$(echo "${json_payload}" | jq \
--arg branch_name "$pr" \
--arg sha "$sha" \
'. + {
revisions: {
revision: [
{
version: $sha,
vcsBranchName: ("refs/heads/" + $branch_name),
"vcs-root-instance": {
"vcs-root-id": "Cockroach_Cockroach"
}
}
]
}
}')
fi
echo "Input:"
dump_json "$json_payload"
echo "======================================="
echo "Output:"
result=$(curl -ss -X POST \
https://teamcity.cockroachdb.com/app/rest/buildQueue \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H "Authorization: Bearer $token" \
-d "$json_payload")
dump_json "$result"
echo "======================================="
echo "${result}" | jq -r '.webUrl' 2>/dev/null