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