bintray.sh 1.44 KB
Newer Older
zauberstuhl's avatar
zauberstuhl committed
1 2 3 4 5 6 7 8
#!/bin/bash

API=https://api.bintray.com

# NOTE will be set via gitlab protected vars
# BINTRAY_USER=$1
# BINTRAY_API_KEY=$2
# BINTRAY_REPO=$3
9
PCK_NAME=$(echo $VERSION |sed 's#^v[\.0-9\-]*\([a-z]*\)[\.0-9]*$#\1#')
zauberstuhl's avatar
zauberstuhl committed
10 11 12 13
CURL="curl -u${BINTRAY_USER}:${BINTRAY_API_KEY} -H Content-Type:application/json -H Accept:application/json"

data="{
\"name\": \"${PCK_NAME}\",
14
\"desc\": \"${PCK_NAME} update channel\",
15
\"vcs_url\": \"${CI_PROJECT_URL}\",
zauberstuhl's avatar
zauberstuhl committed
16 17 18 19 20 21 22 23 24 25 26 27 28
\"licenses\": [\"GPL-3.0\"],
\"issue_tracker_url\": \"${CI_PROJECT_URL}/issues\",
\"website_url\": \"${CI_PROJECT_URL}/wikis/home\",
\"desc_url\": \"${CI_PROJECT_URL}\",
\"labels\": [\"ganggo\", \"gitlab\", \"deploy\"],
\"public_download_numbers\": true,
\"public_stats\": true
}"

echo "Creating package ${PCK_NAME}..."
echo $(${CURL} -X POST -d "${data}" ${API}/packages/${BINTRAY_REPO})

for BIN in $(ls updater.*.bin); do
29 30 31 32
  log=$(mktemp)
  osarch=$(echo ${BIN} |cut -d. -f2)
  upstream="updater.${osarch}.${VERSION}.bin"
  status_code=$(${CURL} --write-out %{http_code} --silent --output ${log} \
zauberstuhl's avatar
zauberstuhl committed
33
    -T ${BIN} -H X-Bintray-Package:${PCK_NAME} \
34
    -H X-Bintray-Version:${VERSION} ${API}/content/${BINTRAY_REPO}/${upstream})
zauberstuhl's avatar
zauberstuhl committed
35 36

  if [ $status_code -eq 201 ]; then
37
    echo "Publishing ${upstream}..."
zauberstuhl's avatar
zauberstuhl committed
38
    echo $(${CURL} -X POST -d "{ \"discard\": \"false\" }" \
39
      ${API}/content/${BINTRAY_REPO}/${PCK_NAME}/${VERSION}/publish)
zauberstuhl's avatar
zauberstuhl committed
40
  else
41
    echo -ne "Cannot publish ${upstream}!\n\n" && cat ${log} && exit 1
zauberstuhl's avatar
zauberstuhl committed
42
  fi
43
  rm ${log}
zauberstuhl's avatar
zauberstuhl committed
44
done