{{ message }}
Repository navigation
Expand file tree
/
Copy pathpublish
More file actions
executable file
·350 lines (319 loc) · 15.2 KB
/
Copy pathpublish
File metadata and controls
executable file
·350 lines (319 loc) · 15.2 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
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#!/usr/bin/env bash
set -euo pipefail
# shellcheck disable=SC1091
# shellcheck disable=SC1090
source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/functions"
#######################################################################
# Script for releasing Twitter OSS libraries based their Github source.
#
# See: print_usage function for usage.
# NOTE: this script is expected to be run in the directory of the
# project being released.
#######################################################################
VERSION="24.5.0"
NAME="Dodo Publish"
# Util publishes two projects independently
UTIL_COMMANDS="./sbt +publishLocal +publishLocalSigned +publishSigned +publishM2;"
declare "util_name=util"
declare "util_commands=$UTIL_COMMANDS"
# Scrooge publishes it's projects independently for various reasons (including the sbt-plugin and maven-plugin).
# sbt-plugin needs the generator in scala 2.10 and 2.12 and published to m2.
SCROOGE_COMMANDS="./sbt \"project scrooge-thriftValidation\" +publishLocal +publishLocalSigned +publishM2 +publishSigned;"
SCROOGE_COMMANDS="${SCROOGE_COMMANDS}./sbt \"project scrooge-generator\" +publishLocal +publishLocalSigned +publishM2 +publishSigned;"
SCROOGE_COMMANDS="${SCROOGE_COMMANDS}./sbt \"project scrooge-core\" +publishLocal +publishLocalSigned +publishSigned;"
SCROOGE_COMMANDS="${SCROOGE_COMMANDS}./sbt \"project scrooge-linter\" +publishLocalSigned +publishSigned;"
SCROOGE_COMMANDS="${SCROOGE_COMMANDS}./sbt \"project scrooge-serializer\" +publishLocal +publishLocalSigned +publishSigned;"
SCROOGE_COMMANDS="${SCROOGE_COMMANDS}./sbt \"project scrooge-sbt-plugin\" ++2.10.7 ^^0.13.18 publishLocalSigned;"
# our projects use the scrooge-sbt-plugin with sbt 1.x so we also publish the plugin locally unsigned for usage in building
SCROOGE_COMMANDS="${SCROOGE_COMMANDS}./sbt \"project scrooge-sbt-plugin\" ++2.12.12 ^^1.7.1 publishLocal publishLocalSigned;"
declare "scrooge_name=scrooge"
declare "scrooge_commands=$SCROOGE_COMMANDS"
# publish scrooge-sbt-plugin
SCROOGE_SBT_PLUGIN_COMMANDS="./sbt \"project scrooge-sbt-plugin\" ++2.10.7 ^^0.13.18 publishSigned;"
SCROOGE_SBT_PLUGIN_COMMANDS="${SCROOGE_SBT_PLUGIN_COMMANDS}./sbt \"project scrooge-sbt-plugin\" ++2.12.12 ^^1.7.1 publishSigned;"
declare "scroogesbtplugin_name=scrooge-sbt-plugin"
declare "scroogesbtplugin_commands=$SCROOGE_SBT_PLUGIN_COMMANDS"
# publish scrooge-maven-plugin
# We skip javadoc generation due to this issue:
# https://issues.apache.org/jira/browse/MJAVADOC-382
SCROOGE_MAVEN_PLUGIN_COMMANDS="cd scrooge-maven-plugin;mvn -e -Dmaven.javadoc.skip=true deploy -Pgithub;cd ..;"
declare "scroogemavenplugin_name=scrooge-maven-plugin"
declare "scroogemavenplugin_commands=$SCROOGE_MAVEN_PLUGIN_COMMANDS"
FINAGLE_COMMANDS="./sbt +publishLocal +publishLocalSigned +publishSigned"
declare "finagle_name=finagle"
declare "finagle_commands=$FINAGLE_COMMANDS"
TWITTER_SERVER_COMMANDS="./sbt +publishLocal +publishLocalSigned +publishSigned"
declare "twitterserver_name=twitter-server"
declare "twitterserver_commands=$TWITTER_SERVER_COMMANDS"
FINATRA_COMMANDS="sed -i'' -e \"s/\/\/ START EXAMPLES/\/* \/\/ START EXAMPLES/g\" build.sbt;sed -i'' -e \"s/\/\/ END EXAMPLES/*\/ \/\/ END EXAMPLES/g\" build.sbt;"
FINATRA_COMMANDS="${FINATRA_COMMANDS=}./sbt +publishLocalSigned +publishSigned"
declare "finatra_name=finatra"
declare "finatra_commands=$FINATRA_COMMANDS"
GITHUB_API_URL="https://api.github.com"
GITHUB_ACCEPT="Accept: application/vnd.github.v3+json"
GITHUB_API_TOKEN=${API_KEY:-XXXXX}
WORKSPACE=${GITHUB_WORKSPACE:-.}
IS_CI=${CI:-false}
# Validation project list
project_list=( "util" "finagle" "scrooge" "twitter-server" "finatra" "scrooge-sbt-plugin" "scrooge-maven-plugin")
# Initialize defaults
snapshot=false # Snapshot release. Default = false. Set to true for a snapshot release.
release_version="" # Version to be released. While this will be parsed from build.sbt files, we need to perform some up-front validation as well.
phab_id="" # Differential ID to use as the criteria for finding the pre-release commit in the Github repository.
dry_run=false # Output but don't execute the release commands
dry_run_input="false"
verbose=false # prints build configuration options and other verbose statements
function print_usage {
echo "USAGE: $0 --phab-id D123456 --version 17.12.0 --verbose <project>"
echo "Options:
--snapshot False (versioned release) or True (snapshot release). Default: false.
--phab-id Differential ID to use as the criteria for finding the pre-release commit in the develop branch.
--version Version to be released.
--dry-run Output, but do not execute the release. Remotes will still be cloned. Default: false.
--verbose Run in verbose mode. Default: false.
--help Print usage.
project [REQUIRED] Project to publish. Must be one of: ${project_list[*]}."
}
function parse_version {
if [[ "$project" == "scrooge-sbt-plugin" ]] || [[ "$project" == "scrooge-maven-plugin" ]]; then
sed -n 's/val releaseVersion = "\(.*\)"/\1/p' "$WORKSPACE/scrooge/build.sbt"
else
sed -n 's/val releaseVersion = "\(.*\)"/\1/p' "$WORKSPACE/$project/build.sbt"
fi
}
function run_commands {
local commands=$1
IFS=';' read -ra commandsArray <<< "$commands"
for command in "${commandsArray[@]}"; do
if [[ "$verbose" = false ]]; then
command="${command//.\/sbt /./sbt --warn }" # set sbt log level to warn
fi
log "info" "$command"
if [[ "$dry_run" = false ]]; then
retry 2 "$command"
fi
done
}
function release_snapshot {
# start release of the given project
local details=""
if [[ "$dry_run" = true ]]; then details=" (dry-run)"; fi
local -r version=$(parse_version "$project")
if [[ "$version" == *-SNAPSHOT ]]; then
log "info" ""
log "info" "------------------------------------------------------------------------"
log "info" "Snapshot Release $project v$version${details}"
log "info" "------------------------------------------------------------------------"
log "info" ""
run_commands "$(array_get "${project//-/}" commands)"
else
log "error" ""
log "error" "------------------------------------------------------------------------"
log "error" "SKIPPING Snapshot Release $project v$version${details}"
log "error" "Snapshot release requested but project version v$version$ is not a -SNAPSHOT."
log "error" "------------------------------------------------------------------------"
log "error" ""
fi
}
function release {
if [[ "$IS_CI" = true ]]; then
# set up git for pushing commits
git config --global user.email "${API_USER}@twitter.com"
git config --global user.name "$API_USER"
fi
# start release of the given project
local details=""
if [[ "$dry_run" = true ]]; then details=" (dry-run)"; fi
log "info" ""
log "info" "------------------------------------------------------------------------"
log "info" "Release $project v${release_version}${details}"
log "info" "------------------------------------------------------------------------"
log "info" ""
if [[ "$project" != "scrooge-sbt-plugin" ]] && [[ "$project" != "scrooge-maven-plugin" ]]; then
# git fetch branches with a depth to the timestamp of the current release HEAD
log "info" "--- Fetch develop branch commits ---"
if [[ "$IS_CI" = true ]]; then
fetch_branches
fi
# update release from develop branch
log "info" "--- Merging develop branch commits into release branch ---"
log "info" ""
if [[ "$IS_CI" = true ]]; then
merge_release
fi
fi
local -r version=$(parse_version "$project")
if [[ "$version" != "$release_version" ]]; then
log "error" ">>> Parsed version: $version does not equal passed release version: $release_version."
log "error" ">>> Please check the given release version to ensure it is correctly specified."
if [[ "$dry_run" == false ]] ; then
exit 1
else
log "info" ""
fi
fi
# checkout release and run commands
log "info" "--- Running release commands ---"
log "info" ""
if [[ "$dry_run" = false ]]; then
git checkout release
fi
run_commands "$(array_get "${project//-/}" commands)"
if [[ "$project" != "scrooge-sbt-plugin" ]] && [[ "$project" != "scrooge-maven-plugin" ]]; then
# undo any local changes
reset_cmd="git reset HEAD --hard"
log "info" ""
log "info" "-- Undoing any local changes ---"
log "info" "$reset_cmd"
if [[ "$dry_run" = false ]]; then
eval "$reset_cmd"
fi
# push tags when on release (for release)
log "info" ""
log "info" "--- Pushing $project-$version tag to origin/release ---"
push_tag_and_release
github_release
fi
}
function push_tag_and_release {
repository="$project"
if [[ "$project" = scrooge* ]]; then
repository="scrooge"
fi
# we force create here so that we can overwrite if we need to recover a partial state
local -r create_tag="git tag -f $project-$version"
log "info" "$create_tag"
if [[ "$dry_run" = false ]]; then
eval "$create_tag"
fi
if [[ "$IS_CI" = true ]]; then
remote="https://${API_USER}:${GITHUB_API_TOKEN}@github.com/twitter/${repository}.git"
# we force push here so that we can overwrite if we need to recover a partial state
# we want to be to not update anything other than the tag so we specify to push to only the specific tag refspec
local -r push_tag="git push $remote --force refs/tags/$project-$version:refs/tags/$project-$version"
log "info" "$push_tag"
if [[ "$dry_run" = false ]]; then
eval "$push_tag"
fi
# we don't need to force push here--if we're up to date, it will still return 0
local -r push_release="git push $remote HEAD" # pushes HEAD of the current branch to the branch with the same name on the remote
log "info" "$push_release" # we're currently in release, thus this should push local release to remote release
if [[ "$dry_run" = false ]]; then
eval "$push_release"
fi
fi
}
# only done after push_tag_and_release, requires API_KEY env var to be set.
function github_release {
if [[ -n "$GITHUB_API_TOKEN" ]] && [[ "$GITHUB_API_TOKEN" != "XXXXX" ]]; then
release_name="$(echo "$project" | awk '{$1=toupper(substr($1,0,1))substr($1,2)}1') $version"
log "info" "Creating Github release: $release_name"
local -r create_release_curl_cmd="curl -s -o /dev/null -X POST -H \"Authorization: token $GITHUB_API_TOKEN\" -H \"$GITHUB_ACCEPT\" -H \"Content-Type: application/json\" -d '{\"tag_name\": \"$project-$version\", \"name\": \"$release_name\", \"draft\": true}' \"${GITHUB_API_URL}/repos/twitter/$project/releases\""
log "info" "${create_release_curl_cmd/$GITHUB_API_TOKEN/XXXXX}"
if [[ "$dry_run" = false ]]; then
eval "$create_release_curl_cmd"
fi
else
log "info" "Skipping creation of Github release. No GitHub API_KEY specified."
fi
}
function echo_set_options {
if [[ "$verbose" = true ]]; then
log "debug" "------------------------------------------------------------------------"
current_date=$(date "+%YT%H:%M:%S%z")
log "debug" "Twitter $NAME v$VERSION ($current_date)"
log "debug" ""
log "debug" "--- java version ---"
version=$(java -version 2>&1); version_lines=$(echo java -version 2>&1 | wc -l)
i=1; while [ "$i" -le "$version_lines" ]; do
line=$(echo "$version" | head -n $i | tail -n 1)
log "debug" " $line"
i=$((i + 1))
done
log "debug" ""
log "debug" "--- env ---"
log "debug" " SBT_OPTS = $SBT_OPTS"
log "debug" " WORKSPACE = $WORKSPACE"
log "debug" " CI = $IS_CI"
log "debug" ""
log "debug" "--- options ---"
log "debug" " project = $project"
if [[ "$snapshot" = false ]]; then
log "debug" " versioned release = true"
log "debug" " release version = $release_version"
log "debug" " phab-id = $phab_id"
else
log "debug" " snapshot release = true"
fi
log "debug" " dry-run = $dry_run"
log "debug" ""
fi
}
# BEGIN: OPTION PARSING AND VALIDATION ------------------------------------------------------------------
# Simple option parsing. We could use getopts but rather use "long"
# names only. And this is position-agnostic to the options, e.g.,
# these options can occur before or after the main arguments.
shift_count="0"
for arg in "$@"; do
shift
case "$arg" in
"--snapshot") snapshot=true ;;
"--version") release_version=$1; ((shift_count+=1)) ;;
"--phab-id") phab_id=$1; ((shift_count+=1)) ;;
"--dry-run") dry_run_input=$1; ((shift_count+=1)) ;;
"--verbose") verbose=true ;;
"--help") print_usage >&2; exit ;;
*) check_arg $arg;set -- "$@" "$arg"
esac
done
# parse dry run bool
if [[ "$dry_run_input" == "true" ]] || [[ "$dry_run_input" == "1" ]]; then dry_run=true; fi
# if local, set dry run to true
if [[ "$IS_CI" = false ]]; then dry_run=true; fi
# read and validate $project
project="unset"
# need to shift by the number of params set above with values
if [[ "$shift_count" != "0" ]]; then shift $shift_count; fi
if [[ -z "$*" ]]; then print_usage >&2; exit 1; fi
# Read in remaining option -- which should be the project name.
project="$1"
if ! contains_project "$project"; then
log "error" "Project must be one of: ${project_list[*]}" >&2
print_usage >&2
exit 1
fi
if [[ "$snapshot" = false ]] && [[ -z "$phab_id" ]]; then
log "error" "Must supply a differential id with \"--phab-id\"." >&2
print_usage >&2
exit 1
fi
if [[ "$snapshot" = false ]] && [[ -z "$release_version" ]]; then
log "error" "Must supply a release version." >&2
print_usage >&2
exit 1
fi
if [[ "$snapshot" = false ]] && [[ "$dry_run" = false ]] && [[ -z "$API_KEY" ]]; then
log "error" "API_KEY environment variable MUST be set. "
exit 1
fi
# END: OPTION PARSING AND VALIDATION --------------------------------------------------------------------
# SET SBT_OPTS ------------------------------------------------------------------------------------------
export SBT_OPTS="-DSKIP_FLAKY=true -Dsbt.log.noformat=true"
# BEGIN: EXECUTE BUILD ----------------------------------------------------------------------------------
SECONDS=0
echo_set_options
if [[ "$snapshot" = true ]]; then
release_snapshot
else
release
fi
duration="$SECONDS"
FORMATTED=$(date "+%YT%H:%M:%S%z")
log "info" "------------------------------------------------------------------------"
log "info" "RELEASE SUCCESS"
log "info" "------------------------------------------------------------------------"
log "info" "Total time: $duration s"
log "info" "Finished at: $FORMATTED"
log "info" "Twitter $NAME version v$VERSION"
log "info" "------------------------------------------------------------------------"
# END: EXECUTE BUILD ------------------------------------------------------------------------------------
You can’t perform that action at this time.
