Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 2 | # ----------------------------------------------------------------------- |
| 3 | # Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 16 | # |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 17 | # github-release.sh |
| 18 | # builds (with make) and uploads release artifacts (binaries, etc.) to github |
| 19 | # given a tag also create checksums files and release notes from the commit |
| 20 | # message |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 21 | # ----------------------------------------------------------------------- |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 22 | # 1) Staging to replace command github-release with gh. |
| 23 | # 2) gh auth / GIT_TOKEN handling may be needed |
| 24 | # ----------------------------------------------------------------------- |
| 25 | # gh release create abc/1.2.3-rc2 --discussion-category "Announcements" --generate-notes hello.txt |
| 26 | # https://github.com/cli/cli/issues/4993 |
| 27 | # ----------------------------------------------------------------------- |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 28 | |
Joey Armstrong | 41923cc | 2023-01-30 14:38:16 -0500 | [diff] [blame] | 29 | # declare -g TRACE=0 # uncomment to set -x |
| 30 | |
| 31 | # shellcheck disable=SC2015 |
| 32 | [[ -v TRACE ]] && { set -x; } || { set +x; } # SC2015 (shellcheck -x) |
| 33 | |
| 34 | |
Joey Armstrong | 7f382ef | 2023-01-25 12:00:08 -0500 | [diff] [blame] | 35 | ##-------------------## |
| 36 | ##---] GLOBALS [---## |
| 37 | ##-------------------## |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 38 | set -euo pipefail |
| 39 | |
| 40 | declare -g scratch # temp workspace for downloads |
| 41 | declare -g gh_cmd # path to gh command |
| 42 | |
Joey Armstrong | 7f382ef | 2023-01-25 12:00:08 -0500 | [diff] [blame] | 43 | declare -g ARGV="$*" # archive for display |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 44 | declare -g SCRIPT_VERSION='1.1' # git changeset needed |
Joey Armstrong | 7f382ef | 2023-01-25 12:00:08 -0500 | [diff] [blame] | 45 | |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 46 | declare -g RELEASE_TEMP |
| 47 | |
Joey Armstrong | 7f382ef | 2023-01-25 12:00:08 -0500 | [diff] [blame] | 48 | ##--------------------## |
| 49 | ##---] INCLUDES [---## |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 50 | ##--------------------# |
Joey Armstrong | 7f382ef | 2023-01-25 12:00:08 -0500 | [diff] [blame] | 51 | # shellcheck disable=SC1091 |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 52 | # source "${pgmdir}/common/common.sh" "${common_args[@]}" |
Joey Armstrong | 7f382ef | 2023-01-25 12:00:08 -0500 | [diff] [blame] | 53 | |
| 54 | ## ----------------------------------------------------------------------- |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 55 | ## Intent: Cleanup scratch area on exit |
| 56 | ## ----------------------------------------------------------------------- |
| 57 | function sigtrap() |
| 58 | { |
| 59 | ## Prevent mishaps |
| 60 | local is_read_only |
| 61 | is_read_only="$(declare -p scratch)" |
| 62 | if [[ $is_read_only != *"declare -r scratch="* ]]; then |
| 63 | echo "ERROR: variable scratch is not read-only, cleanup skipped" |
| 64 | exit 1 |
| 65 | fi |
| 66 | |
| 67 | if [ -d "$scratch" ]; then |
| 68 | /bin/rm -fr "$scratch" |
| 69 | fi |
| 70 | |
| 71 | return |
| 72 | } |
| 73 | trap sigtrap EXIT |
| 74 | |
| 75 | ## ----------------------------------------------------------------------- |
| 76 | ## Intent: Create a scratch area for downloads and transient tools |
| 77 | ## ----------------------------------------------------------------------- |
| 78 | function init() |
| 79 | { |
| 80 | declare -g scratch |
| 81 | |
| 82 | local pkgbase="${0##*/}" # basename |
| 83 | local pkgname="${pkgbase%.*}" |
| 84 | |
| 85 | scratch="$(mktemp -d -t "${pkgname}.XXXXXXXXXX")" |
| 86 | readonly scratch |
| 87 | return |
| 88 | } |
| 89 | |
| 90 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 7f382ef | 2023-01-25 12:00:08 -0500 | [diff] [blame] | 91 | ## Intent: Output a log banner to identify the running script/version. |
| 92 | ## ----------------------------------------------------------------------- |
| 93 | ## TODO: |
| 94 | ## o SCRIPT_VERSION => git changeset for repo:ci-managment |
| 95 | ## o echo "library version: ${env."library.libName.version"}" |
| 96 | # ----------------------------------------------------------------------- |
| 97 | # 14:18:38 > git fetch --no-tags --progress -- https://gerrit.opencord.org/ci-management.git +refs/heads/*:refs/remotes/origin/* # timeout=10 |
| 98 | # 14:18:39 Checking out Revision 50f6e0b97f449b32d32ec0e02d59642000351847 (master) |
| 99 | # ----------------------------------------------------------------------- |
| 100 | function banner() |
| 101 | { |
| 102 | local iam="${0##*/}" |
| 103 | |
| 104 | cat <<EOH |
| 105 | |
| 106 | ** ----------------------------------------------------------------------- |
| 107 | ** IAM: ${iam} :: ${FUNCNAME[0]} |
| 108 | ** ARGV: ${ARGV} |
| 109 | ** PWD: $(/bin/pwd) |
| 110 | ** NOW: $(date '+%Y/%m/%d %H:%M:%S') |
| 111 | ** VER: ${SCRIPT_VERSION:-'unknown'} |
| 112 | ** ----------------------------------------------------------------------- |
| 113 | EOH |
| 114 | |
| 115 | return |
| 116 | } |
| 117 | |
Joey Armstrong | af577ab | 2022-12-15 14:43:33 -0500 | [diff] [blame] | 118 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 50f6e0b | 2023-01-24 14:14:08 -0500 | [diff] [blame] | 119 | ## Intent: |
| 120 | ## Display available command versions |
| 121 | ## A github release job is failing due to a command being mia. |
| 122 | ## ----------------------------------------------------------------------- |
| 123 | function displayCommands() |
| 124 | { |
| 125 | # which git || /bin/true |
| 126 | # git --version || /bin/true |
| 127 | # go version || /bin/true |
| 128 | # helm version || /bin/true |
| 129 | return |
| 130 | } |
| 131 | |
| 132 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 133 | ## Intent: Display filesystem with a banner for logging |
| 134 | ## ----------------------------------------------------------------------- |
| 135 | function displayPwd() |
| 136 | { |
| 137 | local iam="${0##*/}" |
| 138 | echo "** ${iam}: ENTER" |
| 139 | |
| 140 | cat <<EOM |
| 141 | |
| 142 | ** ----------------------------------------------------------------------- |
| 143 | ** IAM: $iam :: ${FUNCNAME[0]} |
| 144 | ** PWD: $(/bin/pwd) |
| 145 | ** ----------------------------------------------------------------------- |
| 146 | EOM |
| 147 | find . -maxdepth 1 -ls |
| 148 | echo "** ${iam}: LEAVE" |
| 149 | return |
| 150 | } |
| 151 | |
| 152 | ## ----------------------------------------------------------------------- |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 153 | ## Intent: Copy files from the build directory into the release staging directory. |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 154 | ## ----------------------------------------------------------------------- |
| 155 | function copyToRelease() |
| 156 | { |
| 157 | local iam="${FUNCNAME[0]}" |
| 158 | echo "** ${iam}: ENTER" |
| 159 | |
| 160 | local artifact_glob="${ARTIFACT_GLOB%/*}" |
| 161 | echo "** ${iam}: $(declare -p ARTIFACT_GLOB) $(declare -p artifact_glob)" |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 162 | |
| 163 | # Copy artifacts into the release temp dir |
| 164 | # shellcheck disable=SC2086 |
| 165 | # cp -v "$ARTIFACT_GLOB" "$RELEASE_TEMP" |
| 166 | echo "rsync -rv --checksum \"$artifact_glob/.\" \"$RELEASE_TEMP/.\"" |
| 167 | rsync -rv --checksum "$artifact_glob/." "$RELEASE_TEMP/." |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 168 | |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 169 | echo "** ${iam}: RELEASE_TEMP=${RELEASE_TEMP}" |
| 170 | find "$RELEASE_TEMP" -print |
| 171 | |
| 172 | echo "** ${iam}: LEAVE" |
| 173 | echo |
| 174 | return |
| 175 | } |
| 176 | |
| 177 | ## ----------------------------------------------------------------------- |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 178 | ## Intent: |
| 179 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 38bfeea | 2023-02-06 18:01:29 -0500 | [diff] [blame] | 180 | function github_release_list() |
| 181 | { |
| 182 | local what="$1" ; shift |
| 183 | local user="$1" ; shift |
| 184 | local repo="$1" ; shift |
| 185 | |
| 186 | local iam="${FUNCNAME[0]}" |
| 187 | echo "** ${iam}: ENTER" |
| 188 | |
| 189 | declare -a cmd=() |
| 190 | |
| 191 | cmd+=("$gh_cmd") |
| 192 | cmd+=('--verbose') |
| 193 | cmd+=('--limit' '10') |
| 194 | cmd+=('release' 'list') |
| 195 | cmd+=('--repo' "opencord/$repo") |
| 196 | |
| 197 | # gh release create [<tag>] [<files>...] |
| 198 | echo "** ${iam}: RUNNING " "${cmd[@]}" |
| 199 | "${cmd[@]}" |
| 200 | |
| 201 | echo "** ${iam}: ENTER" |
| 202 | return |
| 203 | } |
| 204 | |
| 205 | ## ----------------------------------------------------------------------- |
| 206 | ## Intent: |
| 207 | ## ----------------------------------------------------------------------- |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 208 | function github_release_pre() |
| 209 | { |
| 210 | local what="$1" ; shift |
| 211 | local user="$1" ; shift |
| 212 | local repo="$1" ; shift |
| 213 | local tag="$1" ; shift |
| 214 | local name="$1" ; shift |
| 215 | local descr="$1" ; shift |
| 216 | |
| 217 | local iam="${FUNCNAME[0]}" |
| 218 | echo "** ${iam}: ENTER" |
| 219 | |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 220 | declare -p user |
| 221 | declare -p repo |
| 222 | declare -p tag |
| 223 | declare -p name |
| 224 | declare -p descr |
| 225 | |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 226 | case "$what" in |
| 227 | gh) |
| 228 | declare -a cmd=() |
| 229 | |
Joey Armstrong | d94b5e6 | 2023-01-29 19:23:42 -0500 | [diff] [blame] | 230 | ## [TODO] Refactor into a function accepting: |
| 231 | ## --create |
| 232 | ## --info |
| 233 | ## --upload |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 234 | cmd+=("$gh_cmd") |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 235 | # cmd+=('--verbose') |
Joey Armstrong | cf41d33 | 2023-01-30 11:43:05 -0500 | [diff] [blame] | 236 | cmd+=('release' 'create') |
| 237 | cmd+=("$tag") # no switch for tag, pass inline. |
| 238 | # cmd+=('--latest') # auto tag based on origin/master |
| 239 | # cmd+=('--target') # Use when a branch based release is needed. |
| 240 | |
Joey Armstrong | 717c778 | 2023-01-30 09:18:58 -0500 | [diff] [blame] | 241 | cmd+=('--repo' "opencord/$repo") |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 242 | cmd+=('--title' "$name") |
Joey Armstrong | d94b5e6 | 2023-01-29 19:23:42 -0500 | [diff] [blame] | 243 | # cmd+=('--descripton' "$descr") # not supported |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 244 | cmd+=('--discussion-category' "Announcements") |
Joey Armstrong | cf41d33 | 2023-01-30 11:43:05 -0500 | [diff] [blame] | 245 | # cmd+=('--verify-tag') # fatal |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 246 | |
Joey Armstrong | 41923cc | 2023-01-30 14:38:16 -0500 | [diff] [blame] | 247 | declare -p cmd |
| 248 | |
Joey Armstrong | cf41d33 | 2023-01-30 11:43:05 -0500 | [diff] [blame] | 249 | # gh release create [<tag>] [<files>...] |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 250 | echo "** ${iam}: RUNNING " "${cmd[@]}" |
| 251 | "${cmd[@]}" |
| 252 | ;; |
| 253 | |
| 254 | *) |
| 255 | declare -a cmd=() |
| 256 | |
| 257 | cmd+=('github-release') |
| 258 | # cmd+=('--verbose') |
| 259 | cmd+=('release') |
| 260 | cmd+=('--user' "$user") |
| 261 | cmd+=('--repo' "$repo") |
| 262 | cmd+=('--tag' "$tag") |
| 263 | cmd+=('--name' "$name") |
| 264 | cmd+=('--descripton' "$descr") |
| 265 | |
| 266 | echo "** ${iam}: RUNNING " "${cmd[@]}" |
| 267 | "${cmd[@]}" |
| 268 | ;; |
| 269 | esac |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 270 | |
| 271 | echo "** ${iam}: ENTER" |
| 272 | return |
| 273 | } |
| 274 | |
| 275 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 276 | ## Intent: |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 277 | ## ----------------------------------------------------------------------- |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 278 | function install_gh_binary() |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 279 | { |
| 280 | local iam="${FUNCNAME[0]}" |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 281 | echo "** $iam: ENTER" |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 282 | |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 283 | pushd "$scratch" |
| 284 | echo -e "\n** ${iam}: Retrieve latest gh download URLs" |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 285 | |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 286 | local latest="https://github.com/cli/cli/releases/latest" |
| 287 | local tarball="gh.tar.tgz" |
| 288 | |
| 289 | local VER |
| 290 | VER=$(curl --silent -qI "$latest" \ |
| 291 | | awk -F '/' '/^location/ {print substr($NF, 1, length($NF)-1)}') |
| 292 | # echo "VER=[$VER]" |
| 293 | |
| 294 | echo "** ${iam}: Download latest gh binary" |
| 295 | local url="https://github.com/cli/cli/releases/download/${VER}/gh_${VER#v}_linux_amd64.tar.gz" |
| 296 | wget --quiet --output-document="$tarball" "$url" |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 297 | |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 298 | echo "** ${iam}: Unpack tarball" |
| 299 | tar zxf "$tarball" |
| 300 | |
| 301 | gh_cmd="$(find "${scratch}" -name 'gh' -print)" |
| 302 | readonly gh_cmd |
| 303 | |
| 304 | echo "** ${iam} Command: ${gh_cmd}" |
| 305 | echo "** ${iam} Version: $("$gh_cmd" --version)" |
| 306 | popd |
| 307 | |
| 308 | echo "** $iam: LEAVE" |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 309 | return |
| 310 | } |
| 311 | |
Joey Armstrong | af577ab | 2022-12-15 14:43:33 -0500 | [diff] [blame] | 312 | ##----------------## |
| 313 | ##---] MAIN [---## |
| 314 | ##----------------## |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 315 | iam="${0##*/}" |
| 316 | |
Joey Armstrong | 7f382ef | 2023-01-25 12:00:08 -0500 | [diff] [blame] | 317 | banner |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 318 | init |
| 319 | install_gh_binary |
Joey Armstrong | 7f382ef | 2023-01-25 12:00:08 -0500 | [diff] [blame] | 320 | |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 321 | # when not running under Jenkins, use current dir as workspace and a blank |
| 322 | # project name |
| 323 | WORKSPACE=${WORKSPACE:-.} |
| 324 | GERRIT_PROJECT=${GERRIT_PROJECT:-} |
| 325 | |
| 326 | # Github organization (or user) this project is published on. Project name should |
| 327 | # be the same on both Gerrit and GitHub |
| 328 | GITHUB_ORGANIZATION=${GITHUB_ORGANIZATION:-} |
| 329 | |
| 330 | # glob pattern relative to project dir matching release artifacts |
Joey Armstrong | 7f382ef | 2023-01-25 12:00:08 -0500 | [diff] [blame] | 331 | # ARTIFACT_GLOB=${ARTIFACT_GLOB:-"release/*"} # stat -- release/* not found, literal string (?) |
Joey Armstrong | 50f6e0b | 2023-01-24 14:14:08 -0500 | [diff] [blame] | 332 | ARTIFACT_GLOB=${ARTIFACT_GLOB:-"release/."} |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 333 | |
| 334 | # Temporary staging directory to copy artifacts to |
| 335 | RELEASE_TEMP="$WORKSPACE/release" |
Zack Williams | 2f8e847 | 2019-05-21 16:29:06 -0700 | [diff] [blame] | 336 | mkdir -p "$RELEASE_TEMP" |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 337 | |
| 338 | # Use "release" as the default makefile target, can be a space separated list |
| 339 | RELEASE_TARGETS=${RELEASE_TARGETS:-release} |
| 340 | |
Zack Williams | 0f39849 | 2019-10-23 16:02:24 -0700 | [diff] [blame] | 341 | |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 342 | # check that we're on a semver released version, or exit |
| 343 | pushd "$GERRIT_PROJECT" |
| 344 | GIT_VERSION=$(git tag -l --points-at HEAD) |
| 345 | |
Zack Williams | 6e070f5 | 2019-10-04 11:08:59 -0700 | [diff] [blame] | 346 | # match bare versions or v-prefixed golang style version |
| 347 | if [[ "$GIT_VERSION" =~ ^v?([0-9]+)\.([0-9]+)\.([0-9]+)$ ]] |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 348 | then |
| 349 | echo "git has a SemVer released version tag: '$GIT_VERSION'" |
| 350 | echo "Building artifacts for GitHub release." |
| 351 | else |
| 352 | echo "No SemVer released version tag found, exiting..." |
| 353 | exit 0 |
| 354 | fi |
| 355 | popd |
| 356 | |
Zack Williams | 0f39849 | 2019-10-23 16:02:24 -0700 | [diff] [blame] | 357 | # Set and handle GOPATH and PATH |
| 358 | export GOPATH=${GOPATH:-$WORKSPACE/go} |
| 359 | export PATH=$PATH:/usr/lib/go-1.12/bin:/usr/local/go/bin:$GOPATH/bin |
| 360 | |
| 361 | # To support golang projects that require GOPATH to be set and code checked out there |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 362 | # If $DEST_GOPATH is not an empty string: |
Zack Williams | 76356cb | 2019-08-30 10:44:42 -0700 | [diff] [blame] | 363 | # - create GOPATH within WORKSPACE, and destination directory within |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 364 | # - set PATH to include $GOPATH/bin and the system go binaries |
Zack Williams | 76356cb | 2019-08-30 10:44:42 -0700 | [diff] [blame] | 365 | # - move project from $WORKSPACE/$GERRIT_PROJECT to new location in $GOPATH |
| 366 | # - start release process within that directory |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 367 | |
| 368 | DEST_GOPATH=${DEST_GOPATH:-} |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 369 | if [ -n "$DEST_GOPATH" ]; then |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 370 | mkdir -p "$GOPATH/src/$DEST_GOPATH" |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 371 | release_path="$GOPATH/src/$DEST_GOPATH/$GERRIT_PROJECT" |
Zack Williams | 76356cb | 2019-08-30 10:44:42 -0700 | [diff] [blame] | 372 | mv "$WORKSPACE/$GERRIT_PROJECT" "$release_path" |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 373 | else |
| 374 | release_path="$WORKSPACE/$GERRIT_PROJECT" |
| 375 | fi |
| 376 | |
| 377 | if [ ! -f "$release_path/Makefile" ]; then |
| 378 | echo "Makefile not found at $release_path!" |
| 379 | exit 1 |
| 380 | else |
Joey Armstrong | af577ab | 2022-12-15 14:43:33 -0500 | [diff] [blame] | 381 | |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 382 | pushd "$release_path" |
| 383 | |
| 384 | # Release description is sanitized version of the log message |
Joey Armstrong | af577ab | 2022-12-15 14:43:33 -0500 | [diff] [blame] | 385 | RELEASE_DESCRIPTION="$(git log -1 --pretty=%B | tr -dc "[:alnum:]\n\r\.\[\]\:\-\\\/\`\' ")" |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 386 | |
| 387 | # build the release, can be multiple space separated targets |
| 388 | # shellcheck disable=SC2086 |
Joey Armstrong | af577ab | 2022-12-15 14:43:33 -0500 | [diff] [blame] | 389 | make "$RELEASE_TARGETS" |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 390 | |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 391 | # doDebug # deterine why ARTIFACT_GLOB is empty |
| 392 | copyToRelease |
Joey Armstrong | 50f6e0b | 2023-01-24 14:14:08 -0500 | [diff] [blame] | 393 | |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 394 | cat <<EOM |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 395 | |
| 396 | ** ----------------------------------------------------------------------- |
| 397 | ** Create the release: |
| 398 | ** 1) Create initial github release with download area. |
| 399 | ** 2) Generate checksum.SHA256 for all released files. |
| 400 | ** 3) Upload files to complete the release. |
| 401 | ** 4) Display released info from github. |
| 402 | ** ----------------------------------------------------------------------- |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 403 | EOM |
| 404 | |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 405 | # git auth login |
| 406 | # git auth logout |
Joey Armstrong | 38bfeea | 2023-02-06 18:01:29 -0500 | [diff] [blame] | 407 | |
| 408 | gh release list [flags] |
| 409 | echo "** ${iam} List releases" |
| 410 | github_release_list \ |
| 411 | "$GITHUB_ORGANIZATION"\ |
| 412 | "$GERRIT_PROJECT" |
| 413 | |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 414 | # Usage: github-release [global options] <verb> [verb options] |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 415 | # create release |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 416 | echo "** ${iam} Creating Release: $GERRIT_PROJECT - $GIT_VERSION" |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 417 | github_release_pre 'gh'\ |
| 418 | "$GITHUB_ORGANIZATION"\ |
| 419 | "$GERRIT_PROJECT"\ |
| 420 | "$GIT_VERSION"\ |
| 421 | "$GERRIT_PROJECT - $GIT_VERSION"\ |
| 422 | "$RELEASE_DESCRIPTION" |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 423 | |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 424 | echo "** ${iam} Packaging release files" |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 425 | pushd "$RELEASE_TEMP" |
| 426 | |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 427 | echo "** ${iam}: Files to release:" |
| 428 | readarray -t to_release < <(find . -mindepth 1 -maxdepth 1 -type f -print) |
| 429 | declare -p to_release |
Joey Armstrong | d8b6f33 | 2023-01-25 18:35:17 -0500 | [diff] [blame] | 430 | |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 431 | # Generate and check checksums |
Zack Williams | 2f8e847 | 2019-05-21 16:29:06 -0700 | [diff] [blame] | 432 | sha256sum -- * > checksum.SHA256 |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 433 | sha256sum -c < checksum.SHA256 |
| 434 | |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 435 | echo |
| 436 | echo "** ${iam} Checksums(checksum.SHA256):" |
Zack Williams | 0d93d84 | 2019-05-21 17:02:49 -0700 | [diff] [blame] | 437 | cat checksum.SHA256 |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 438 | echo |
Zack Williams | 0d93d84 | 2019-05-21 17:02:49 -0700 | [diff] [blame] | 439 | |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 440 | echo "** ${iam} Upload files being released" |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 441 | |
| 442 | # shellcheck disable=SC2194 |
| 443 | case 'gh' in |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 444 | gh) |
Joey Armstrong | d94b5e6 | 2023-01-29 19:23:42 -0500 | [diff] [blame] | 445 | declare -a cmd=() |
| 446 | cmd+=("$gh_cmd") |
| 447 | cmd+=('release' 'upload') |
Joey Armstrong | cf41d33 | 2023-01-30 11:43:05 -0500 | [diff] [blame] | 448 | cmd+=("$GIT_VERSION") |
Joey Armstrong | 717c778 | 2023-01-30 09:18:58 -0500 | [diff] [blame] | 449 | cmd+=('--repo' "opencord/${GERRIT_PROJECT}") |
Joey Armstrong | d94b5e6 | 2023-01-29 19:23:42 -0500 | [diff] [blame] | 450 | cmd+=("${to_release[@]}") |
Joey Armstrong | cf41d33 | 2023-01-30 11:43:05 -0500 | [diff] [blame] | 451 | |
Joey Armstrong | 41923cc | 2023-01-30 14:38:16 -0500 | [diff] [blame] | 452 | declare -p cmd |
| 453 | |
Joey Armstrong | cf41d33 | 2023-01-30 11:43:05 -0500 | [diff] [blame] | 454 | # gh release upload <tag> <files>... [flags] |
Joey Armstrong | d94b5e6 | 2023-01-29 19:23:42 -0500 | [diff] [blame] | 455 | "${cmd[@]}" |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 456 | ;; |
| 457 | |
| 458 | *) |
| 459 | |
| 460 | # upload all files to the release |
| 461 | for rel_file in * |
| 462 | do |
| 463 | echo "** ${iam} Uploading file: $rel_file" |
| 464 | github-release \ |
| 465 | upload \ |
| 466 | --user "$GITHUB_ORGANIZATION" \ |
| 467 | --repo "$GERRIT_PROJECT" \ |
| 468 | --tag "$GIT_VERSION" \ |
| 469 | --name "$rel_file" \ |
| 470 | --file "$rel_file" |
| 471 | done |
| 472 | ;; |
| 473 | esac |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 474 | |
| 475 | popd |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 476 | popd |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 477 | fi |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 478 | |
| 479 | # [SEE ALSO] |
| 480 | # ----------------------------------------------------------------------- |
| 481 | # https://www.shellcheck.net/wiki/SC2236 |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 482 | # https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#create-a-release |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 483 | # ----------------------------------------------------------------------- |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 484 | # https://cli.github.com/manual/gh_help_reference |
| 485 | # https://cli.github.com/manual/gh_release |
| 486 | # ----------------------------------------------------------------------- |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 487 | |
| 488 | # [EOF] |