-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhash.sh
48 lines (42 loc) · 1.24 KB
/
hash.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash
# gets hash of tag
if [[ $# -eq 0 ]]
then
version=$(git describe --tags --abbrev=0)
else
version=$1
fi
#shellcheck disable=SC2046,SC2005
echo $(git show-ref --tag "${version}") | tail -1| head -n1 | cut -d " " -f1
function get-moduleversion {
IFS='/' read -r name provider module <<<"$1"
url="https://github.com/${name}/terraform-${provider}-${module}"
git -c 'versionsort.suffix=-' \
ls-remote --exit-code --refs --sort='version:refname' --tags "${url}" '*.*.*' \
| tail --lines=1 \
| cut --delimiter='/' --fields=3
}
function get-moduleinfo() {
IFS='/' read -r name provider module <<<"${1}"
url="https://github.com/${name}/terraform-${provider}-${module}"
#echo $url
results=$(git -c 'versionsort.suffix=-' \
ls-remote --exit-code --refs --sort='version:refname' --tags "${url}" '*.*.*' \
| tail --lines=1 )
echo "${results}"
}
function split() {
IFS=" " read -r hash version <<<"$1"
echo "${hash}"
}
function get-modulehash() {
local temp
temp=$(get-moduleinfo "$1")
split "${temp}"
}
function get-url() {
hash=$(get-modulehash "$1")
IFS='/' read -r name provider module <<<"$1"
url="git::https://github.com/${name}/terraform-${provider}-${module}.git?ref=${hash}"
echo "${url}"
}