Skip to content

Instantly share code, notes, and snippets.

@lxhunter
Last active July 8, 2022 19:12
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lxhunter/9d4310462b6972a3f57b5f914543fd51 to your computer and use it in GitHub Desktop.
Save lxhunter/9d4310462b6972a3f57b5f914543fd51 to your computer and use it in GitHub Desktop.
Automated semantic versioning for travis-ci or any other ci
#!/bin/bash
export SEMVER_LAST_TAG=$(git describe --abbrev=0 --tags 2>/dev/null)
export SEMVER_RELEASE_LEVEL=$(git log --oneline -1 --pretty=%B | cat | tr -d '\n' | cut -d "[" -f2 | cut -d "]" -f1)
#curl -o /tmp/hub.tgz https://github.com/github/hub/releases/download/v2.2.9/hub-linux-arm64-2.2.9.tgz
#tar -xvzf /tmp/hub.tgz -C /tmp
if [ -z $SEMVER_LAST_TAG ]; then
>&2 echo "No tags defined"
SEMVER_LAST_TAG="0.0.1"
fi
if [ -n $SEMVER_RELEASE_LEVEL ]; then
git clone https://github.com/fsaintjacques/semver-tool /tmp/semver &> /dev/null
SEMVER_NEW_TAG=$(/tmp/semver/src/semver bump $SEMVER_RELEASE_LEVEL $SEMVER_LAST_TAG)
git tag $SEMVER_NEW_TAG &> /dev/null
git push origin --tags &> /dev/null
echo $SEMVER_NEW_TAG
else
>&2 echo "No release level defined"
fi
exit 0
@lxhunter
Copy link
Author

lxhunter commented Oct 8, 2016

I am using https://github.com/fsaintjacques/semver-tool to auto version my builds:

examples:

for patch level

$ git commit -m "[patch] few changes"

for minor patches

$ git commit -m "[minor] added the foo feature"

for major patches

$ git commit -m "[major] added breaking change"

@mikesparr
Copy link

Very cool. I looked into semantic-release but that was for versioning npm deploys and I'm just interested in bumping the version in package.json and mostly corresponding Github tags. Do you have example of the .travis.yml config to incorporate this script or are you still using this?

@lxhunter
Copy link
Author

@mikesparr: I used in the travis.yml like so:

anguage: python
cache: pip
sudo: required
script:
- echo "yes!"
branches:
  only:
  - next
after_success:
- curl https://gist.githubusercontent.com/lxhunter/9d4310462b6972a3f57b5f914543fd51/raw/semver.sh | bash

@proegssilb
Copy link

Is there any sort of special process you have to do to get this to work? Looks like the tags aren't getting pushed back to github in my repo...

@lxhunter
Copy link
Author

@proegssilb: sorry just saw your comment... how may i be of help?

@lxhunter
Copy link
Author

lxhunter commented Mar 7, 2018

for all interested: i moved to https://github.com/semantic-release/exec for this

@singhjeevan30
Copy link

Is there any sort of special process you have to do to get this to work? Looks like the tags aren't getting pushed back to github in my repo...

hey, same is happening with me... how can i perform the same thing successfully?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment