#!/bin/bash

VERSION="$(cat project.clj | egrep -o -m 1 '[0-9].[0-9].[0-9](-[A-Z]+)?')"

echo "VERSION: $VERSION"

if [[ $VERSION =~ "SNAPSHOT" ]];
then
    echo "Skipping tagging..."
    exit 0;
fi

lein pom

# Taken from https://github.com/k911/swoole-bundle/blob/develop/deploy/releaser.sh
## Disclaimer: Thanks @k911 for providing me your solution!
git tag ${VERSION}

yarn conventional-changelog -p angular -i CHANGELOG.md -s -r 0

git tag -d ${VERSION}

git add CHANGELOG.md pom.xml
git commit -q -m "chore(release): Version ${VERSION} :tada: [skip ci]

$(./node_modules/.bin/conventional-changelog)
"

git push HEAD:master --tags

conventional-github-releaser -p angular -r 0 -t ${GH_TOKEN}
