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 | d94b5e6 | 2023-01-29 19:23:42 -0500 | [diff] [blame^] | 197 | cmd+=('release' 'create') |
| 198 | # cmd+=('--latest') |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 199 | cmd+=('--repo' "$repo") |
| 200 | cmd+=('--title' "$name") |
Joey Armstrong | d94b5e6 | 2023-01-29 19:23:42 -0500 | [diff] [blame^] | 201 | # cmd+=('--descripton' "$descr") # not supported |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 202 | cmd+=('--discussion-category' "Announcements") |
| 203 | # cmd+=('--latest') - auto based on date & ver |
| 204 | cmd+=('--verify-tag') |
| 205 | |
| 206 | # --branch exists, omit switch for tag |
| 207 | cmd+=("$tag") |
| 208 | |
| 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 | |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 280 | # when not running under Jenkins, use current dir as workspace and a blank |
| 281 | # project name |
| 282 | WORKSPACE=${WORKSPACE:-.} |
| 283 | GERRIT_PROJECT=${GERRIT_PROJECT:-} |
| 284 | |
| 285 | # Github organization (or user) this project is published on. Project name should |
| 286 | # be the same on both Gerrit and GitHub |
| 287 | GITHUB_ORGANIZATION=${GITHUB_ORGANIZATION:-} |
| 288 | |
| 289 | # glob pattern relative to project dir matching release artifacts |
Joey Armstrong | 7f382ef | 2023-01-25 12:00:08 -0500 | [diff] [blame] | 290 | # ARTIFACT_GLOB=${ARTIFACT_GLOB:-"release/*"} # stat -- release/* not found, literal string (?) |
Joey Armstrong | 50f6e0b | 2023-01-24 14:14:08 -0500 | [diff] [blame] | 291 | ARTIFACT_GLOB=${ARTIFACT_GLOB:-"release/."} |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 292 | |
| 293 | # Temporary staging directory to copy artifacts to |
| 294 | RELEASE_TEMP="$WORKSPACE/release" |
Zack Williams | 2f8e847 | 2019-05-21 16:29:06 -0700 | [diff] [blame] | 295 | mkdir -p "$RELEASE_TEMP" |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 296 | |
| 297 | # Use "release" as the default makefile target, can be a space separated list |
| 298 | RELEASE_TARGETS=${RELEASE_TARGETS:-release} |
| 299 | |
Zack Williams | 0f39849 | 2019-10-23 16:02:24 -0700 | [diff] [blame] | 300 | |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 301 | # check that we're on a semver released version, or exit |
| 302 | pushd "$GERRIT_PROJECT" |
| 303 | GIT_VERSION=$(git tag -l --points-at HEAD) |
| 304 | |
Zack Williams | 6e070f5 | 2019-10-04 11:08:59 -0700 | [diff] [blame] | 305 | # match bare versions or v-prefixed golang style version |
| 306 | if [[ "$GIT_VERSION" =~ ^v?([0-9]+)\.([0-9]+)\.([0-9]+)$ ]] |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 307 | then |
| 308 | echo "git has a SemVer released version tag: '$GIT_VERSION'" |
| 309 | echo "Building artifacts for GitHub release." |
| 310 | else |
| 311 | echo "No SemVer released version tag found, exiting..." |
| 312 | exit 0 |
| 313 | fi |
| 314 | popd |
| 315 | |
Zack Williams | 0f39849 | 2019-10-23 16:02:24 -0700 | [diff] [blame] | 316 | # Set and handle GOPATH and PATH |
| 317 | export GOPATH=${GOPATH:-$WORKSPACE/go} |
| 318 | export PATH=$PATH:/usr/lib/go-1.12/bin:/usr/local/go/bin:$GOPATH/bin |
| 319 | |
| 320 | # 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] | 321 | # If $DEST_GOPATH is not an empty string: |
Zack Williams | 76356cb | 2019-08-30 10:44:42 -0700 | [diff] [blame] | 322 | # - create GOPATH within WORKSPACE, and destination directory within |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 323 | # - set PATH to include $GOPATH/bin and the system go binaries |
Zack Williams | 76356cb | 2019-08-30 10:44:42 -0700 | [diff] [blame] | 324 | # - move project from $WORKSPACE/$GERRIT_PROJECT to new location in $GOPATH |
| 325 | # - start release process within that directory |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 326 | |
| 327 | DEST_GOPATH=${DEST_GOPATH:-} |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 328 | if [ -n "$DEST_GOPATH" ]; then |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 329 | mkdir -p "$GOPATH/src/$DEST_GOPATH" |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 330 | release_path="$GOPATH/src/$DEST_GOPATH/$GERRIT_PROJECT" |
Zack Williams | 76356cb | 2019-08-30 10:44:42 -0700 | [diff] [blame] | 331 | mv "$WORKSPACE/$GERRIT_PROJECT" "$release_path" |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 332 | else |
| 333 | release_path="$WORKSPACE/$GERRIT_PROJECT" |
| 334 | fi |
| 335 | |
| 336 | if [ ! -f "$release_path/Makefile" ]; then |
| 337 | echo "Makefile not found at $release_path!" |
| 338 | exit 1 |
| 339 | else |
Joey Armstrong | af577ab | 2022-12-15 14:43:33 -0500 | [diff] [blame] | 340 | |
Joey Armstrong | 7f382ef | 2023-01-25 12:00:08 -0500 | [diff] [blame] | 341 | # shellcheck disable=SC2015 |
| 342 | [[ -v TRACE ]] && { set -x; } || { set +x; } # SC2015 (shellcheck -x) |
| 343 | |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 344 | pushd "$release_path" |
| 345 | |
| 346 | # Release description is sanitized version of the log message |
Joey Armstrong | af577ab | 2022-12-15 14:43:33 -0500 | [diff] [blame] | 347 | RELEASE_DESCRIPTION="$(git log -1 --pretty=%B | tr -dc "[:alnum:]\n\r\.\[\]\:\-\\\/\`\' ")" |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 348 | |
| 349 | # build the release, can be multiple space separated targets |
| 350 | # shellcheck disable=SC2086 |
Joey Armstrong | af577ab | 2022-12-15 14:43:33 -0500 | [diff] [blame] | 351 | make "$RELEASE_TARGETS" |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 352 | |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 353 | # doDebug # deterine why ARTIFACT_GLOB is empty |
| 354 | copyToRelease |
Joey Armstrong | 50f6e0b | 2023-01-24 14:14:08 -0500 | [diff] [blame] | 355 | |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 356 | cat <<EOM |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 357 | |
| 358 | ** ----------------------------------------------------------------------- |
| 359 | ** Create the release: |
| 360 | ** 1) Create initial github release with download area. |
| 361 | ** 2) Generate checksum.SHA256 for all released files. |
| 362 | ** 3) Upload files to complete the release. |
| 363 | ** 4) Display released info from github. |
| 364 | ** ----------------------------------------------------------------------- |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 365 | EOM |
| 366 | |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 367 | # git auth login |
| 368 | # git auth logout |
| 369 | |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 370 | # Usage: github-release [global options] <verb> [verb options] |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 371 | # create release |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 372 | echo "** ${iam} Creating Release: $GERRIT_PROJECT - $GIT_VERSION" |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 373 | github_release_pre 'gh'\ |
| 374 | "$GITHUB_ORGANIZATION"\ |
| 375 | "$GERRIT_PROJECT"\ |
| 376 | "$GIT_VERSION"\ |
| 377 | "$GERRIT_PROJECT - $GIT_VERSION"\ |
| 378 | "$RELEASE_DESCRIPTION" |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 379 | |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 380 | echo "** ${iam} Packaging release files" |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 381 | pushd "$RELEASE_TEMP" |
| 382 | |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 383 | echo "** ${iam}: Files to release:" |
| 384 | readarray -t to_release < <(find . -mindepth 1 -maxdepth 1 -type f -print) |
| 385 | declare -p to_release |
Joey Armstrong | d8b6f33 | 2023-01-25 18:35:17 -0500 | [diff] [blame] | 386 | |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 387 | # Generate and check checksums |
Zack Williams | 2f8e847 | 2019-05-21 16:29:06 -0700 | [diff] [blame] | 388 | sha256sum -- * > checksum.SHA256 |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 389 | sha256sum -c < checksum.SHA256 |
| 390 | |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 391 | echo |
| 392 | echo "** ${iam} Checksums(checksum.SHA256):" |
Zack Williams | 0d93d84 | 2019-05-21 17:02:49 -0700 | [diff] [blame] | 393 | cat checksum.SHA256 |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 394 | echo |
Zack Williams | 0d93d84 | 2019-05-21 17:02:49 -0700 | [diff] [blame] | 395 | |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 396 | echo "** ${iam} Upload files being released" |
Joey Armstrong | d99e3d2 | 2023-01-29 12:35:43 -0500 | [diff] [blame] | 397 | |
| 398 | # shellcheck disable=SC2194 |
| 399 | case 'gh' in |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 400 | gh) |
Joey Armstrong | d94b5e6 | 2023-01-29 19:23:42 -0500 | [diff] [blame^] | 401 | declare -a cmd=() |
| 402 | cmd+=("$gh_cmd") |
| 403 | cmd+=('release' 'upload') |
| 404 | cmd+=('--repo' "$GERRIT_PROJECT") |
| 405 | cmd+=("${to_release[@]}") |
| 406 | "${cmd[@]}" |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 407 | ;; |
| 408 | |
| 409 | *) |
| 410 | |
| 411 | # upload all files to the release |
| 412 | for rel_file in * |
| 413 | do |
| 414 | echo "** ${iam} Uploading file: $rel_file" |
| 415 | github-release \ |
| 416 | upload \ |
| 417 | --user "$GITHUB_ORGANIZATION" \ |
| 418 | --repo "$GERRIT_PROJECT" \ |
| 419 | --tag "$GIT_VERSION" \ |
| 420 | --name "$rel_file" \ |
| 421 | --file "$rel_file" |
| 422 | done |
| 423 | ;; |
| 424 | esac |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 425 | |
| 426 | popd |
Joey Armstrong | 1962bcf | 2023-01-27 13:53:18 -0500 | [diff] [blame] | 427 | popd |
Zack Williams | 27cd3e5 | 2018-09-18 16:44:50 -0700 | [diff] [blame] | 428 | fi |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 429 | |
| 430 | # [SEE ALSO] |
| 431 | # ----------------------------------------------------------------------- |
| 432 | # https://www.shellcheck.net/wiki/SC2236 |
Joey Armstrong | 26707f0 | 2023-01-26 12:41:12 -0500 | [diff] [blame] | 433 | # 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] | 434 | # ----------------------------------------------------------------------- |
Joey Armstrong | f085d87 | 2023-01-28 17:52:29 -0500 | [diff] [blame] | 435 | # https://cli.github.com/manual/gh_help_reference |
| 436 | # https://cli.github.com/manual/gh_release |
| 437 | # ----------------------------------------------------------------------- |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 438 | |
| 439 | # [EOF] |