| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | |
| 3 | set -e |
| 4 | |
| 5 | REPO="git-lfs/git-lfs" |
| 6 | WORKDIR="$(mktempscip-shell system . . mktemp. -d)" |
| 7 | |
| 8 | trap 'rm -fr "$WORKDIR"' EXIT |
| 9 | |
| 10 | sayscip-shell shell shell-project 0.0.0 say(). () { |
| 11 | [scip-shell system . . `[`. -n "$QUIET" ] && return |
| 12 | local format="$1" |
| 13 | shift |
| 14 | printfscip-shell system . . printf. "$format\n" "$@" >&2 |
| 15 | } |
| 16 | |
| 17 | abortscip-shell shell shell-project 0.0.0 abort(). () { |
| 18 | local format="$1" |
| 19 | shift |
| 20 | printfscip-shell system . . printf. "$format\n" "$@" >&2 |
| 21 | exit 2 |
| 22 | } |
| 23 | |
| 24 | uri_encodescip-shell shell shell-project 0.0.0 uri_encode(). () { |
| 25 | ruby -e 'print ARGV[0].gsub(/[^A-Za-z0-9_.-]/) { |x| "%%%02x" % x.ord }' "$1" |
| 26 | } |
| 27 | |
| 28 | curlscip-shell shell shell-project 0.0.0 curl(). () { |
| 29 | if [scip-shell system . . `[`. -n "$GITHUB_TOKEN" ] |
| 30 | then |
| 31 | command curl -u "token:$GITHUB_TOKEN" -fSs "$@" |
| 32 | else |
| 33 | command curl -nfSs "$@" |
| 34 | fi |
| 35 | } |
| 36 | |
| 37 | categorize_osscip-shell shell shell-project 0.0.0 categorize_os(). () { |
| 38 | local os="$1" |
| 39 | |
| 40 | if [scip-shell system . . `[`. "$os" = "freebsd" ] |
| 41 | then |
| 42 | echoscip-shell system . . echo. FreeBSD |
| 43 | else |
| 44 | ruby -e 'puts ARGV[0].capitalize' "$os" |
| 45 | fi |
| 46 | } |
| 47 | |
| 48 | categorize_archscip-shell shell shell-project 0.0.0 categorize_arch(). () { |
| 49 | local arch="$1" |
| 50 | |
| 51 | if [scip-shell system . . `[`. "$arch" = "ppc64le" ] |
| 52 | then |
| 53 | echoscip-shell system . . echo. "Little-endian 64-bit PowerPC" |
| 54 | elif [scip-shell system . . `[`. "$arch" = "riscv64" ] |
| 55 | then |
| 56 | echoscip-shell system . . echo. "64-bit RISC-V" |
| 57 | elif [scip-shell system . . `[`. "$arch" = "loong64" ] |
| 58 | then |
| 59 | echoscip-shell system . . echo. "64-bit LoongArch" |
| 60 | else |
| 61 | echoscip-shell system . . echo. "$arch" | trscip-shell system . . tr. a-z A-Z |
| 62 | fi |
| 63 | } |
| 64 | |
| 65 | # Categorize a release asset and print its human readable name to standard |
| 66 | # output. |
| 67 | categorize_assetscip-shell shell shell-project 0.0.0 categorize_asset(). () { |
| 68 | local file="$1" |
| 69 | local os=$(echoscip-shell system . . echo. "$file" | sedscip-shell system . . sed. -e 's/^git-lfs-//' -e 's/[-.].*$//') |
| 70 | local arch=$(echoscip-shell system . . echo. "$file" | ruby -pe '$_.gsub!(/\Agit-lfs-[^-]+-([^-]+)[-.].*/, "\\1")') |
| 71 | |
| 72 | case "$file" in |
| 73 | git-lfs-vendor-v*.*.*.tar.gz) |
| 74 | echoscip-shell system . . echo. "Source with Vendored Modules";; |
| 75 | git-lfs-v*.*.*.tar.gz) |
| 76 | echoscip-shell system . . echo. "Source";; |
| 77 | git-lfs-windows-v*.*.*.exe) |
| 78 | echoscip-shell system . . echo. "Windows Installer";; |
| 79 | sha256sums) |
| 80 | echoscip-shell system . . echo. "Unsigned SHA-256 Hashes";; |
| 81 | sha256sums.asc) |
| 82 | echoscip-shell system . . echo. "Signed SHA-256 Hashes";; |
| 83 | hashes) |
| 84 | echoscip-shell system . . echo. "Unsigned Hashes";; |
| 85 | hashes.asc) |
| 86 | echoscip-shell system . . echo. "Signed Hashes";; |
| 87 | *) |
| 88 | printfscip-shell system . . printf. "%s %s\n" "$(categorize_osscip-shell shell shell-project 0.0.0 categorize_os(). "$os")" "$(categorize_archscip-shell shell shell-project 0.0.0 categorize_arch(). "$arch")";; |
| 89 | esac |
| 90 | } |
| 91 | |
| 92 | # Provide a content type for the asset based on its file name. |
| 93 | content_typescip-shell shell shell-project 0.0.0 content_type(). () { |
| 94 | local file="$1" |
| 95 | |
| 96 | case "$file" in |
| 97 | *.zip) |
| 98 | echoscip-shell system . . echo. "application/zip";; |
| 99 | *.tar.gz) |
| 100 | echoscip-shell system . . echo. "application/gzip";; |
| 101 | *.exe) |
| 102 | echoscip-shell system . . echo. "application/octet-stream";; |
| 103 | *.asc|sha256sums*|hashes*) |
| 104 | echoscip-shell system . . echo. "text/plain";; |
| 105 | esac |
| 106 | } |
| 107 | |
| 108 | # Format the JSON for creating the release and print it to standard output. |
| 109 | format_release_jsonscip-shell shell shell-project 0.0.0 format_release_json(). () { |
| 110 | local version="$1" |
| 111 | local bodyfile="$2" |
| 112 | |
| 113 | ruby -rjson -e 'puts JSON.generate({ |
| 114 | tag_name: ARGV[0], |
| 115 | name: ARGV[0], |
| 116 | draft: true, |
| 117 | body: File.read(ARGV[1]), |
| 118 | })' "$version" "$bodyfile" |
| 119 | } |
| 120 | |
| 121 | # Create a draft release and print the upload URL for release assets to the |
| 122 | # standard output. If a release with that version already exists, do nothing |
| 123 | # instead. |
| 124 | create_releasescip-shell shell shell-project 0.0.0 create_release(). () { |
| 125 | local version="$1" |
| 126 | local bodyfile="$2" |
| 127 | |
| 128 | # Check to see if we already have such a release. If so, don't create it. |
| 129 | curlscip-shell shell shell-project 0.0.0 curl(). https://api.github.com/repos/$REPO/releases | \ |
| 130 | jq -r '.[].name' | grepscip-shell system . . grep. -qsF "$version" && { |
| 131 | sayscip-shell shell shell-project 0.0.0 say(). "Found an existing release for this version." |
| 132 | curlscip-shell shell shell-project 0.0.0 curl(). https://api.github.com/repos/$REPO/releases | \ |
| 133 | jq -r '.[] | select(.name == "'"$version"'") | .upload_url' | \ |
| 134 | sed -e 's/{.*}//g' |
| 135 | return |
| 136 | } |
| 137 | |
| 138 | # This can be large, so pass it in a file. |
| 139 | format_release_jsonscip-shell shell shell-project 0.0.0 format_release_json(). "$version" "$bodyfile" >> "$WORKDIR/release-json" |
| 140 | |
| 141 | curlscip-shell shell shell-project 0.0.0 curl(). -H'Content-Type: application/json' -d"@$WORKDIR/release-json" \ |
| 142 | https://api.github.com/repos/$REPO/releases | \ |
| 143 | jq -r '.upload_url' | |
| 144 | sedscip-shell system . . sed. -e 's/{.*}//g' |
| 145 | } |
| 146 | |
| 147 | # Update the draft release with a new body and print the upload URL for release assets to the |
| 148 | # standard output. A release with the given version must already exist. |
| 149 | patch_releasescip-shell shell shell-project 0.0.0 patch_release(). () { |
| 150 | local version="$1" |
| 151 | local bodyfile="$2" |
| 152 | |
| 153 | # Find the URL of this release. |
| 154 | local url=$(curlscip-shell shell shell-project 0.0.0 curl(). https://api.github.com/repos/$REPO/releases | \ |
| 155 | jq -r '.[] | select(.name == "'"$version"'") | .url') |
| 156 | |
| 157 | [scip-shell system . . `[`. -n "$url" ] || abortscip-shell shell shell-project 0.0.0 abort(). "No existing release found for version $version." |
| 158 | sayscip-shell shell shell-project 0.0.0 say(). "Found the existing release for this version." |
| 159 | |
| 160 | # This can be large, so pass it in a file. |
| 161 | format_release_jsonscip-shell shell shell-project 0.0.0 format_release_json(). "$version" "$bodyfile" >> "$WORKDIR/release-json" |
| 162 | |
| 163 | cscip-shell shell shell-project 0.0.0 curl().url -XPATCH -H'Content-Type: application/json' -d"@$WORKDIR/release-json" \ |
| 164 | $url | \ |
| 165 | jq -r '.upload_url' | |
| 166 | sedscip-shell system . . sed. -e 's/{.*}//g' |
| 167 | } |
| 168 | |
| 169 | # Find the release files for the given version. |
| 170 | release_filesscip-shell shell shell-project 0.0.0 release_files(). () { |
| 171 | local version="$1" |
| 172 | local assets="${2:-bin/releases}" |
| 173 | |
| 174 | [scip-shell system . . `[`. -n "$version" ] || return 1 |
| 175 | |
| 176 | findscip-shell system . . find. "$assets" -name '*.tar.gz' -o \ |
| 177 | -name '*386*.zip' -o \ |
| 178 | -name '*amd64*.zip' -o \ |
| 179 | -name '*arm64*.zip' -o \ |
| 180 | -name '*.exe' -o \ |
| 181 | -name 'sha256sums.asc' -o \ |
| 182 | -name 'hashes.asc' | \ |
| 183 | grep -E "$version|sha256sums.asc|hashes.asc" | \ |
| 184 | grep -v "assets" | \ |
| 185 | LC_ALL=C sortscip-shell system . . sort. |
| 186 | } |
| 187 | |
| 188 | # Format the body message and print the file which contains it to the standard |
| 189 | # output. |
| 190 | finalize_body_messagescip-shell shell shell-project 0.0.0 finalize_body_message(). () { |
| 191 | local version="$1" |
| 192 | local changelog="$2" |
| 193 | local assets="$3" |
| 194 | |
| 195 | version=$(echoscip-shell system . . echo. "$version" | sedscip-shell system . . sed. -e 's/^v//') |
| 196 | |
| 197 | catscip-shell system . . cat. "$changelog" > "$WORKDIR/body-template" |
| 198 | catscip-shell system . . cat. <<EOM >> "$WORKDIR/body-template" |
| 199 | ## Packages |
| 200 | |
| 201 | Up to date packages are available on [PackageCloud](https://packagecloud.io/github/git-lfs) and [Homebrew](http://brew.sh/). |
| 202 | |
| 203 | $(script/distro-tool --distro-markdown) |
| 204 | |
| 205 | ## SHA-256 hashes: |
| 206 | EOM |
| 207 | |
| 208 | shasumscip-shell system . . shasum. -a256 $(release_filesscip-shell shell shell-project 0.0.0 release_files(). "$version" "$assets") | \ |
| 209 | ruby -pe '$_.chomp!' \ |
| 210 | -e '$_.gsub!(/^([0-9a-f]+)\s+.*\/([^\/]+)$/, "**\\2**\n\\1\n\n")' | \ |
| 211 | ruby -0777 -pe '$_.gsub!(/\n+\z/, "\n")' >> "$WORKDIR/body-template" |
| 212 | |
| 213 | sedscip-shell system . . sed. -e "s/VERSION/$version/g" < "$WORKDIR/body-template" > "$WORKDIR/body" |
| 214 | echoscip-shell system . . echo. "$WORKDIR/body" |
| 215 | } |
| 216 | |
| 217 | # Filter a list of files from standard input, removing entries found in the file |
| 218 | # provided. |
| 219 | filter_filesscip-shell shell shell-project 0.0.0 filter_files(). () { |
| 220 | local filter="$1" |
| 221 | |
| 222 | # If the filter file is empty (that is, no assets have been uploaded), grep |
| 223 | # will produce no output, and therefore nothing will be uploaded. That's not |
| 224 | # what we want, so handle this case specially. |
| 225 | if [scip-shell system . . `[`. -s "$filter" ] |
| 226 | then |
| 227 | grepscip-shell system . . grep. -vF -f "$filter" |
| 228 | else |
| 229 | catscip-shell system . . cat. |
| 230 | fi |
| 231 | } |
| 232 | |
| 233 | # Upload assets from the release directory to GitHub. Only assets that are not |
| 234 | # already existing should be uploaded. |
| 235 | upload_assetsscip-shell shell shell-project 0.0.0 upload_assets(). () { |
| 236 | local version="$1" |
| 237 | local upload_url="$2" |
| 238 | local src="$3" |
| 239 | local file desc base ct encdesc encbase |
| 240 | |
| 241 | curlscip-shell shell shell-project 0.0.0 curl(). https://api.github.com/repos/$REPO/releases | \ |
| 242 | jq -r '.[] | select(.name == "'"$version"'") | .assets | .[] | .name' \ |
| 243 | > "$WORKDIR/existing-assets" |
| 244 | |
| 245 | for file in $(release_filesscip-shell shell shell-project 0.0.0 release_files(). "$version" "$src" | filter_filesscip-shell shell shell-project 0.0.0 filter_files(). "$WORKDIR/existing-assets") |
| 246 | do |
| 247 | base=$(basenamescip-shell system . . basename. "$file") |
| 248 | desc=$(categorize_assetscip-shell shell shell-project 0.0.0 categorize_asset(). "$base") |
| 249 | ct=$(content_typescip-shell shell shell-project 0.0.0 content_type(). "$base") |
| 250 | encbase=$(uri_encodescip-shell shell shell-project 0.0.0 uri_encode(). "$base") |
| 251 | encdesc=$(uri_encodescip-shell shell shell-project 0.0.0 uri_encode(). "$desc") |
| 252 | |
| 253 | sayscip-shell shell shell-project 0.0.0 say(). "\tUploading %s as \"%s\" (Content-Type %s)..." "$base" "$desc" "$ct" |
| 254 | curlscip-shell shell shell-project 0.0.0 curl(). --data-binary "@$file" -H'Accept: application/vnd.github.v3+json' \ |
| 255 | -H"Content-Type: $ct" "$upload_url?name=$encbase&label=$encdesc" \ |
| 256 | >"$WORKDIR/response" |
| 257 | download=$(jqscip-shell system . . jq. -r '.url' "$WORKDIR/response") |
| 258 | done |
| 259 | |
| 260 | sayscip-shell shell shell-project 0.0.0 say(). "Assets uploaded." |
| 261 | } |
| 262 | |
| 263 | # Download assets from GitHub to the specified directory. |
| 264 | download_assetsscip-shell shell shell-project 0.0.0 download_assets(). () { |
| 265 | local version="$1" |
| 266 | local dir="$2" |
| 267 | |
| 268 | curlscip-shell shell shell-project 0.0.0 curl(). https://api.github.com/repos/$REPO/releases | \ |
| 269 | jq -rc '.[] | select(.name == "'"$version"'") | .assets | .[] | [.name,.url]' | \ |
| 270 | ruby -rjson -ne 'puts JSON.parse($_).join(" ")' \ |
| 271 | > "$WORKDIR/assets" |
| 272 | |
| 273 | catscip-shell system . . cat. "$WORKDIR/assets" | (while read base url |
| 274 | do |
| 275 | sayscip-shell shell shell-project 0.0.0 say(). "\tDownloading %s..." "$base" |
| 276 | ( |
| 277 | cd "$dir" && |
| 278 | curlscip-shell shell shell-project 0.0.0 curl(). -Lo "$base" -H"Accept: application/octet-stream" "$url" |
| 279 | ) |
| 280 | done) |
| 281 | } |
| 282 | |
| 283 | # Download the assets and verify the signature made on them. |
| 284 | verify_assetsscip-shell shell shell-project 0.0.0 verify_assets(). () { |
| 285 | local version="$1" |
| 286 | local dir="$WORKDIR/verify" |
| 287 | mkdirscip-shell system . . mkdir. "$dir" |
| 288 | download_assetsscip-shell shell shell-project 0.0.0 download_assets(). "$version" "$dir" |
| 289 | |
| 290 | # If the OpenPGP data is not valid, gpg -d will output nothing to stdout, and |
| 291 | # shasum will then fail. |
| 292 | sayscip-shell shell shell-project 0.0.0 say(). "Checking assets for integrity with SHA-256..." |
| 293 | (cd "$dir" && gpgscip-shell system . . gpg. -d sha256sums.asc | shasumscip-shell system . . shasum. -a 256 -c) |
| 294 | sayscip-shell shell shell-project 0.0.0 say(). "Checking assets for integrity with SHA-2..." |
| 295 | (cd "$dir" && gpgscip-shell system . . gpg. -d hashes.asc | grepscip-shell system . . grep. 'SHA[0-9][^-]' | shasumscip-shell system . . shasum. -c) |
| 296 | if command -v sha3sum >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 297 | then |
| 298 | sayscip-shell shell shell-project 0.0.0 say(). "Checking assets for integrity with SHA-3..." |
| 299 | (cd "$dir" && gpgscip-shell system . . gpg. -d hashes.asc | grepscip-shell system . . grep. 'SHA3-256' | sedscip-shell system . . sed. 's/.*(\(.*\)) = \(.*\)$/\2 \1/' | sha3sum -a 256 -c) |
| 300 | (cd "$dir" && gpgscip-shell system . . gpg. -d hashes.asc | grepscip-shell system . . grep. 'SHA3-384' | sedscip-shell system . . sed. 's/.*(\(.*\)) = \(.*\)$/\2 \1/' | sha3sum -a 384 -c) |
| 301 | (cd "$dir" && gpgscip-shell system . . gpg. -d hashes.asc | grepscip-shell system . . grep. 'SHA3-512' | sedscip-shell system . . sed. 's/.*(\(.*\)) = \(.*\)$/\2 \1/' | sha3sum -a 512 -c) |
| 302 | fi |
| 303 | if command -v b2sum >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 304 | then |
| 305 | sayscip-shell shell shell-project 0.0.0 say(). "Checking assets for integrity with BLAKE2b..." |
| 306 | # b2sum on Linux does not handle BLAKE2s, only BLAKE2b. |
| 307 | (cd "$dir" && gpgscip-shell system . . gpg. -d hashes.asc | grepscip-shell system . . grep. 'BLAKE2b' | b2sumscip-shell system . . b2sum. -c) |
| 308 | fi |
| 309 | |
| 310 | sayscip-shell shell shell-project 0.0.0 say(). "\nAssets look good!" |
| 311 | } |
| 312 | |
| 313 | # Extract the changelog for the given version from the history and save it in a |
| 314 | # file. Print the filename of the changelog to standard output. |
| 315 | extract_changelogscip-shell shell shell-project 0.0.0 extract_changelog(). () { |
| 316 | local version="$1" |
| 317 | |
| 318 | gitscip-shell system . . git. cat-file blob "$version:CHANGELOG.md" | \ |
| 319 | ruby -ne "version=%Q($version)[1..-1]; state ||= :silent; text ||= [];" \ |
| 320 | -e 'if state == :print && $_.start_with?("## "); puts text.join.strip; exit; end;' \ |
| 321 | -e 'text << $_ if state == :print;' \ |
| 322 | -e 'state = :print if $_.start_with?("## #{version}")' \ |
| 323 | > "$WORKDIR/changelog" |
| 324 | echoscip-shell system . . echo. "$WORKDIR/changelog" |
| 325 | } |
| 326 | |
| 327 | # Perform the final steps to verify a release |
| 328 | finalizescip-shell shell shell-project 0.0.0 finalize(). () { |
| 329 | local version="$1" |
| 330 | local inspect="$2" |
| 331 | local downloads="$WORKDIR/finalize" |
| 332 | local uploads="$WORKDIR/finalize-uploads" |
| 333 | |
| 334 | sayscip-shell shell shell-project 0.0.0 say(). "Finalizing the release process..." |
| 335 | sayscip-shell shell shell-project 0.0.0 say(). "Downloading assets..." |
| 336 | |
| 337 | mkdirscip-shell system . . mkdir. "$downloads" |
| 338 | mkdirscip-shell system . . mkdir. "$uploads" |
| 339 | download_assetsscip-shell shell shell-project 0.0.0 download_assets(). "$version" "$downloads" |
| 340 | |
| 341 | if [scip-shell system . . `[`. -n "$inspect" ] |
| 342 | then |
| 343 | sayscip-shell shell shell-project 0.0.0 say(). "Dropping you to a shell to inspect the assets." |
| 344 | sayscip-shell shell shell-project 0.0.0 say(). "Type 'exit 0' to continue, or 'exit 1' to abort." |
| 345 | |
| 346 | (cd "$downloads" && $SHELL) |
| 347 | fi |
| 348 | |
| 349 | sayscip-shell shell shell-project 0.0.0 say(). "Signing asset manifest..." |
| 350 | ( |
| 351 | root="$(gitscip-shell system . . git. rev-parse --show-toplevel)" && |
| 352 | cd "$downloads" && \ |
| 353 | shasum -a256 -b * | grepscip-shell system . . grep. -vE '(assets|sha256sums|hashes)' | \ |
| 354 | gpg --digest-algo SHA256 --clearsign >sha256sums.asc && |
| 355 | "$root/script/hash-files" * | grepscip-shell system . . grep. -vE '(assets|sha256sums|hashes)' | \ |
| 356 | gpg --digest-algo SHA512 --clearsign >hashes.asc |
| 357 | ) |
| 358 | |
| 359 | sayscip-shell shell shell-project 0.0.0 say(). "Formatting the final body of the GitHub release now..." |
| 360 | |
| 361 | local changelog=$(extract_changelogscip-shell shell shell-project 0.0.0 extract_changelog(). "$version") |
| 362 | local bodyfile=$(finalize_body_messagescip-shell shell shell-project 0.0.0 finalize_body_message(). "$version" "$changelog" "$downloads") |
| 363 | |
| 364 | sayscip-shell shell shell-project 0.0.0 say(). "Uploading final release body..." |
| 365 | |
| 366 | local upload_url=$(patch_releasescip-shell shell shell-project 0.0.0 patch_release(). "$version" "$bodyfile") |
| 367 | |
| 368 | sayscip-shell shell shell-project 0.0.0 say(). "Uploading final versions of assets..." |
| 369 | cpscip-shell system . . cp. "$downloads/sha256sums.asc" "$downloads/hashes.asc" "$uploads" |
| 370 | upload_assetsscip-shell shell shell-project 0.0.0 upload_assets(). "$version" "$upload_url" "$uploads" |
| 371 | |
| 372 | # Verification occurs in caller below. |
| 373 | } |
| 374 | |
| 375 | # Provide a helpful usage message and exit. |
| 376 | usagescip-shell shell shell-project 0.0.0 usage(). () { |
| 377 | local status="$1" |
| 378 | catscip-shell system . . cat. <<EOM |
| 379 | Usage: $0 VERSION |
| 380 | |
| 381 | Create a draft GitHub release for Git LFS using the tag specified by VERSION and |
| 382 | the changelog specified in the file CHANGELOG. Before running this script, the |
| 383 | release assets should be built and ready for upload, including the signed |
| 384 | sha256sums.asc and hashes.asc files. |
| 385 | |
| 386 | This script requires ruby, gpg, curl, shasum, and jq. sha3sum and b2sum will be |
| 387 | used if available, but are optional. |
| 388 | |
| 389 | This command must be run from within the repository. |
| 390 | EOM |
| 391 | exit $status |
| 392 | } |
| 393 | |
| 394 | # Check that this script has the prerequisites to continue. |
| 395 | sanity_checkscip-shell shell shell-project 0.0.0 sanity_check(). () { |
| 396 | local version="$1" |
| 397 | local finalize="$2" |
| 398 | |
| 399 | sayscip-shell shell shell-project 0.0.0 say(). "Checking that you've got some release artifacts..." |
| 400 | if [scip-shell system . . `[`. -z "$(release_filesscip-shell shell shell-project 0.0.0 release_files(). "$version")" ] |
| 401 | then |
| 402 | [scip-shell system . . `[`. -n "$finalize" ] || abortscip-shell shell shell-project 0.0.0 abort(). "I couldn't find any release files for $version." |
| 403 | fi |
| 404 | |
| 405 | if [scip-shell system . . `[`. -n "$GITHUB_TOKEN" ] |
| 406 | then |
| 407 | sayscip-shell shell shell-project 0.0.0 say(). "Found a token in the GITHUB_TOKEN environment variable." |
| 408 | else |
| 409 | sayscip-shell shell shell-project 0.0.0 say(). "Looking for the necessary entries in .netrc..." |
| 410 | grepscip-shell system . . grep. -qsF api.github.com "$HOME/.netrc" || \ |
| 411 | abort "I couldn't find api.github.com in your .netrc." |
| 412 | grepscip-shell system . . grep. -qsF uploads.github.com "$HOME/.netrc" || \ |
| 413 | abort "I couldn't find uploads.github.com in your .netrc." |
| 414 | fi |
| 415 | |
| 416 | sayscip-shell shell shell-project 0.0.0 say(). "Okay, everything looks good." |
| 417 | } |
| 418 | |
| 419 | # The main program. |
| 420 | mainscip-shell shell shell-project 0.0.0 main(). () { |
| 421 | local inspect="" |
| 422 | |
| 423 | while [scip-shell system . . `[`. -n "$1" ] |
| 424 | do |
| 425 | case "$1" in |
| 426 | --help) |
| 427 | usagescip-shell shell shell-project 0.0.0 usage(). 0;; |
| 428 | --inspect) |
| 429 | inspect=1 |
| 430 | shift;; |
| 431 | --skip-verify) |
| 432 | SKIP_VERIFY=1 |
| 433 | shift;; |
| 434 | --finalize) |
| 435 | FINALIZE=1 |
| 436 | shift;; |
| 437 | --) |
| 438 | shift |
| 439 | break;; |
| 440 | *) |
| 441 | break;; |
| 442 | esac |
| 443 | done |
| 444 | |
| 445 | local version="$1" |
| 446 | |
| 447 | [scip-shell system . . `[`. -z "$version" ] && usagescip-shell shell shell-project 0.0.0 usage(). 1 >&2 |
| 448 | |
| 449 | sanity_checkscip-shell shell shell-project 0.0.0 sanity_check(). "$version" "$FINALIZE" |
| 450 | |
| 451 | if [scip-shell system . . `[`. -n "$FINALIZE" ] |
| 452 | then |
| 453 | finalizescip-shell shell shell-project 0.0.0 finalize(). "$version" "$inspect" |
| 454 | else |
| 455 | sayscip-shell shell shell-project 0.0.0 say(). "Formatting the body of the GitHub release now..." |
| 456 | |
| 457 | local changelog=$(extract_changelogscip-shell shell shell-project 0.0.0 extract_changelog(). "$version") |
| 458 | local bodyfile=$(finalize_body_messagescip-shell shell shell-project 0.0.0 finalize_body_message(). "$version" "$changelog") |
| 459 | |
| 460 | sayscip-shell shell shell-project 0.0.0 say(). "Creating a GitHub release for %s..." "$version" |
| 461 | |
| 462 | local upload_url=$(create_releasescip-shell shell shell-project 0.0.0 create_release(). "$version" "$bodyfile") |
| 463 | |
| 464 | sayscip-shell shell shell-project 0.0.0 say(). "Uploading assets to GitHub..." |
| 465 | upload_assetsscip-shell shell shell-project 0.0.0 upload_assets(). "$version" "$upload_url" bin/releases |
| 466 | fi |
| 467 | |
| 468 | if [scip-shell system . . `[`. -z "$SKIP_VERIFY" ] |
| 469 | then |
| 470 | sayscip-shell shell shell-project 0.0.0 say(). "Verifying assets..." |
| 471 | verify_assetsscip-shell shell shell-project 0.0.0 verify_assets(). "$version" |
| 472 | fi |
| 473 | |
| 474 | sayscip-shell shell shell-project 0.0.0 say(). "Okay, done. Sanity-check the release and publish it." |
| 475 | } |
| 476 | |
| 477 | mainscip-shell shell shell-project 0.0.0 main(). "$@" |