Tagging versions of Chef recipes in git after-the-fact

Tagging versions of Chef recipes in git after-the-fact

Chef metadata.rb versions and Git Version tags are NOT CONNECTED AT ALL

#!/bin/bash

# Auto tag script

# Make sure you tag master and have the current tree

pwd

git checkout master

git pull

rm -f temp.txt

rm -f temp2.txt

# Get the versions and metadata.rb commits, dump to file

git log -p — metadata.rb  |grep -E ‘(commit|\+version)’ > temp.txt

# Need to whack sequential commit commit, and keep only the first one:

# see https://stackoverflow.com/questions/45478938/delete-duplicate-lines-through-pattern-in-bash

awk ‘$1==”commit” && p==”commit”{next} {print; p=$1}’ temp.txt > temp2.txt

# dump the file into a usable format:

# see: https://stackoverflow.com/questions/9999934/sed-joining-lines-depending-on-the-second-one

cat temp2.txt | sed ‘$!N;s/\n\s*+//;P;D’

cat temp2.txt | sed ‘$!N;s/\n\s*+//;P;D’ |sed -e ‘s/version//g’  |sed -e ‘s/commit//g’ |tr -d “” |tr “‘” “,” | awk -F’,’ ‘{print “git tag -a v” $2 ” ” $1 ” -m \”Automated tagging\”” }’ > autotag.sh

chmod +x autotag.sh

./autotag.sh

git push –tags origin master

rm -f temp.txt

rm -f temp2.txt

rm -f autotag.sh

Checking out a tag as a new branch (you can’t checkout a tag)

git checkout master

git pull

git checkout -b do_not_merge v2.4.0

How to do it by hand:

Pull down and sync a master copy of your repo locally, cd into that directory:

dev

cd wdprt_sece_zdd

git pull

git checkout master

git pull

git log -p — metadata.rb  |grep -E ‘(commit|\+version)’

CLI:

git log -p — metadata.rb  |grep -E ‘(commit|\+version)’

Gives:

commit d7eb053b80ff04c58eda52b89abeef53cf15736c

+version          ‘2.1.0’

commit 1deb63acb26b3e2028d2b44237560f960ee0baed

+version          ‘2.0.2’

commit b7011d2890e972c6d9ac1920e148f461d94e7425

+version          ‘2.0.1’

commit c710d94ac80667c1706c95bee3c001a29c7c7e8a

commit 0366b2d1be83c677df1ed8eb3cb2c4c4d700aac4

+version          ‘1.0.1’

commit a81a4222d60ec27ef559a1043d91bdfd6e1754c9

    initial commit

+version          ‘1.0.0’

Note the splits! Top commit goes with the first version listed, regardless of interim commits!

GUI:

on the Web UI, find the metadata.rb for your app and select it since this dictates the version to chef, we’ll match up the git tags to it

once in metadata.rb, click the history button for it

from the list of changes to metadata.rb, click the clipboard thing, then <>

use the SHA that it put on the clipboard and the version in the metadata.rb file that you’re looking at

ie:

69436410dae0f256214fa2f27f4bb96e7e83f28a  and  1.1.1

Both:

from your directory of that repo, construct commands like this (you can use the whole SHA or the first 6-ish chars)

If you have multiple metadata.rb versions, only tag the latest (highest in the list) one because someone committed a version without a version bump.

git tag -a v1.1.0 41fb370 -m “Tagging wdprt_sece_mq v1.1.0”

git tag -a v1.1.1 6943641 -m “Tagging wdprt_sece_mq v1.1.1”

git tag -a v1.0.4 98d39c1 -m “Tagging wdprt_sece_mq v1.0.4”

git tag -a v1.0.3 fe5fa88 -m “Tagging wdprt_sece_mq v1.0.3”

git tag -a v1.0.2 9d7f1f9 -m “Tagging wdprt_sece_mq v1.0.2”

git tag -a v1.0.1 0f071d9 -m “Tagging wdprt_sece_mq v1.0.1”

git tag -a v1.0.0 cf56449 -m “Tagging wdprt_sece_mq v1.0.0”

git tag -a v1.1.2 26f75a2 -m “Tagging wdprt_sece_mq v1.1.2”

git push –tags origin master

And now berks should behave since it can find a tag

How to delete tags if you goof:

WW-AM04041696:wdprt_tomcat bwilliam$ git push –delete origin v2.5.1

To https://github.disney.com/WDPRT-chef/wdprt_tomcat.git

– [deleted]         v2.5.1

WW-AM04041696:wdprt_tomcat bwilliam$ git tag -d v2.5.1

Deleted tag ‘v2.5.1’ (was dccffed)

WW-AM04041696:wdprt_tomcat bwilliam$ git tag -d delete

Deleted tag ‘delete’ (was dccffed)

# Then re-push the right tag

WW-AM04041696:wdprt_tomcat bwilliam$ git tag -a v2.5.1 2614f4baf955aeac142a94070a15bf48a8ba6e16 -m “Tagging v2.5.1”

WW-AM04041696:wdprt_tomcat bwilliam$ git push –tags origin master

Automatic tagging (WIP)

We get this:

commit 74fb42b61975ebc560dabbb0dd380f763a1a0d15

+version          ‘2.0.3’

commit a721d6f882e11f7889be0dcb4c9daa9d2b40b2ba

commit 04a05cc3bd5990aa7c6587ced88afd5f1f4d432d

+version          ‘2.0.2’

commit 1f3dc2742613b396291c054116239b67398f7c33

+version          ‘2.0.1’

commit 4a88517235d66ad0f623b67e5ac4a500aada2f27

+version          ‘2.0.0’

commit 26f75a269212d2743d98abd7314771056b1c6200

+version          ‘1.1.2’

commit 69436410dae0f256214fa2f27f4bb96e7e83f28a

+version          ‘1.1.1’

commit 41fb3704d9b78546acb5025b3d49f7af18f6eba0

+version          ‘1.1.0’

commit 98d39c11f80e499288cbb9bf3a641379ddd68257

+version          ‘1.0.4’

commit fe5fa88dc50b1459eda0cc7a28c13fda5afb26f0

+version          ‘1.0.3’

commit 9d7f1f91a820f3ec5c3102ea4acb837a5cc791ca

+version          ‘1.0.2’

commit 0f071d981b8b491e4f52b7b1d8d0a8b59daa18bf

+version          ‘1.0.1’

commit cf5644964a8830d178bbb9538049db141e64da88

commit d07c46b3b7fdb5bb50e38b08717247f9a8e979c4

commit f680e39ecc46ab643af3ab8edaa8e30ca6d22c24

commit d253d62fa3a72c8b40713c8da76d82b4293155c3

commit 36b4fd8e0ec33040d3236ce8ad8a010d6ad71be2

+version          ‘1.0.0’

so:

# Make sure you tag master and have the current tree

git checkout master

git pull

rm -f temp.txt

rm -f temp2.txt

# Get the versions and metadata.rb commits, dump to file

git log -p — metadata.rb  |grep -E ‘(commit|\+version)’ > temp.txt

#check the file, can be weird

# vi temp.txt

# Need to whack sequential commit commit, and keep only the first one:

# see https://stackoverflow.com/questions/45478938/delete-duplicate-lines-through-pattern-in-bash

awk ‘$1==”commit” && p==”commit”{next} {print; p=$1}’ temp.txt > temp2.txt

# dump the file into a usable format:

# see: https://stackoverflow.com/questions/9999934/sed-joining-lines-depending-on-the-second-one

cat temp2.txt | sed ‘$!N;s/\n\s*+//;P;D’

# gives: 

commit 74fb42b61975ebc560dabbb0dd380f763a1a0d15version          ‘2.0.3’

commit a721d6f882e11f7889be0dcb4c9daa9d2b40b2baversion          ‘2.0.2’

commit 1f3dc2742613b396291c054116239b67398f7c33version          ‘2.0.1’

#Beauty! clean it up:

# need it in this format:

# git tag -a v1.1.0 41fb370 -m “Tagging wdprt_sece_mq v1.1.0”

# cat temp2.txt | sed ‘$!N;s/\n\s*+//;P;D’ |sed -e ‘s/version//g’  |sed -e ‘s/commit//g’ |tr -d ” ” |tr “‘” “,”

# 74fb42b61975ebc560dabbb0dd380f763a1a0d15,2.0.3,

# a721d6f882e11f7889be0dcb4c9daa9d2b40b2ba,2.0.2,

# Make the script

# cat temp2.txt | sed ‘$!N;s/\n\s*+//;P;D’ |sed -e ‘s/version/ -a v/g’  |sed -e ‘s/commit/ git tag /g’  |sed -e ‘s/     / /g’ |tr -d “‘”|sed -e ‘s/v  /v/g’

# Makes it wrong, but interesting:

# git tag  74fb42b61975ebc560dabbb0dd380f763a1a0d15 -a v2.0.3

# git tag  a721d6f882e11f7889be0dcb4c9daa9d2b40b2ba -a v2.0.2

cat temp2.txt | sed ‘$!N;s/\n\s*+//;P;D’ |sed -e ‘s/version//g’  |sed -e ‘s/commit//g’ |tr -d ” ” |tr “‘” “,” | awk -F’,’ ‘{print “git tag -a ” $2 ” ” $1 ” -m \”Automated tagging\”” }’

# Makes:

git tag -a 2.0.2 a721d6f882e11f7889be0dcb4c9daa9d2b40b2ba -m “Automated tagging”

git tag -a 2.0.1 1f3dc2742613b396291c054116239b67398f7c33 -m “Automated tagging”

git tag -a 2.0.0 4a88517235d66ad0f623b67e5ac4a500aada2f27 -m “Automated tagging”

# GTG!!!

git push –tags origin master