bintray.sh 1.65 KB
Newer Older
noplanman's avatar
noplanman committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#!/usr/bin/env sh

# Based on bintray.sh by Lukas Matt (@zauberstuhl)
# https://git.feneas.org/ganggo/ganggo/blob/master/ci/scripts/bintray.sh

# Note: Set via GitLab protected vars!
# BINTRAY_USER=$1
# BINTRAY_API_KEY=$2
# BINTRAY_REPO=$3

PKG_NAME=borg-binaries

API=https://api.bintray.com
CURL="curl -u${BINTRAY_USER}:${BINTRAY_API_KEY} -H Content-Type:application/json -H Accept:application/json"

DATA="{
    \"name\": \"${PKG_NAME}\",
    \"desc\": \"BorgBackup binaries for various architectures\",
    \"vcs_url\": \"${CI_PROJECT_URL}\",
    \"licenses\": [\"WTFPL\"],
    \"issue_tracker_url\": \"${CI_PROJECT_URL}/issues\",
    \"website_url\": \"${CI_PROJECT_URL}\",
    \"desc_url\": \"${CI_PROJECT_URL}\",
    \"labels\": [\"borg\", \"borgbackup\", \"binaries\"],
    \"public_download_numbers\": true,
    \"public_stats\": true
}"

echo "Creating package ${PKG_NAME}..."
${CURL} -X POST -d "${DATA}" "${API}/packages/${BINTRAY_REPO}"

for BIN in $(ls borg-${VERSION}-*); do
    LOG=$(mktemp)
    ARCH=$(echo "${BIN}" | cut -d/ -f4 | cut -d- -f3)
    UPSTREAM="borg-${VERSION}-${ARCH}"
    STATUS_CODE=$(
        ${CURL} --write-out %{http_code} --silent --output "${LOG}" \
        -T "${BIN}" -H X-Bintray-Package:"${PKG_NAME}" -H X-Bintray-Version:"${VERSION}" \
        "${API}/content/${BINTRAY_REPO}/${UPSTREAM}"
    )

    if [ $STATUS_CODE -eq 201 ]; then
        echo "Publishing ${UPSTREAM}..."
        echo $(
            ${CURL} -X POST -d "{ \"discard\": \"false\" }" \
            ${API}/content/${BINTRAY_REPO}/${PKG_NAME}/${VERSION}/publish
        )
    else
        echo "Cannot publish ${UPSTREAM}!" && cat ${LOG} && exit 1
    fi
    rm "${LOG}"
done