|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# The API is documented here: |
| 4 | +# https://www.jfrog.com/confluence/display/BT/Bintray+REST+API |
| 5 | + |
| 6 | +# Environment variables used |
| 7 | +if [ -z "$BINTRAY_USER" ] |
| 8 | +then |
| 9 | + echo "BINTRAY_USER not set". |
| 10 | + exit 9 |
| 11 | +fi |
| 12 | +if [ -z "$BINTRAY_API_KEY" ] |
| 13 | +then |
| 14 | + echo "BINTRAY_API_KEY not set, this is your API key in your profile." |
| 15 | + exit 9 |
| 16 | +fi |
| 17 | +if [ -z "$SONATYPE_USERTOKEN" ] |
| 18 | +then |
| 19 | + echo "SONATYPE_USERTOKEN not set." |
| 20 | + exit 9 |
| 21 | +fi |
| 22 | + |
| 23 | +if [ -z "$SONATYPE_PASSWORDTOKEN" ] |
| 24 | +then |
| 25 | + echo "SONATYPE_PASSWORDTOKEN not set." |
| 26 | + exit 9 |
| 27 | +fi |
| 28 | + |
| 29 | +# Export these |
| 30 | +export BINTRAY_SUBJECT="iopipe" |
| 31 | +export BINTRAY_REPO="iopipe-logger-log4j2" |
| 32 | +export BINTRAY_PACKAGE="iopipe" |
| 33 | + |
| 34 | +# And realpath |
| 35 | +if ! which realpath |
| 36 | +then |
| 37 | + echo "No realpath exists (from GNU Coreutils)" |
| 38 | + exit 9 |
| 39 | +fi |
| 40 | + |
| 41 | +# Get the version from the POM |
| 42 | +# This should extract the version although it could also break in |
| 43 | +# another locale, so hopefully it is not too troublesome |
| 44 | +__pom_ver="`MAVEN_OPTS="-Dorg.slf4j.simpleLogger.defaultLogLevel=OFF |
| 45 | + -Dorg.slf4j.simpleLogger.log.org.apache.maven.plugins.help=INFO" |
| 46 | + mvn help:evaluate --batch-mode -Dexpression=project.version 2>&1 | \ |
| 47 | + grep -v '^\[INFO' | grep -v '^[dD]ownload' | \ |
| 48 | + grep '^[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}' | \ |
| 49 | + tail -n 1 | sed 's/[ \t]*//g' | sed 's/-SNAPSHOT//g'`" |
| 50 | + |
| 51 | +# Note it |
| 52 | +echo "POM version: $__pom_ver" 1>&2 |
| 53 | + |
| 54 | +# Build |
| 55 | +mkdir -p "/tmp/$$/" |
| 56 | +if ! mvn deploy "-DaltDeploymentRepository=file::default::file:///tmp/$$/" |
| 57 | +then |
| 58 | + echo "Failed to build distribution" |
| 59 | + exit 2 |
| 60 | +fi |
| 61 | + |
| 62 | +# *** Create new version |
| 63 | +# HTTP -> POST /packages/:subject/:repo/:package/versions |
| 64 | +# BODY -> { |
| 65 | +# "name": "1.1.5", |
| 66 | +# "released": "ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ)", (optional) |
| 67 | +# "desc": "This version...", |
| 68 | +# "github_release_notes_file": "RELEASE.txt", (optional) |
| 69 | +# "github_use_tag_release_notes": true, (optional) |
| 70 | +# "vcs_tag": "1.1.5" (optional) |
| 71 | +# } |
| 72 | +# RESULT -> Status: 201 Created |
| 73 | +# {Version get JSON response} |
| 74 | +if ! echo '{"name":"'$__pom_ver'", "desc":"'$__pom_ver'"}' | curl --data-binary @- -f -XPOST -u "$BINTRAY_USER:$BINTRAY_API_KEY" -H "Content-Type: application/json" \ |
| 75 | + "https://api.bintray.com/packages/$BINTRAY_SUBJECT/$BINTRAY_REPO/$BINTRAY_PACKAGE/versions" |
| 76 | +then |
| 77 | + echo "Failed to create version!" |
| 78 | + exit 3 |
| 79 | +fi |
| 80 | + |
| 81 | +# Go through every built file and upload them |
| 82 | +# Ignore maven metadata because we do not care about those |
| 83 | +for __file in $(find "/tmp/$$/" -type f | grep -v maven-metadata) |
| 84 | +do |
| 85 | + # We operate on the relative path here, so we want to lose dist |
| 86 | + __as="$(realpath --relative-to="/tmp/$$/" "$__file")" |
| 87 | + |
| 88 | + # *** Upload files for this version (USE THIS MAVEN PUBLISH?? WOULD IT WORK??) |
| 89 | + # HTTP -> PUT /maven/:subject/:repo/:package/:file_path[;publish=0/1] |
| 90 | + # RESULT -> Status: 201 Created |
| 91 | + # { |
| 92 | + # "message": "success" |
| 93 | + # } |
| 94 | + if ! curl --data-binary @- -f -XPUT -u "$BINTRAY_USER:$BINTRAY_API_KEY" -H "Content-Type: application/octet-stream" "https://api.bintray.com/maven/$BINTRAY_SUBJECT/$BINTRAY_REPO/$BINTRAY_PACKAGE/$__as;publish=0" < "$__file" |
| 95 | + then |
| 96 | + echo "Failed to upload $__as" |
| 97 | + |
| 98 | + rm -rvf "/tmp/$$/" |
| 99 | + |
| 100 | + exit 4 |
| 101 | + fi |
| 102 | +done |
| 103 | + |
| 104 | +# Do not need these files anymore |
| 105 | +rm -rvf "/tmp/$$/" |
| 106 | + |
| 107 | +# Allow bintray to settle for a bit |
| 108 | +echo "Settling..." |
| 109 | +sleep 15 |
| 110 | + |
| 111 | +# *** Publish content |
| 112 | +# HTTP -> POST /content/:subject/:repo/:package/:version/publish |
| 113 | +# Status: 200 OK |
| 114 | +# RESULT -> { |
| 115 | +# "files": 39 |
| 116 | +# } |
| 117 | +if ! curl -f -XPOST -u "$BINTRAY_USER:$BINTRAY_API_KEY" "https://api.bintray.com/content/$BINTRAY_SUBJECT/$BINTRAY_REPO/$BINTRAY_PACKAGE/$__pom_ver/publish" |
| 118 | +then |
| 119 | + echo "Failed to publish!" |
| 120 | + exit 5 |
| 121 | +fi |
| 122 | + |
| 123 | +# Allow bintray to settle for a bit |
| 124 | +echo "Settling..." |
| 125 | +sleep 15 |
| 126 | + |
| 127 | +# *** |
| 128 | +# HTTP -> POST /maven_central_sync/:subject/:repo/:package/versions/:version |
| 129 | +# BODY -> { |
| 130 | +# "username": "userToken", // Sonatype OSS user token |
| 131 | +# "password": "passwordToken", // Sonatype OSS user password |
| 132 | +# "close": "1" // Optional |
| 133 | +# } |
| 134 | +if ! echo '{"username":"'"$SONATYPE_USERTOKEN"'", "password":"'"$SONATYPE_PASSWORDTOKEN"'", "close": "1"}' | curl --data-binary @- -f -XPOST -u "$BINTRAY_USER:$BINTRAY_API_KEY" -H "Content-Type: application/json" \ |
| 135 | + "https://api.bintray.com/maven_central_sync/$BINTRAY_SUBJECT/$BINTRAY_REPO/$BINTRAY_PACKAGE/versions/$__pom_ver" |
| 136 | +then |
| 137 | + echo "Failed to sync to maven central!" |
| 138 | + exit 5 |
| 139 | +fi |
| 140 | + |
| 141 | +echo "Cool it worked!" |
| 142 | + |
0 commit comments