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