Skip to content

Instantly share code, notes, and snippets.

@gitawego
Last active November 3, 2019 14:56
Show Gist options
  • Save gitawego/6989c014e130511a7f4514b30a52fee1 to your computer and use it in GitHub Desktop.
Save gitawego/6989c014e130511a7f4514b30a52fee1 to your computer and use it in GitHub Desktop.
sort tags in groovy
// get tags from git first
// git ls-remote --tags --refs https://github.com/angular/angular.git
// def arr = "git ls-remote --tags --refs https://github.com/angular/angular.git".execute()
// arr.waitFor()
// def result = arr.text.tokenize('\n')
def result = new String[3]
result[0] = "d6602ec5194c87b0fc87103ca4d67251c76f233a refs/tags/v1.99"
result[1] = "f25a265a342aed6041ab0cc484224d9ca54b6f41 refs/tags/v0.03.1"
result[2] = "7ceca275d047c90c0c7d5afb13ab97efdf51bd6e refs/tags/v0.03.10"
def finalArray = []
result.each{
finalArray.add((it=~/refs\/tags\/v(.*)$/)[0][1])
}
finalArray.sort()
finalArray.reverse(true)
println finalArray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment