Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #60 from andresmgot/release
Browse files Browse the repository at this point in the history
Enable automatic releases
  • Loading branch information
andresmgot authored Sep 6, 2017
2 parents 904364e + b06a4e5 commit 326db7e
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 3 deletions.
22 changes: 20 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,25 @@ services:
- docker
env:
global:
- KUBELESS_VERSION=0.1.0
- KUBELESS_VERSION: 0.1.0
- REPO_DOMAIN: serverless
- REPO_NAME: serverless-kubeless
- secure: "s+L8ndj0uMNwqbLvbHePHeMJw2LI8DdEdcq1vJ98hNwHOWQc2mHVB4utG9EZFkaL+RAZYduldSJqr443d2BugxrkmzhLUlM5vDks+zHeKecwTah2uuaMUXVT/y/cWDDTVp3phqSqWbHBMG6u0ImvTVWHpnkux55S3QJTHevvhdodpO6VDTsJCEB3e1d2hHxi0L9tJrFXzQRpooV8IUuODwKBJyhK4CD7rvu0D1gBgHaUNnNLrCy4YTaFl19q5NdZUtrQDC7rpSPOhFI9CBFX8GiFq6nY3XzFASwq/JtKc3K7OLIC7Wqb6JpuvFhG6S1yhBzp73pnoE9U0Bi+YMa3L+nPoh58dCB2ldNCCCMbx7R6PWq/TwYzLvgZZ7queC2kbvCTrtU6JJfmb0CxmX1fnUIpCsNeyXaPuo4Ly6WJeAID32z79CwMo9NH0uOVTLy3LTrLcEfELhBRL5+WkMvKmXUt8yN/jEIa/H38pQN5Y/AnJ0KznO8RZ2nLhi1cR+xUkxfPVZ22Wr2XkbzJDZih/mZR+5GQBfUHWgpUChK+e8dOhplk+4PZJEO6Myja7ykXBPYtL9CV/Xi+1nQqLmfhyChiES201KusJr1IrFklslzCzgrSH8Dv2yaYUTe/Ub/I3gWIhKOXY66gkpmB6MSBJUfMK3uR4/wYfCvbtBTugsY="
install:
- npm install -g serverless
- npm install
- npm install
after_success:
- |
if [[ "$TRAVIS_BRANCH" == master && \
"$TRAVIS_PULL_REQUEST" == false && \
-n "$ACCESS_TOKEN" ]]; then
./scripts/release.sh
fi
deploy:
provider: npm
email: [email protected]
api_key:
secure: "jn9tA4DES1n4uxhD+rb7pbzux523AULAgv1f5umqAzvw9bCz7mD6nLS7fo1W8RZSPND7aPM+X5hPknyHm1L+tZbOInKNtCwFkKW2IELJ6a2OCQ+zXN/S/Cxu4dsfeDjE0kiAu5a3YejE5xEjkb98j4eC8i2N4gmdPvDLNqyMXH+W8jF/T2ivkxUGxYOMzyffmsfKmHQ2H31VZEDckcQIENUfLJuxeiBPyrppBKEOgQjpAXiAALnBUrLt741xxL7iQRDHUj8v1cmiymrERhcVpWmYvU4BonlcvPnuWK2dLglQAO+t1UoY5nXS23Lc24yXA8XMp/Bv/dHEB4WwQBNZ4vq+ImGqjFI7/HJlYpHa8eVe6rZJxNnmvBAa3HbTwTz0hoaGwAmHMqPtwelYwL92hEUV/lXQoial9WXSwIqrt24J4Q8UH7jZK3uY3LnCZggDTShSyTvzVp5Xjw/vN0xo5CDlXJ8FZpFkVUWOp7ISYEynzOlW8OZynRiboXyAgLfFMDglhDkcLCpkQLKfKSa0vZWmhgHgNsxs44cFb7pElciQ2uYQjFldXjU/4qVN65s58t4Sn69nFpSthSQKa5iwYMXbI792onVBO334pBdUFBagzP3e4Th4y2k1pFZTZ5UV5gs/2/ROK1KsM5XCi7px4Ddw1kMY4Q6PHZBaTLblqU4="
on:
tags: true
repo: serverless/serverless-kubeless
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-kubeless",
"version": "0.1.11",
"version": "0.1.12",
"description": "This plugin enables support for Kubeless within the [Serverless Framework](https://github.com/serverless).",
"main": "index.js",
"directories": {
Expand Down
64 changes: 64 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash
set -e

function get_version {
echo $(jq -r .version ./package.json)
}

function check_tag {
local tag=$1
published_tags=`curl -s https://api.github.com/repos/$REPO_DOMAIN/$REPO_NAME/tags`
already_published=`echo $published_tags | jq ".[] | select(.name == \"$tag\")"`
echo $already_published
}

function release_tag {
local tag=$1
git fetch --tags
local last_tag=`curl -s https://api.github.com/repos/$REPO_DOMAIN/$REPO_NAME/tags | jq --raw-output '.[0].name'`
local release_notes=`git log $last_tag..HEAD --oneline`
local parsed_release_notes=$(echo "$release_notes" | sed -n -e 'H;${x;s/\n/\\n - /g;s/^\\n//;p;}')
parsed_release_notes=`echo "$parsed_release_notes" | sed -e '${s/ \( - [^ ]* Merge pull request\)/\1/g;}'`
release=`curl -H "Authorization: token $ACCESS_TOKEN" -s --data "{
\"tag_name\": \"$tag\",
\"target_commitish\": \"master\",
\"name\": \"$REPO_NAME-$tag\",
\"body\": \"Release $tag includes the following commits: \n$parsed_release_notes\",
\"draft\": false,
\"prerelease\": false
}" https://api.github.com/repos/$REPO_DOMAIN/$REPO_NAME/releases`
echo $release | jq ".id"
}

version=`get_version`

if [[ -z "$REPO_NAME" || -z "$REPO_DOMAIN" ]]; then
echo "Github repository not specified" > /dev/stderr
exit 1
fi

if [[ -n "$ACCESS_TOKEN" ]]; then
echo "Unable to release: Github Token not specified" > /dev/stderr
exit 1
fi

repo_check=`curl -s https://api.github.com/repos/$REPO_DOMAIN/$REPO_NAME`
if [[ $repo_check == *"Not Found"* ]]; then
echo "Not found a Github repository for $REPO_DOMAIN/$REPO_NAME, it is not possible to publish it" > /dev/stderr
exit 1
else
tag=v$version
already_published=`check_tag $tag`
if [[ -z $already_published ]]; then
echo "Releasing $tag in Github"
release_id=`release_tag $tag`
if [ "$release_id" == "null" ]; then
echo "There was an error trying to release $tag" > /dev/stderr
exit 1
else
echo "Released $tag with ID $release_id"
fi
else
echo "Skipping Github release since $tag was already released"
fi
fi

0 comments on commit 326db7e

Please sign in to comment.