when someone ask you, is it posible to get my latest tag from my github repository so i can put or add it into my automation deployment process for staging environment every morning without have to trigger it manually ? here it’s how to solve it
awan@google-provision:~$ MY_PROJECT=avengers
awan@google-provision:~$ git ls-remote --tags git@github.com:MY_REPOSITORY/"$MY_PROJECT".git | awk '{print $2}' | grep -v '{}' | awk -F"/" '{print $3}' | tail -n 1
put it into variable and you can pass the variable into your automation scripts.
if you’re using ansible to deploy it, ansible has module to do this
- name: Get Latest Tag from my Repo
local_action: shell git ls-remote --tags git@github.com:MY_REPOSITORY/"$MY_PROJECT".git | awk '{print $2}' | grep -v '{}' | awk -F"/" '{print $3}' | tail -n 1
register: my_last_tag
- name: Update Code Via Github
git: repo=git@github.com:MY_REPOSITORY/avengers.git
dest=/home/google/public
update=yes
accept_hostkey=yes
ssh_opts="-o ForwardAgent=yes"
version="{{ item }}"
with_items: my_last_tag.stdout_lines
register: code
sudo: no
tags: update