Skip to content

Commit

Permalink
Add script to publish deb packages to bintray
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorvam committed May 28, 2019
1 parent 335b0f8 commit 9248642
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ coverage*
.idea/*

snap.login

.DS_Store
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ after_success:
deploy:
- provider: script
skip_cleanup: true
script: curl -sL https://git.io/goreleaser | bash
script: >-
curl -sL https://git.io/goreleaser | bash &&
./release/publish_deb_to_bintray.sh
verbose: true
on:
tags: true
condition: "$TRAVIS_OS_NAME = linux"
master: true
master: true
108 changes: 108 additions & 0 deletions release/publish_deb_to_bintray.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/bin/sh

set -e

REPO="dunner-deb"
PACKAGE="dunner"
DISTRIBUTIONS="stable"
COMPONENTS="main"

if [ -z "$USER" ]; then
echo "USER is not set"
exit 1
fi

if [ -z "$API_KEY" ]; then
echo "API_KEY is not set"
exit 1
fi

setVersion () {
VERSION=$(curl --silent "https://api.github.com/repos/leopardslab/dunner/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/');
}

setUploadDirPath () {
UPLOADDIRPATH="pool/d/$PACKAGE"
}

downloadArtifacts() {
echo "Dowloading artifacts"
FILES=$(curl -s https://api.github.com/repos/leopardslab/dunner/releases/latest \
| grep "browser_download_url.*deb" \
| cut -d : -f 3 \
| sed -e 's/^/https:/' \
| tr -d '"' );
echo $FILES
for i in $FILES; do
RESPONSE_CODE=$(curl -O $i)
if [ "$(echo $RESPONSE_CODE | head -c2)" != "20" ]; then
echo "Unable to download $i HTTP response code: $RESPONSE_CODE"
fi
done;
echo "Finished downloading"
}

bintrayUpload () {
for i in $FILES; do
FILENAME=${i##*/}
ARCH=$(echo ${FILENAME##*_} | cut -d '.' -f 1)
if [ $ARCH == "386" ]; then
ARCH="i386"
fi

URL="https://api.bintray.com/content/leopardslab/$REPO/$PACKAGE/$VERSION/$UPLOADDIRPATH/$FILENAME;deb_distribution=$DISTRIBUTIONS;deb_component=$COMPONENTS;deb_architecture=$ARCH?publish=1&override=1"
echo "Uploading $URL"

CURL_COMMAND="curl -T $FILENAME -u$USER:$API_KEY $URL -I -s -w "%{http_code}" -o /dev/null"
RESPONSE_CODE=$(CURL_COMMAND);
if [ "$(echo $RESPONSE_CODE | head -c2)" != "20" ]; then
echo "Unable to upload, HTTP response code: $RESPONSE_CODE"
exit 1
fi
echo "HTTP response code: $RESPONSE_CODE"
done;
}

bintraySetDownloads () {
for i in $FILES; do
FILENAME=${i##*/}
ARCH=$(echo ${FILENAME##*_} | cut -d '.' -f 1)
if [ $ARCH == "386" ]; then
ARCH="i386"
fi
URL="https://api.bintray.com/file_metadata/leopardslab/$REPO/$UPLOADDIRPATH/$FILENAME"

echo "Putting $FILENAME in $PACKAGE's download list"
RESPONSE_CODE=$(curl -X PUT -d "{ \"list_in_downloads\": true }" -H "Content-Type: application/json" -u$USER:$API_KEY $URL -s -w "%{http_code}" -o /dev/null);

if [ "$(echo $RESPONSE_CODE | head -c2)" != "20" ]; then
echo "Unable to put in download list, HTTP response code: $RESPONSE_CODE"
exit 1
fi
echo "HTTP response code: $RESPONSE_CODE"
done
}

snooze () {
echo "\nSleeping for 30 seconds. Have a coffee..."
sleep 30s;
echo "Done sleeping\n"
}

printMeta () {
echo "Publishing: $PACKAGE"
echo "Version to be uploaded: $VERSION"
}

cleanArtifacts () {
rm -f "$(pwd)/*.deb"
}

cleanArtifacts
downloadArtifacts
setVersion
printMeta
setUploadDirPath
bintrayUpload
snooze
bintraySetDownloads

0 comments on commit 9248642

Please sign in to comment.