Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bump deployed version tag inside .env file. For use with Envoyer.io and Laravel 5 to update a VERSION var inside the .env file of your Envoyer releases.
#! /bin/bash
archivo='.env'
filelines=`cat $archivo`
i=0
newfilelines=''
echo "Fetching dirty tags from remote repository..."
gitVersion=`git ls-remote -t {{REPOSITORY-URL}} *.*.*^*`
gv=''
echo "Figuring out which is the latest version tag and cleaning the dirty tag list output"
for line in $gitVersion; do
i=$(($i + 1))
if [[ $line =~ ([0-9]+\.[0-9]+\.[0-9]+) ]]; then
if [[ $gv != '' ]]; then
printf -v gv "$gv\n${BASH_REMATCH[0]}"
else
printf -v gv "${BASH_REMATCH[0]}"
fi
fi
done
echo "Counting the tags we ended up with to get the last one only"
tagQty=`echo "$gv" | wc -l`
actualVersion=`echo "$gv" | sed -n "$tagQty"p`
echo "Selected version tag: $actualVersion"
i=0
echo "Now replacing the version entry in the .env file..."
for line in $filelines ; do
i=$(($i + 1))
if [[ $line == *"VERSION="* ]]; then
IFS='=' read -a array <<< "$line"
envVersion="${array[1]}"
line="VERSION=$actualVersion"
fi
printf -v newfilelines "%1s\n%5s" "$newfilelines" "$line"
done
echo "$newfilelines" > "$archivo"
echo "Finished!"
@morales2k

This comment has been minimized.

Copy link
Owner Author

morales2k commented Oct 2, 2015

This was set inside an envoyer.io hook. There were other commands we had to do, to start the ssh agent and assign a key to use for communicating with the bitbucket hosted repository so it pulled the tags in a non-interactive way. Using the https url for the repo will prompt for password everytime and we dont want to use that as envoyer automatic commands will make it hard to input that for the git command, so we do the auth with ssh keys and it works.

Just run the ssh setup commands (start the agent and add the key for the session envoyer connects in to work) before running this script in the same hook.

So far it is working but I am unsure if it will continue to work as expected past version 0.9.x or 0.x.9 as I am unsure if the order of the tags from the git ls-remote -t command will always remain as expected (last pushed tag is last in list). As such if you are reading this and have knowledge on the subject plz drop a line and shed some light on it.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.