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 | # ----------------------------------------------------------------------- |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 22 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 23 | set -euo pipefail |
| 24 | |
| 25 | ##-------------------## |
| 26 | ##---] GLOBALS [---## |
| 27 | ##-------------------## |
| 28 | declare -g WORKSPACE |
| 29 | declare -g GERRIT_PROJECT |
Joey Armstrong | 78cecc5 | 2023-04-03 11:39:11 -0400 | [diff] [blame] | 30 | declare -g __githost=github.com |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 31 | # export DEBUG=1 |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 32 | |
| 33 | ## ----------------------------------------------------------------------- |
| 34 | ## Uncomment to activate |
| 35 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 55fe80e | 2023-04-05 18:32:14 -0400 | [diff] [blame] | 36 | declare -i -g gen_version=1 |
| 37 | declare -i -g draft_release=1 |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 38 | |
Joey Armstrong | 41923cc | 2023-01-30 14:38:16 -0500 | [diff] [blame] | 39 | # declare -g TRACE=0 # uncomment to set -x |
| 40 | |
| 41 | # shellcheck disable=SC2015 |
| 42 | [[ -v TRACE ]] && { set -x; } || { set +x; } # SC2015 (shellcheck -x) |
| 43 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 44 | declare -a -g ARGV=() # Capture args to minimize globals and arg passing |
| 45 | [[ $# -gt 0 ]] && ARGV=("$@") |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 46 | |
| 47 | declare -g scratch # temp workspace for downloads |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 48 | |
Joey Armstrong | 78cecc5 | 2023-04-03 11:39:11 -0400 | [diff] [blame] | 49 | declare -g SCRIPT_VERSION='1.3' # git changeset needed |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 50 | |
Joey Armstrong | 7f382ef | 2023-01-25 12:00:08 -0500 | [diff] [blame] | 51 | ##--------------------## |
| 52 | ##---] INCLUDES [---## |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 53 | ##--------------------# |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 54 | |
| 55 | ## ----------------------------------------------------------------------- |
| 56 | ## Intent: Register an interrupt handler to display a stack trace on error |
| 57 | ## ----------------------------------------------------------------------- |
| 58 | function errexit() |
| 59 | { |
| 60 | local err=$? |
| 61 | set +o xtrace |
| 62 | local code="${1:-1}" |
| 63 | |
| 64 | local prefix="${BASH_SOURCE[1]}:${BASH_LINENO[0]}" |
| 65 | echo -e "\nOFFENDER: ${prefix}" |
| 66 | if [ $# -gt 0 ] && [ "$1" == '--stacktrace-quiet' ]; then |
| 67 | code=1 |
| 68 | else |
| 69 | echo "ERROR: '${BASH_COMMAND}' exited with status $err" |
| 70 | fi |
| 71 | |
| 72 | # Print out the stack trace described by $function_stack |
| 73 | if [ ${#FUNCNAME[@]} -gt 2 ] |
| 74 | then |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 75 | echo "Call tree:" |
| 76 | for ((i=1;i<${#FUNCNAME[@]}-1;i++)) |
| 77 | do |
| 78 | echo " $i: ${BASH_SOURCE[$i+1]}:${BASH_LINENO[$i]} ${FUNCNAME[$i]}(...)" |
| 79 | done |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 80 | fi |
| 81 | |
| 82 | echo "Exiting with status ${code}" |
| 83 | echo |
| 84 | exit "${code}" |
| 85 | # return |
| 86 | } |
| 87 | |
| 88 | # trap ERR to provide an error handler whenever a command exits nonzero |
| 89 | # this is a more verbose version of set -o errexit |
| 90 | trap errexit ERR |
| 91 | |
| 92 | # setting errtrace allows our ERR trap handler to be propagated to functions, |
| 93 | # expansions and subshells |
| 94 | set -o errtrace |
Joey Armstrong | 7f382ef | 2023-01-25 12:00:08 -0500 | [diff] [blame] | 95 | |
| 96 | ## ----------------------------------------------------------------------- |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 97 | ## Intent: Cleanup scratch area on exit |
| 98 | ## ----------------------------------------------------------------------- |
| 99 | function sigtrap() |
| 100 | { |
| 101 | ## Prevent mishaps |
| 102 | local is_read_only |
| 103 | is_read_only="$(declare -p scratch)" |
| 104 | if [[ $is_read_only != *"declare -r scratch="* ]]; then |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 105 | echo "ERROR: variable scratch is not read-only, cleanup skipped" |
| 106 | exit 1 |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 107 | fi |
| 108 | |
| 109 | if [ -d "$scratch" ]; then |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 110 | /bin/rm -fr "$scratch" |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 111 | fi |
| 112 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 113 | do_logout |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 114 | return |
| 115 | } |
| 116 | trap sigtrap EXIT |
| 117 | |
| 118 | ## ----------------------------------------------------------------------- |
Joey Armstrong | ad7b1e0 | 2023-03-27 11:55:48 -0400 | [diff] [blame] | 119 | ## Intent: Return a release version for queries |
| 120 | ## Note: Do not use in production, function is intended for interactive use |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 121 | ## ----------------------------------------------------------------------- |
| 122 | function get_version() |
| 123 | { |
| 124 | declare -n ref="$1" |
| 125 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 126 | declare -a rev=() |
| 127 | rev+=("$(( RANDOM % 10 + 1 ))") |
| 128 | rev+=("$(( RANDOM % 256 + 1 ))") |
Joey Armstrong | eef8c2c | 2023-03-27 17:27:43 -0400 | [diff] [blame] | 129 | rev+=("$(( RANDOM % 10000 + 1 ))") |
Joey Armstrong | fc20ed5 | 2023-04-03 19:37:58 -0400 | [diff] [blame] | 130 | local ver="v${rev[0]}.${rev[1]}.${rev[2]}" |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 131 | |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 132 | func_echo "VERSION: $ver" |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 133 | ref="$ver" |
| 134 | return |
| 135 | } |
| 136 | |
| 137 | ## ----------------------------------------------------------------------- |
| 138 | ## Intent: Provide defaults for environment variables |
| 139 | ## ----------------------------------------------------------------------- |
| 140 | function initEnvVars() |
| 141 | { |
| 142 | # when not running under Jenkins, use current dir as workspace and a blank |
| 143 | # project name |
| 144 | declare -g WORKSPACE=${WORKSPACE:-.} |
| 145 | declare -g GERRIT_PROJECT=${GERRIT_PROJECT:-} |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 146 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 147 | # Github organization (or user) this project is published on. Project name should |
| 148 | # be the same on both Gerrit and GitHub |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 149 | declare -g GITHUB_ORGANIZATION=${GITHUB_ORGANIZATION:-} |
| 150 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 151 | # glob pattern relative to project dir matching release artifacts |
| 152 | # ARTIFACT_GLOB=${ARTIFACT_GLOB:-"release/*"} # stat -- release/* not found, literal string (?) |
| 153 | declare -g ARTIFACT_GLOB=${ARTIFACT_GLOB:-"release/."} |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 154 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 155 | # Use "release" as the default makefile target, can be a space separated list |
| 156 | declare -g RELEASE_TARGETS=${RELEASE_TARGETS:-release} |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 157 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 158 | # Set and handle GOPATH and PATH |
| 159 | export GOPATH=${GOPATH:-$WORKSPACE/go} |
| 160 | export PATH=$PATH:/usr/lib/go-1.12/bin:/usr/local/go/bin:$GOPATH/bin |
| 161 | return |
| 162 | } |
| 163 | |
| 164 | ## ----------------------------------------------------------------------- |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 165 | ## Intent: Create a scratch area for downloads and transient tools |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 166 | ## temp directory will be automatically removed upon exit. |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 167 | ## ----------------------------------------------------------------------- |
| 168 | function init() |
| 169 | { |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 170 | local pkgbase="${0##*/}" # basename |
| 171 | local pkgname="${pkgbase%.*}" |
| 172 | |
Joey Armstrong | ad7b1e0 | 2023-03-27 11:55:48 -0400 | [diff] [blame] | 173 | # initEnvVars # moved to full_banner() |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 174 | |
| 175 | ## Create a temp directory for auto-cleanup |
| 176 | declare -g scratch |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 177 | scratch="$(mktemp -d -t "${pkgname}.XXXXXXXXXX")" |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 178 | readonly scratch |
| 179 | declare -p scratch |
| 180 | |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 181 | ## prime the stream: cache answers |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 182 | local work |
| 183 | get_release_dir work |
| 184 | declare -p work |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 185 | |
| 186 | local filler |
| 187 | getGitVersion filler |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 188 | return |
| 189 | } |
| 190 | |
| 191 | ## ----------------------------------------------------------------------- |
| 192 | ## Intent: Verbose output for logging |
| 193 | ## ----------------------------------------------------------------------- |
| 194 | function banner() |
| 195 | { |
| 196 | local iam="${0##*/}" |
| 197 | cat <<EOB |
| 198 | |
| 199 | ** ----------------------------------------------------------------------- |
| 200 | ** ${iam}::${FUNCNAME[1]}: $* |
| 201 | ** ----------------------------------------------------------------------- |
| 202 | EOB |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 7f382ef | 2023-01-25 12:00:08 -0500 | [diff] [blame] | 206 | ## Intent: Output a log banner to identify the running script/version. |
| 207 | ## ----------------------------------------------------------------------- |
| 208 | ## TODO: |
| 209 | ## o SCRIPT_VERSION => git changeset for repo:ci-managment |
| 210 | ## o echo "library version: ${env."library.libName.version"}" |
| 211 | # ----------------------------------------------------------------------- |
| 212 | # 14:18:38 > git fetch --no-tags --progress -- https://gerrit.opencord.org/ci-management.git +refs/heads/*:refs/remotes/origin/* # timeout=10 |
| 213 | # 14:18:39 Checking out Revision 50f6e0b97f449b32d32ec0e02d59642000351847 (master) |
| 214 | # ----------------------------------------------------------------------- |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 215 | function full_banner() |
Joey Armstrong | 7f382ef | 2023-01-25 12:00:08 -0500 | [diff] [blame] | 216 | { |
Joey Armstrong | ad7b1e0 | 2023-03-27 11:55:48 -0400 | [diff] [blame] | 217 | local iam="${0##*/}" |
| 218 | |
| 219 | initEnvVars # set defaults |
Joey Armstrong | 7f382ef | 2023-01-25 12:00:08 -0500 | [diff] [blame] | 220 | |
| 221 | cat <<EOH |
| 222 | |
| 223 | ** ----------------------------------------------------------------------- |
| 224 | ** IAM: ${iam} :: ${FUNCNAME[0]} |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 225 | ** ARGV: ${ARGV[@]} |
Joey Armstrong | 7f382ef | 2023-01-25 12:00:08 -0500 | [diff] [blame] | 226 | ** PWD: $(/bin/pwd) |
| 227 | ** NOW: $(date '+%Y/%m/%d %H:%M:%S') |
| 228 | ** VER: ${SCRIPT_VERSION:-'unknown'} |
| 229 | ** ----------------------------------------------------------------------- |
Joey Armstrong | ad7b1e0 | 2023-03-27 11:55:48 -0400 | [diff] [blame] | 230 | ** GERRIT_PROJECT: $(declare -p GERRIT_PROJECT) |
| 231 | ** GITHUB_ORGANIZATION: $(declare -p GITHUB_ORGANIZATION) |
| 232 | ** RELEASE_TARGETS: $(declare -p RELEASE_TARGETS) |
| 233 | ** GOPATH: $(declare -p GOPATH) |
| 234 | ** ----------------------------------------------------------------------- |
| 235 | ** PATH += /usr/lib/go-1.12/bin:/usr/local/go/bin:GOPATH/bin |
| 236 | ** ----------------------------------------------------------------------- |
Joey Armstrong | 7f382ef | 2023-01-25 12:00:08 -0500 | [diff] [blame] | 237 | EOH |
| 238 | |
| 239 | return |
| 240 | } |
| 241 | |
Joey Armstrong | af577ab | 2022-12-15 14:43:33 -0500 | [diff] [blame] | 242 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 243 | ## Intent: Display a message with 'iam' identifier for logging |
Joey Armstrong | 50f6e0b | 2023-01-24 14:14:08 -0500 | [diff] [blame] | 244 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 245 | function func_echo() |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 246 | { |
| 247 | local iam="${0##*/}" |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 248 | echo "** ${iam} :: ${FUNCNAME[1]}: $*" |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 249 | return |
| 250 | } |
| 251 | |
| 252 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 253 | ## Intent: Display an error message then exit with status. |
| 254 | ## ----------------------------------------------------------------------- |
| 255 | function error() |
| 256 | { |
| 257 | local iam="${0##*/}" |
| 258 | echo "ERROR ${iam} :: ${FUNCNAME[1]}: $*" |
| 259 | exit 1 |
| 260 | } |
| 261 | |
| 262 | ## ----------------------------------------------------------------------- |
| 263 | ## Intent: Verify sandbox/build is versioned for release. |
| 264 | ## ----------------------------------------------------------------------- |
| 265 | function getGitVersion() |
| 266 | { |
| 267 | declare -n varname="$1"; shift |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 268 | |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 269 | local __ver # use prefix('__') to protect callers variable name |
| 270 | if [[ -v cached_getGitVersion ]]; then |
| 271 | __ver="$cached_getGitVersion" |
| 272 | varname="$__ver" |
| 273 | return |
Joey Armstrong | 39fac65 | 2023-03-27 18:50:43 -0400 | [diff] [blame] | 274 | |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 275 | elif [[ -v argv_gen_version ]]; then |
| 276 | get_version __ver |
| 277 | |
| 278 | elif [[ -v WORKSPACE ]] && [[ -v GITHUB_TOKEN ]]; then # i_am_jenkins |
Joey Armstrong | f9a0a88 | 2023-04-17 11:53:57 -0400 | [diff] [blame^] | 279 | local path="$GERRIT_PROJECT" |
| 280 | pushd "$path" || error "pushd GERRIT_PROJECT= failed $(declare -p path)" |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 281 | __ver="$(git tag -l --points-at HEAD)" |
Joey Armstrong | f9a0a88 | 2023-04-17 11:53:57 -0400 | [diff] [blame^] | 282 | popd || error "popd GERRIT_PROJECT= failed" |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 283 | |
| 284 | elif [[ -v argv_version_file ]]; then # local debug |
| 285 | [[ ! -f VERSION ]] && error "./VERSION file not found" |
| 286 | readarray -t tmp < <(sed -e 's/[[:blank:]]//g' 'VERSION') |
| 287 | __ver="v${tmp[0]}" |
| 288 | |
| 289 | else |
Joey Armstrong | f9a0a88 | 2023-04-17 11:53:57 -0400 | [diff] [blame^] | 290 | cd .. |
| 291 | local path="$GERRIT_PROJECT" |
| 292 | pushd "$path" || error "pushd GERRIT_PROJECT= failed $(declare -p path)" |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 293 | __ver="$(git tag -l --points-at HEAD)" |
Joey Armstrong | f9a0a88 | 2023-04-17 11:53:57 -0400 | [diff] [blame^] | 294 | popd || error "popd GERRIT_PROJECT= failed" |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 295 | fi |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 296 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 297 | # ------------------------------------------------------ |
| 298 | # match bare versions or v-prefixed golang style version |
| 299 | # Critical failure for new/yet-to-be-released repo ? |
| 300 | # ------------------------------------------------------ |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 301 | if [[ "$__ver" =~ ^v?([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then |
Joey Armstrong | fc20ed5 | 2023-04-03 19:37:58 -0400 | [diff] [blame] | 302 | echo "git has a SemVer released version tag: '$__ver'" |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 303 | echo "Building artifacts for GitHub release." |
| 304 | |
| 305 | elif [[ "$__ver" =~ ^v?([0-9]+)\.([0-9]+)\.([0-9]+)-dev([0-9]+)$ ]]; then |
| 306 | declare -i -g draft_release=1 |
| 307 | echo "Detected --draft SemVer release version tag [$__ver]" |
| 308 | echo "Building artifacts for GitHub release." |
| 309 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 310 | else |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 311 | error "No SemVer released version tag found, exiting..." |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 312 | fi |
| 313 | |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 314 | ## Cache value for subsequent calls. |
| 315 | ## readonly is a guarantee assignment happens once. |
| 316 | declare -g cached_getGitVersion="$__ver" |
| 317 | readonly cached_getGitVersion; |
| 318 | |
| 319 | varname="$__ver" |
| 320 | func_echo "Version is [$__ver] from $(/bin/pwd)" |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 321 | return |
| 322 | } |
| 323 | |
| 324 | ## ----------------------------------------------------------------------- |
| 325 | ## Intent: |
| 326 | ## Note: Release description is sanitized version of the log message |
| 327 | ## ----------------------------------------------------------------------- |
| 328 | function getReleaseDescription() |
| 329 | { |
| 330 | declare -n varname="$1"; shift |
| 331 | |
| 332 | local msg |
| 333 | msg="$(git log -1 --pretty=%B)" |
| 334 | |
| 335 | local val |
| 336 | val="$(tr -dc "[:alnum:]\n\r\.\[\]\:\-\\\/\`\' " <<< "$msg")" |
| 337 | |
| 338 | [[ ${#val} -eq 0 ]] && error "Release Description is empty ($msg)" |
| 339 | varname="$val" |
| 340 | return |
| 341 | } |
| 342 | |
| 343 | ## ----------------------------------------------------------------------- |
| 344 | ## Intent: Retrieve value of the release temp directory. |
| 345 | ## ----------------------------------------------------------------------- |
| 346 | ## Note: Limit use of globals so logic can be isolated in function calls. |
| 347 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 348 | function get_release_dir() |
| 349 | { |
| 350 | declare -n varname=$1; shift |
| 351 | |
| 352 | # Temporary staging directory to copy artifacts to |
| 353 | varname="$scratch/release" |
| 354 | mkdir -p "$varname" |
| 355 | return |
| 356 | } |
| 357 | |
| 358 | ## ----------------------------------------------------------------------- |
| 359 | ## Intent: Retrieve github server hostname |
| 360 | ## ----------------------------------------------------------------------- |
| 361 | function get_gh_hostname() |
| 362 | { |
| 363 | declare -n varname=$1; shift |
| 364 | varname+=('--hostname' "${__githost}") |
| 365 | return |
| 366 | } |
| 367 | |
| 368 | ## ----------------------------------------------------------------------- |
| 369 | ## Intent: Retrieve repository organizaiton name |
| 370 | ## ----------------------------------------------------------------------- |
| 371 | function get_gh_repo_org() |
| 372 | { |
| 373 | declare -n varname=$1; shift |
| 374 | declare -g __repo_org |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 375 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 376 | local org |
| 377 | if [[ -v __repo_org ]]; then |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 378 | org="$__repo_org" |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 379 | elif [[ ! -v GITHUB_ORGANIZATION ]]; then |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 380 | error "--repo-org or GITHUB_ORGANIZATION= are required" |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 381 | else |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 382 | org="${GITHUB_ORGANIZATION}" |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 383 | fi |
| 384 | |
| 385 | # shellcheck disable=SC2178 |
| 386 | varname="$org" |
| 387 | return |
| 388 | } |
| 389 | |
| 390 | ## ----------------------------------------------------------------------- |
| 391 | ## Intent: Retrieve repository organizaiton name |
| 392 | ## ----------------------------------------------------------------------- |
| 393 | function get_gh_repo_name() |
| 394 | { |
| 395 | declare -n varname=$1; shift |
| 396 | declare -g __repo_name |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 397 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 398 | local name |
| 399 | if [[ -v __repo_name ]]; then |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 400 | name="$__repo_name" |
Joey Armstrong | 39fac65 | 2023-03-27 18:50:43 -0400 | [diff] [blame] | 401 | elif [[ ! -v GERRIT_PROJECT ]]; then |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 402 | error "--repo-name or GERRIT_PROJECT= are required" |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 403 | else |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 404 | name="${GERRIT_PROJECT}" |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 405 | fi |
| 406 | |
| 407 | varname="$name" |
| 408 | return |
| 409 | } |
| 410 | |
| 411 | ## ----------------------------------------------------------------------- |
| 412 | ## Intent: Return path for the gh release query |
| 413 | ## ----------------------------------------------------------------------- |
| 414 | function get_gh_releases() |
| 415 | { |
| 416 | declare -n ref="$1" |
| 417 | |
| 418 | local repo_org |
| 419 | get_gh_repo_org repo_org |
| 420 | |
| 421 | local repo_name |
| 422 | get_gh_repo_name repo_name |
| 423 | |
| 424 | ref="repos/${repo_org}/${repo_name}/releases" |
| 425 | func_echo "ref=$ref" |
| 426 | return |
| 427 | } |
| 428 | |
| 429 | ## ----------------------------------------------------------------------- |
| 430 | ## Intent: Retrieve repository path argument |
| 431 | ## ----------------------------------------------------------------------- |
| 432 | function get_argv_repo() |
| 433 | { |
| 434 | declare -n varname=$1; shift |
| 435 | |
| 436 | local repo_org |
| 437 | get_gh_repo_org repo_org |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 438 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 439 | local repo_name |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 440 | get_gh_repo_name repo_name |
| 441 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 442 | varname="${repo_org}/${repo_name}" |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 443 | # func_echo "VARNAME=$varname" |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 444 | return |
| 445 | } |
| 446 | |
| 447 | ## ----------------------------------------------------------------------- |
| 448 | ## Intent: Retrieve release name string "project - version" |
| 449 | ## ----------------------------------------------------------------------- |
| 450 | function get_argv_name() |
| 451 | { |
| 452 | declare -n varname=$1; shift |
| 453 | |
| 454 | local repo_name |
| 455 | get_gh_repo_name repo_name |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 456 | |
| 457 | local repo_ver |
| 458 | getGitVersion repo_ver |
| 459 | |
| 460 | # varname="${repo_name} - $GIT_VERSION" |
| 461 | varname="${repo_name} - ${repo_ver}" |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 462 | func_echo "varname=$varname" |
| 463 | return |
| 464 | } |
| 465 | |
| 466 | ## ----------------------------------------------------------------------- |
| 467 | ## Intent: Retrieve tag version |
| 468 | ## ----------------------------------------------------------------------- |
| 469 | function get_argv_tag() |
| 470 | { |
| 471 | declare -n varname=$1; shift |
| 472 | |
| 473 | # cached_argv_tag='v3.41.3204' |
| 474 | if [[ ! -v cached_argv_tag ]]; then |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 475 | declare -g cached_argv_tag |
| 476 | if [[ -v GIT_VERSION ]]; then # hello jenkins |
| 477 | cached_argv_tag="$GIT_VERSION" |
| 478 | fi |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 479 | fi |
| 480 | |
| 481 | [[ ${#cached_argv_tag} -eq 0 ]] && error "Unable to determine GIT_VERSION=" |
| 482 | varname="$cached_argv_tag" |
| 483 | func_echo "varname=$varname" |
| 484 | return |
| 485 | } |
| 486 | |
| 487 | ## ----------------------------------------------------------------------- |
| 488 | ## Intent: |
| 489 | ## ----------------------------------------------------------------------- |
| 490 | # To support golang projects that require GOPATH to be set and code checked out there |
| 491 | # If $DEST_GOPATH is not an empty string: |
| 492 | # - create GOPATH within WORKSPACE, and destination directory within |
| 493 | # - set PATH to include $GOPATH/bin and the system go binaries |
| 494 | # - move project from $WORKSPACE/$GERRIT_PROJECT to new location in $GOPATH |
| 495 | # - start release process within that directory |
| 496 | ## ----------------------------------------------------------------------- |
| 497 | function get_release_path() |
| 498 | { |
| 499 | declare -n varname=$1; shift |
| 500 | |
| 501 | DEST_GOPATH=${DEST_GOPATH:-} |
| 502 | if [ -n "$DEST_GOPATH" ]; then |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 503 | mkdir -p "$GOPATH/src/$DEST_GOPATH" |
| 504 | varname="$GOPATH/src/$DEST_GOPATH/$GERRIT_PROJECT" |
| 505 | mv "$WORKSPACE/$GERRIT_PROJECT" "$varname" |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 506 | else |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 507 | varname="$WORKSPACE/$GERRIT_PROJECT" |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 508 | fi |
| 509 | |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 510 | ## Verify pwd is OK |
| 511 | for path in \ |
| 512 | "$varname/Makefile"\ |
| 513 | "$varname/makefile"\ |
| 514 | "__ERROR__"\ |
| 515 | ; do |
| 516 | case "$path" in |
| 517 | __ERROR__) error "Makefile not found at $varname!" ;; |
| 518 | *) [[ -f "$path" ]] && break ;; |
| 519 | esac |
| 520 | done |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 521 | |
| 522 | return |
| 523 | } |
| 524 | |
| 525 | ## ----------------------------------------------------------------------- |
| 526 | ## Intent: Display future enhancements |
| 527 | ## ----------------------------------------------------------------------- |
| 528 | function todo() |
| 529 | { |
| 530 | local iam="${0##*/}" |
| 531 | |
| 532 | cat <<EOT |
| 533 | |
| 534 | ** ----------------------------------------------------------------------- |
| 535 | ** IAM: ${iam} :: ${FUNCNAME[0]} |
| 536 | ** ----------------------------------------------------------------------- |
| 537 | o get_release_path() |
| 538 | - refactor redundant paths into local vars. |
| 539 | - see comments, do we have a one-off failure condition ? |
Joey Armstrong | ad7b1e0 | 2023-03-27 11:55:48 -0400 | [diff] [blame] | 540 | o PATH += golang appended 3 times, release needs a single, reliable answer. |
| 541 | o do_login, do_logout and api calls do not use the my_gh wrapper: |
| 542 | - Add a lookup function to cache and retrieve path to downloaded gh command. |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 543 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 544 | EOT |
| 545 | |
| 546 | return |
| 547 | } |
| 548 | |
| 549 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 550 | ## Intent: Verify a directory contains content for release. |
| 551 | ## ----------------------------------------------------------------------- |
| 552 | ## Given: |
| 553 | ## scalar Path to release/ directory |
| 554 | ## ref Results returned through this indirect var. |
| 555 | ## ----------------------------------------------------------------------- |
| 556 | ## Usage: |
| 557 | ## declare -a artifacts=() |
| 558 | ## get_artifacts '/foo/bar/tans' artifacts |
| 559 | ## declare -p artifacts |
| 560 | ## ----------------------------------------------------------------------- |
| 561 | function get_artifacts() |
| 562 | { |
| 563 | local dir="$1" ; shift |
| 564 | declare -n ref=$1 ; shift |
| 565 | |
Joey Armstrong | 55fe80e | 2023-04-05 18:32:14 -0400 | [diff] [blame] | 566 | # Glob available files, exclude checksums |
| 567 | readarray -t __artifacts < <(find "$dir" -mindepth 1 ! -type d \ |
Joey Armstrong | f9a0a88 | 2023-04-17 11:53:57 -0400 | [diff] [blame^] | 568 | | grep -iv -e 'sum256' -e 'checksum') |
| 569 | # func_echo "$(declare -p __artifacts)" |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 570 | |
| 571 | # ----------------------------------------------------------------------- |
| 572 | # Verify count>0 to inhibit source-only release |
| 573 | # Problem children: |
| 574 | # o build or make release failures. |
| 575 | # o docker container filesystem mount problem (~volume) |
| 576 | # ----------------------------------------------------------------------- |
| 577 | [[ ${#__artifacts[@]} -eq 0 ]] \ |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 578 | && error "Artifact dir is empty: $(declare -p dir)" |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 579 | |
| 580 | ref=("${__artifacts[@]}") |
| 581 | return |
| 582 | } |
| 583 | |
| 584 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 585 | ## Intent: Copy files from the build directory into the release staging |
| 586 | ## directory for publishing to github releases/ endpoint. |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 587 | ## ----------------------------------------------------------------------- |
| 588 | function copyToRelease() |
| 589 | { |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 590 | banner '' |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 591 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 592 | local artifact_glob="${ARTIFACT_GLOB%/*}" |
| 593 | func_echo "$(declare -p artifact_glob)" |
| 594 | |
| 595 | local work |
| 596 | get_release_dir work |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 597 | func_echo "Artifact dir: $(declare -p work)" |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 598 | |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 599 | ## Verify release content is available |
| 600 | declare -a artifacts=() |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 601 | # get_artifacts "$work" artifacts |
| 602 | get_artifacts "$artifact_glob" artifacts |
| 603 | func_echo "Artifacts in copy_from: $(declare -p artifacts)" |
Joey Armstrong | 472bfba | 2023-03-27 18:12:28 -0400 | [diff] [blame] | 604 | |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 605 | # Copy artifacts into the release temp dir |
| 606 | # shellcheck disable=SC2086 |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 607 | echo "rsync -rv --checksum \"$artifact_glob/.\" \"$work/.\"" |
| 608 | rsync -rv --checksum "$artifact_glob/." "$work/." |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 609 | |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 610 | get_artifacts "$work" artifacts |
| 611 | func_echo "Artifacts in copy_to: $(declare -p artifacts)" |
| 612 | |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 613 | return |
| 614 | } |
| 615 | |
| 616 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 617 | ## https://docs.github.com/en/rest/releases?apiVersion=2022-11-28 |
| 618 | # https://cli.github.com/manual/gh_release_create |
| 619 | # --target <branch> or commit SHA |
| 620 | # --title |
| 621 | # --generate-notes |
| 622 | # --release-notes (notes file) |
| 623 | # --release |
| 624 | # release create dist/*.tgz |
| 625 | # --discussion-category "General" |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 626 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 627 | # https://cli.github.com/manual/gh_release_create |
| 628 | ## ----------------------------------------------------------------------- |
| 629 | function gh_release_create() |
Joey Armstrong | 38bfeea | 2023-02-06 18:01:29 -0500 | [diff] [blame] | 630 | { |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 631 | banner '' |
Joey Armstrong | 38bfeea | 2023-02-06 18:01:29 -0500 | [diff] [blame] | 632 | |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 633 | local version |
| 634 | getGitVersion version |
Joey Armstrong | 38bfeea | 2023-02-06 18:01:29 -0500 | [diff] [blame] | 635 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 636 | local work |
| 637 | get_release_dir work |
| 638 | |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 639 | declare -a args=() |
| 640 | args+=('--host-repo') |
| 641 | args+=('--title') |
| 642 | if [[ -v draft_release ]]; then |
| 643 | args+=('--draft') |
| 644 | else |
| 645 | args+=('--discussion-category' 'Announcements') |
| 646 | fi |
| 647 | |
Joey Armstrong | 55fe80e | 2023-04-05 18:32:14 -0400 | [diff] [blame] | 648 | if [[ -v release_notes ]]; then |
Joey Armstrong | f9a0a88 | 2023-04-17 11:53:57 -0400 | [diff] [blame^] | 649 | args+=('--notes-file' "$release_notes") |
Joey Armstrong | 55fe80e | 2023-04-05 18:32:14 -0400 | [diff] [blame] | 650 | fi |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 651 | |
Joey Armstrong | 78cecc5 | 2023-04-03 11:39:11 -0400 | [diff] [blame] | 652 | pushd "$work/.." >/dev/null |
Joey Armstrong | f9a0a88 | 2023-04-17 11:53:57 -0400 | [diff] [blame^] | 653 | # func_echo "WORK=$work" |
Joey Armstrong | 78cecc5 | 2023-04-03 11:39:11 -0400 | [diff] [blame] | 654 | readarray -t payload < <(find 'release' -maxdepth 4 ! -type d -print) |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 655 | |
Joey Armstrong | ad7b1e0 | 2023-03-27 11:55:48 -0400 | [diff] [blame] | 656 | func_echo "$gh_cmd release create ${version} ${args[@]}" "${payload[@]}" |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 657 | |
| 658 | if [[ -v dry_run ]]; then |
| 659 | echo "[SKIP] dry run" |
| 660 | else |
Joey Armstrong | 78cecc5 | 2023-04-03 11:39:11 -0400 | [diff] [blame] | 661 | func_echo "my_gh release create '$version' ${args[@]} ${payload[@]}" |
Joey Armstrong | f9a0a88 | 2023-04-17 11:53:57 -0400 | [diff] [blame^] | 662 | exit 1 |
Joey Armstrong | 4dbe700 | 2023-04-04 12:47:38 -0400 | [diff] [blame] | 663 | my_gh 'release' 'create' "$version" "${args[@]}" "${payload[@]}" |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 664 | set +x |
| 665 | fi |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 666 | popd >/dev/null |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 667 | |
Joey Armstrong | 38bfeea | 2023-02-06 18:01:29 -0500 | [diff] [blame] | 668 | return |
| 669 | } |
| 670 | |
| 671 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 672 | ## Intent: Authenticate credentials for a github gh session |
Joey Armstrong | 38bfeea | 2023-02-06 18:01:29 -0500 | [diff] [blame] | 673 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 674 | ## NOTE: my_gh currently unused due to --with-token < "$pac" |
| 675 | ## ----------------------------------------------------------------------- |
| 676 | function do_login() |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 677 | { |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 678 | declare -g pac |
Joey Armstrong | 485081f | 2023-03-27 13:34:08 -0400 | [diff] [blame] | 679 | declare -a login_args=() |
| 680 | [[ $# -gt 0 ]] && login_args+=("$@") |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 681 | |
Joey Armstrong | 485081f | 2023-03-27 13:34:08 -0400 | [diff] [blame] | 682 | # https://github.com/cli/cli/issues/2922#issuecomment-775027762 |
Joey Armstrong | 75a0d93 | 2023-03-28 08:59:54 -0400 | [diff] [blame] | 683 | # (sigh) why not quietly return VS forcing a special logic path |
Joey Armstrong | e6e18eb | 2023-03-27 14:19:21 -0400 | [diff] [blame] | 684 | # [[ -v WORKSPACE ]] && [[ -v GITHUB_TOKEN ]] && return |
| 685 | |
| 686 | # 12:58:36 ** ----------------------------------------------------------------------- |
| 687 | # 12:58:36 ** jenkins582353203049151829.sh::do_login: --hostname github.com |
| 688 | # 12:58:36 ** --------------------------------------------------------------------# --- |
| 689 | # 12:58:36 ** jenkins582353203049151829.sh :: do_login: Detected ENV{GITHUB_TOKEN}= |
| 690 | # 12:58:36 The value of the GITHUB_TOKEN environment variable is being used for authentication. |
| 691 | # 12:58:36 To have GitHub CLI store credentials instead, first clear the value from the environment. |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 692 | # ----------------------------------------------------------------------- |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 693 | |
Joey Armstrong | 485081f | 2023-03-27 13:34:08 -0400 | [diff] [blame] | 694 | get_gh_hostname login_args |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 695 | |
Joey Armstrong | 485081f | 2023-03-27 13:34:08 -0400 | [diff] [blame] | 696 | banner "${login_args[@]}" |
Joey Armstrong | 78cecc5 | 2023-04-03 11:39:11 -0400 | [diff] [blame] | 697 | func_echo "$(declare -p WORKSPACE)" |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 698 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 699 | ## Read from disk is safer than export GITHUB_TOKEN= |
| 700 | if [[ -v pac ]] && [[ ${#pac} -gt 0 ]]; then # interactive/debugging |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 701 | [ ! -f "$pac" ] && error "PAC token file $pac does not exist" |
Joey Armstrong | 78cecc5 | 2023-04-03 11:39:11 -0400 | [diff] [blame] | 702 | func_echo "$gh_cmd auth login ${login_args[@]} --with-token < $pac" |
Joey Armstrong | 485081f | 2023-03-27 13:34:08 -0400 | [diff] [blame] | 703 | "$gh_cmd" auth login "${login_args[@]}" --with-token < "$pac" |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 704 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 705 | elif [[ ! -v GITHUB_TOKEN ]]; then |
| 706 | error "--token [t] or GITHUB_TOKEN= are required" |
Joey Armstrong | 41923cc | 2023-01-30 14:38:16 -0500 | [diff] [blame] | 707 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 708 | else # jenkins |
Joey Armstrong | 78cecc5 | 2023-04-03 11:39:11 -0400 | [diff] [blame] | 709 | func_echo "$gh_cmd auth login ${login_args[@]} (ie: jenkins)" |
Joey Armstrong | 733ea9f | 2023-04-03 21:19:46 -0400 | [diff] [blame] | 710 | |
Joey Armstrong | f9a0a88 | 2023-04-17 11:53:57 -0400 | [diff] [blame^] | 711 | # https://github.com/cli/cli/issues/2922#issuecomment-775027762 |
| 712 | # When using GITHUB_TOKEN, there is no need to even run gh auth login |
Joey Armstrong | 733ea9f | 2023-04-03 21:19:46 -0400 | [diff] [blame] | 713 | # "$gh_cmd" auth login "${login_args[@]}" |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 714 | fi |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 715 | |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 716 | declare -i -g active_login=1 # signal logout needed |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 717 | |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 718 | return |
| 719 | } |
| 720 | |
| 721 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 722 | ## Intent: Destroy credentials/gh session authenticated by do_login |
| 723 | ## ----------------------------------------------------------------------- |
| 724 | ## NOTE: my_gh currently unused due to "<<< 'y'" |
| 725 | ## ----------------------------------------------------------------------- |
| 726 | function do_logout() |
| 727 | { |
| 728 | declare -i -g active_login |
| 729 | [[ ! -v active_login ]] && return |
| 730 | |
Joey Armstrong | 78cecc5 | 2023-04-03 11:39:11 -0400 | [diff] [blame] | 731 | declare -a logout_args=() |
| 732 | [[ $# -gt 0 ]] && logout_args+=("$@") |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 733 | |
Joey Armstrong | 78cecc5 | 2023-04-03 11:39:11 -0400 | [diff] [blame] | 734 | get_gh_hostname logout_args |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 735 | |
Joey Armstrong | 78cecc5 | 2023-04-03 11:39:11 -0400 | [diff] [blame] | 736 | banner "${logout_args[@]}" |
| 737 | func_echo "$gh_cmd auth logout ${logout_args[@]} <<< 'Y'" |
| 738 | "$gh_cmd" auth logout "${logout_args[@]}" <<< 'Y' |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 739 | |
| 740 | unset active_login |
| 741 | return |
| 742 | } |
| 743 | |
| 744 | ## ----------------------------------------------------------------------- |
| 745 | ## Intent: Query for repository version strings |
| 746 | ## ----------------------------------------------------------------------- |
| 747 | function get_releases() |
| 748 | { |
| 749 | declare -n ref="$1"; shift |
| 750 | local func="${FUNCNAME[0]}" |
| 751 | |
| 752 | banner "" |
| 753 | pushd "$scratch" >/dev/null |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 754 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 755 | # gh api repos/{owner}/{repo}/releases |
| 756 | local releases_uri |
| 757 | get_gh_releases releases_uri |
Joey Armstrong | f9a0a88 | 2023-04-17 11:53:57 -0400 | [diff] [blame^] | 758 | # declare -p releases_uri |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 759 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 760 | ref=() |
Joey Armstrong | ad7b1e0 | 2023-03-27 11:55:48 -0400 | [diff] [blame] | 761 | "$gh_cmd" api "$releases_uri" "${common[@]}" | jq . > 'release.raw' |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 762 | readarray -t __tmp < <(jq '.[] | "\(.tag_name)"' 'release.raw') |
| 763 | |
| 764 | local release |
| 765 | for release in "${__tmp[@]}"; |
| 766 | do |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 767 | release="${release//\"/}" |
| 768 | ref+=("$release") |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 769 | done |
| 770 | |
| 771 | popd >/dev/null |
| 772 | return |
| 773 | } |
| 774 | |
| 775 | ## ----------------------------------------------------------------------- |
| 776 | ## Intent: Display repository query strings. |
| 777 | ## Indirect: verify authentication and API |
| 778 | ## ----------------------------------------------------------------------- |
| 779 | function showReleases() |
| 780 | { |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 781 | declare -a raw=() |
| 782 | get_releases raw |
| 783 | |
| 784 | ## Sort for display, we may need to prune volume later on |
| 785 | IFS=$'\n' releases=($(sort -nr <<<"${raw[*]}")) |
| 786 | unset IFS |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 787 | |
| 788 | local release |
| 789 | for release in "${releases[@]}"; |
| 790 | do |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 791 | func_echo "$release" |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 792 | done |
| 793 | return |
| 794 | } |
| 795 | |
| 796 | ## ----------------------------------------------------------------------- |
| 797 | ## Intent: Install the gh command line tool locally |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 798 | ## ----------------------------------------------------------------------- |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 799 | function install_gh_binary() |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 800 | { |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 801 | banner |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 802 | |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 803 | pushd "$scratch" |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 804 | func_echo "Retrieve latest gh download URLs" |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 805 | |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 806 | local latest="https://github.com/cli/cli/releases/latest" |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 807 | local tarball="gh.tar.tgz" |
| 808 | |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 809 | readarray -t latest < <(\ |
| 810 | curl --silent -qI "$latest" \ |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 811 | | awk -F '/' '/^location/ {print substr($NF, 1, length($NF)-1)}') |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 812 | declare -p latest |
| 813 | if [ ${#latest[@]} -ne 1 ]; then |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 814 | error "Unable to determine latest gh package version" |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 815 | fi |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 816 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 817 | local VER="${latest[0]}" |
| 818 | |
| 819 | func_echo "Download latest gh binary" |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 820 | local url="https://github.com/cli/cli/releases/download/${VER}/gh_${VER#v}_linux_amd64.tar.gz" |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 821 | func_echo "wget --quiet --output-document='$tarball' '$url'" |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 822 | wget --quiet --output-document="$tarball" "$url" |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 823 | |
| 824 | func_echo "Unpack tarball" |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 825 | tar zxf "$tarball" |
| 826 | |
Joey Armstrong | 78cecc5 | 2023-04-03 11:39:11 -0400 | [diff] [blame] | 827 | declare -g gh_cmd |
| 828 | gh_cmd="$(find "${scratch}" -name 'gh' -print)" |
| 829 | #declare -g gh_cmd='/usr/bin/gh' |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 830 | readonly gh_cmd |
| 831 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 832 | func_echo "Command: ${gh_cmd}" |
| 833 | func_echo "Version: $("$gh_cmd" --version)" |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 834 | popd |
| 835 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 836 | return |
| 837 | } |
| 838 | |
| 839 | ## ----------------------------------------------------------------------- |
| 840 | ## Intent: Danger Will Robinson |
| 841 | ## ----------------------------------------------------------------------- |
| 842 | function releaseDelete() |
| 843 | { |
| 844 | local version="$1"; shift |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 845 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 846 | banner "${in_args[@]}" |
| 847 | declare -a args=() |
| 848 | args+=('--host-repo') |
| 849 | args+=('--yes') |
| 850 | # args+=('--cleanup-tag') |
| 851 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 852 | echo |
| 853 | echo "===========================================================================" |
| 854 | my_gh 'release' 'delete' "$version" "${args[@]}" |
| 855 | echo "===========================================================================" |
| 856 | echo |
| 857 | |
| 858 | showReleases |
| 859 | return |
| 860 | } |
| 861 | |
| 862 | ## ----------------------------------------------------------------------- |
| 863 | ## Intent: Copy binaries into temp/release, checksum then publish |
| 864 | ## ----------------------------------------------------------------------- |
| 865 | function release_staging() |
| 866 | { |
| 867 | local release_temp |
| 868 | get_release_dir release_temp |
| 869 | |
| 870 | banner '' |
| 871 | func_echo "Packaging release files" |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 872 | |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 873 | pushd "$release_temp" >/dev/null \ |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 874 | || error "pushd failed: dir is [$release_temp]" |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 875 | |
| 876 | declare -a to_release=() |
| 877 | get_artifacts '.' to_release |
| 878 | |
Joey Armstrong | 55fe80e | 2023-04-05 18:32:14 -0400 | [diff] [blame] | 879 | if false; then |
Joey Armstrong | f9a0a88 | 2023-04-17 11:53:57 -0400 | [diff] [blame^] | 880 | for fyl in "${to_release[@]}"; |
| 881 | do |
| 882 | func_echo "sha256sum $fyl > ${fyl}.sha256" |
| 883 | sha256sum "$fyl" > "${fyl}.sha256" |
| 884 | done |
Joey Armstrong | 55fe80e | 2023-04-05 18:32:14 -0400 | [diff] [blame] | 885 | fi |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 886 | |
| 887 | # Generate and check checksums |
Joey Armstrong | 55fe80e | 2023-04-05 18:32:14 -0400 | [diff] [blame] | 888 | sha256sum -- * | grep -iv -e 'checksum' -e 'sha256' > checksum.SHA256 |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 889 | sha256sum -c < checksum.SHA256 |
| 890 | |
| 891 | echo |
| 892 | func_echo "Checksums(checksum.SHA256):" |
| 893 | cat checksum.SHA256 |
| 894 | |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 895 | if false; then |
Joey Armstrong | 78cecc5 | 2023-04-03 11:39:11 -0400 | [diff] [blame] | 896 | # Careful with credentials display |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 897 | get_gh_hostname login_args |
| 898 | banner "gh auth status ${login_args[@]}" |
| 899 | gh auth status "${login_args[@]}" |
| 900 | fi |
| 901 | |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 902 | gh_release_create # publish |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 903 | |
| 904 | popd >/dev/null || error "pushd failed: dir is [$release_temp]" |
| 905 | |
| 906 | return |
| 907 | } |
| 908 | |
| 909 | ## ----------------------------------------------------------------------- |
| 910 | ## Intent: Display program usage |
| 911 | ## ----------------------------------------------------------------------- |
| 912 | function usage() |
| 913 | { |
| 914 | [[ $# -gt 0 ]] && func_echo "$*" |
| 915 | |
| 916 | cat <<EOH |
| 917 | Usage: github-release.sh [options] [target] ... |
| 918 | |
| 919 | [Github CLI (gh) arguments] |
| 920 | --login Perform authentication using a PAC |
| 921 | --logout |
| 922 | --host [h] Specify github server for connection. |
| 923 | |
| 924 | [Options] |
| 925 | --token Login debugging, alternative to env var use. |
Joey Armstrong | 55fe80e | 2023-04-05 18:32:14 -0400 | [diff] [blame] | 926 | --release-notes [f] Release notes are passed in this file. |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 927 | |
| 928 | [Modes] |
| 929 | --debug Enable script debug mode |
| 930 | --verbose Enable script verbose mode |
| 931 | |
| 932 | All remaining arguments are passthrough to the gh command. |
| 933 | EOH |
| 934 | |
| 935 | exit 0 |
| 936 | } |
| 937 | |
| 938 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 939 | ## Intent: Normalize common arguments and access to the gh command. |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 940 | ## o Cache path to the gh command |
| 941 | ## o Construct a gh command line from given args |
| 942 | ## o Command wrapper can provide defaults (--hostname github.com) |
| 943 | ## ----------------------------------------------------------------------- |
| 944 | ## Given: |
| 945 | ## scalar Array variable name (declare -n is a reference) |
| 946 | ## Return: |
| 947 | ## ref gh command line passed back to caller |
| 948 | ## Switches: |
| 949 | ## --host Pass default github hostname |
| 950 | ## --verbose Enable verbose mode# |
| 951 | ## --version Display command version |
| 952 | ## @array Remaining arguments passed as command switches. |
| 953 | ## ----------------------------------------------------------------------- |
| 954 | ## See Also: |
| 955 | ## o https://cli.github.com/manual |
| 956 | ## ----------------------------------------------------------------------- |
| 957 | function my_gh() |
| 958 | { |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 959 | declare -a cmd=() |
| 960 | cmd+=("$gh_cmd") |
| 961 | |
| 962 | ## ---------------------- |
| 963 | ## Construct command line |
| 964 | ## ---------------------- |
| 965 | # shellcheck disable=SC2034 |
| 966 | declare -A action=() # pending operations |
| 967 | declare -a args=() # common gh command line args |
| 968 | |
| 969 | while [ $# -gt 0 ]; do |
| 970 | local arg="$1"; shift |
| 971 | case "$arg" in |
| 972 | |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 973 | # Modes |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 974 | -*debug) declare -i -g debug=1 ;; |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 975 | -*verbose) args+=('--verbose') ;; |
| 976 | |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 977 | -*hostname) |
| 978 | get_gh_hostname in_args |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 979 | ;; |
| 980 | |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 981 | --host-repo) |
| 982 | local val |
| 983 | get_argv_repo val |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 984 | |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 985 | # --repo <[HOST/]OWNER/REPO> |
Joey Armstrong | 78cecc5 | 2023-04-03 11:39:11 -0400 | [diff] [blame] | 986 | args+=('--repo' "${__githost}/${val}") |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 987 | ;; |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 988 | |
Joey Armstrong | f9a0a88 | 2023-04-17 11:53:57 -0400 | [diff] [blame^] | 989 | # args+=('--repo' 'github.com/opencord/bbsim') |
| 990 | |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 991 | --repo) |
| 992 | local val |
| 993 | get_argv_repo val |
| 994 | args+=('--repo' "$val") |
| 995 | ;; |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 996 | |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 997 | --tag) |
| 998 | local val |
| 999 | get_argv_tag val |
Joey Armstrong | 4dbe700 | 2023-04-04 12:47:38 -0400 | [diff] [blame] | 1000 | args+=("$val") # No switch, pass inline |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 1001 | ;; |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1002 | |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 1003 | --title) |
| 1004 | local val |
| 1005 | get_argv_name val |
Joey Armstrong | f9a0a88 | 2023-04-17 11:53:57 -0400 | [diff] [blame^] | 1006 | args+=('--title' "'$val'") |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 1007 | ;; |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 1008 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1009 | *) args+=("$arg") ;; |
| 1010 | esac |
| 1011 | done |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 1012 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1013 | cmd+=("${args[@]}") |
| 1014 | echo "** Running: ${cmd[*]}" |
| 1015 | "${cmd[@]}" |
| 1016 | local status=$? |
| 1017 | |
| 1018 | [[ $status -eq 0 ]] && { true; } || { false; } |
| 1019 | return |
| 1020 | } |
| 1021 | |
| 1022 | ## --------------------------------------------------------------------------- |
| 1023 | ## Intent: |
| 1024 | ## --------------------------------------------------------------------------- |
| 1025 | function usage() |
| 1026 | { |
| 1027 | cat <<EOH |
Joey Armstrong | 76026b7 | 2023-03-29 12:19:17 -0400 | [diff] [blame] | 1028 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1029 | Usage: $0 |
| 1030 | Usage: make [options] [target] ... |
| 1031 | --help This mesage |
Joey Armstrong | 55fe80e | 2023-04-05 18:32:14 -0400 | [diff] [blame] | 1032 | --pac Personal Access Token (path to containing file or a string) |
| 1033 | --repo-name ex: voltctl |
| 1034 | --repo-org ex: opencord |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1035 | |
| 1036 | [DEBUG] |
| 1037 | --gen-version Generate a random release version string. |
| 1038 | --git-hostname Git server hostname (default=github.com) |
Joey Armstrong | 55fe80e | 2023-04-05 18:32:14 -0400 | [diff] [blame] | 1039 | --version-file Read version string from local version file (vs env var) |
Joey Armstrong | f9a0a88 | 2023-04-17 11:53:57 -0400 | [diff] [blame^] | 1040 | |
| 1041 | [MODES] |
Joey Armstrong | 55fe80e | 2023-04-05 18:32:14 -0400 | [diff] [blame] | 1042 | --debug Enable script debug mode |
| 1043 | --draft Create a draft release (vs published) |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 1044 | --dry-run Simulation mode |
Joey Armstrong | 55fe80e | 2023-04-05 18:32:14 -0400 | [diff] [blame] | 1045 | --todo Display future enhancement list |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1046 | |
Joey Armstrong | 55fe80e | 2023-04-05 18:32:14 -0400 | [diff] [blame] | 1047 | Usage: $0 --draft --repo-org opencord --repo-name voltctl --git-hostname github.com --pac ~/access.pac |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1048 | EOH |
| 1049 | return |
| 1050 | } |
| 1051 | |
| 1052 | ## --------------------------------------------------------------------------- |
| 1053 | ## Intent: Parse script command line arguments |
| 1054 | ## --------------------------------------------------------------------------- |
| 1055 | function parse_args() |
| 1056 | { |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1057 | [[ -v DEBUG ]] && func_echo "ENTER" |
| 1058 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1059 | while [ $# -gt 0 ]; do |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 1060 | local arg="$1"; shift |
| 1061 | func_echo "ARGV: $arg" |
| 1062 | case "$arg" in |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1063 | |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 1064 | -*debug) declare -i -g debug=1 ;; |
| 1065 | --draft) declare -i -g draft_release=1 ;; |
| 1066 | --dry-run) declare -i -g dry_run=1 ;; |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1067 | |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 1068 | --version-file) |
| 1069 | declare -i -g argv_version_file=1 |
| 1070 | ;; |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1071 | |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 1072 | -*gen-version) |
| 1073 | declare -g -i argv_gen_version=1 |
| 1074 | ;; |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1075 | |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 1076 | -*git-hostname) |
| 1077 | __githost="$1"; shift |
| 1078 | ;; |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1079 | |
Joey Armstrong | 55fe80e | 2023-04-05 18:32:14 -0400 | [diff] [blame] | 1080 | -*release-notes) |
Joey Armstrong | f9a0a88 | 2023-04-17 11:53:57 -0400 | [diff] [blame^] | 1081 | if [ -f "$1" ]; then |
| 1082 | declare -g release_notes="$1"; |
| 1083 | shift |
| 1084 | fi |
| 1085 | ;; |
Joey Armstrong | 55fe80e | 2023-04-05 18:32:14 -0400 | [diff] [blame] | 1086 | |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 1087 | -*repo-name) |
| 1088 | __repo_name="$1"; shift |
| 1089 | ;; |
| 1090 | |
| 1091 | -*repo-org) |
| 1092 | __repo_org="$1"; shift |
| 1093 | ;; |
| 1094 | |
| 1095 | -*pac) |
| 1096 | declare -g pac="$1"; shift |
| 1097 | readonly pac |
| 1098 | [[ ! -f "$pac" ]] && error "--token= does not exist ($pac)" |
| 1099 | : # nop/true |
| 1100 | ;; |
| 1101 | |
| 1102 | -*todo) todo ;; |
| 1103 | |
| 1104 | -*help) |
| 1105 | usage |
| 1106 | exit 0 |
| 1107 | ;; |
| 1108 | |
| 1109 | *) error "Detected unknown argument $arg" ;; |
| 1110 | esac |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1111 | done |
| 1112 | |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 1113 | return |
| 1114 | } |
| 1115 | |
Joey Armstrong | af577ab | 2022-12-15 14:43:33 -0500 | [diff] [blame] | 1116 | ##----------------## |
| 1117 | ##---] MAIN [---## |
| 1118 | ##----------------## |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 1119 | iam="${0##*/}" |
| 1120 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1121 | full_banner |
| 1122 | parse_args $@ |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 1123 | init |
| 1124 | install_gh_binary |
Joey Armstrong | 7f382ef | 2023-01-25 12:00:08 -0500 | [diff] [blame] | 1125 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1126 | do_login |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 1127 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1128 | release_path='/dev/null' |
| 1129 | get_release_path release_path |
| 1130 | declare -p release_path |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 1131 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1132 | pushd "$release_path" || error "pushd failed: dir is [$release_path]" |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 1133 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1134 | # legacy: getGitVersion "$GERRIT_PROJECT" GIT_VERSION |
| 1135 | getGitVersion GIT_VERSION |
| 1136 | getReleaseDescription RELEASE_DESCRIPTION |
Joey Armstrong | 55fe80e | 2023-04-05 18:32:14 -0400 | [diff] [blame] | 1137 | if [[ ! -v release_notes ]]; then |
Joey Armstrong | f9a0a88 | 2023-04-17 11:53:57 -0400 | [diff] [blame^] | 1138 | declare -g release_notes="$scratch/release.notes" |
| 1139 | echo "$RELEASE_DESCRIPTION" > "$release_notes" |
Joey Armstrong | 55fe80e | 2023-04-05 18:32:14 -0400 | [diff] [blame] | 1140 | fi |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 1141 | |
Joey Armstrong | eef8c2c | 2023-03-27 17:27:43 -0400 | [diff] [blame] | 1142 | cat <<EOM |
| 1143 | |
| 1144 | ** ----------------------------------------------------------------------- |
| 1145 | ** GIT VERSION: $(declare -p GIT_VERSION) |
| 1146 | ** RELEASE_DESCRIPTION: $(declare -p RELEASE_DESCRIPTION) |
| 1147 | ** RELEASE_TARGETS: $(declare -p RELEASE_TARGETS) |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 1148 | ** ----------------------------------------------------------------------- |
| 1149 | ** Running: make ${RELEASE_TARGETS} |
Joey Armstrong | eef8c2c | 2023-03-27 17:27:43 -0400 | [diff] [blame] | 1150 | ** ----------------------------------------------------------------------- |
| 1151 | EOM |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1152 | # build the release, can be multiple space separated targets |
| 1153 | # ----------------------------------------------------------------------- |
| 1154 | # % go build command-line-arguments: |
| 1155 | # copying /tmp/go-build4212845548/b001/exe/a.out: |
| 1156 | # open release/voltctl-1.8.25-linux-amd64: permission denied |
| 1157 | # missing: docker run mkdir |
| 1158 | # ----------------------------------------------------------------------- |
| 1159 | # shellcheck disable=SC2086 |
Joey Armstrong | eef8c2c | 2023-03-27 17:27:43 -0400 | [diff] [blame] | 1160 | make "$RELEASE_TARGETS" |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1161 | copyToRelease |
Joey Armstrong | 50f6e0b | 2023-01-24 14:14:08 -0500 | [diff] [blame] | 1162 | |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 1163 | cat <<EOM |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 1164 | |
| 1165 | ** ----------------------------------------------------------------------- |
| 1166 | ** Create the release: |
| 1167 | ** 1) Create initial github release with download area. |
| 1168 | ** 2) Generate checksum.SHA256 for all released files. |
| 1169 | ** 3) Upload files to complete the release. |
Joey Armstrong | 75a0d93 | 2023-03-28 08:59:54 -0400 | [diff] [blame] | 1170 | ** 4) Display released info from github |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 1171 | ** ----------------------------------------------------------------------- |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 1172 | EOM |
| 1173 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1174 | showReleases |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1175 | release_staging |
| 1176 | popd || error "pushd failed: dir is [$release_path]" |
Joey Armstrong | 43c4842 | 2023-04-03 10:17:32 -0400 | [diff] [blame] | 1177 | # fi |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 1178 | |
Joey Armstrong | 2097d3e | 2023-03-26 10:32:03 -0400 | [diff] [blame] | 1179 | do_logout |
| 1180 | |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 1181 | # [SEE ALSO] |
| 1182 | # ----------------------------------------------------------------------- |
| 1183 | # https://www.shellcheck.net/wiki/SC2236 |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 1184 | # 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] | 1185 | # ----------------------------------------------------------------------- |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 1186 | # https://cli.github.com/manual/gh_help_reference |
| 1187 | # https://cli.github.com/manual/gh_release |
| 1188 | # ----------------------------------------------------------------------- |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 1189 | |
| 1190 | # [EOF] |