-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhash.ps1
52 lines (43 loc) · 1.12 KB
/
hash.ps1
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
49
50
51
52
#!/usr/bin/env pwsh
[CmdletBinding()]
param (
[Parameter()]
[string]
$version
)
function Get-Hash {
param (
[Parameter()]
[string]
$version
)
if (!$version) {
$version = $(git describe --tags --abbrev=0)
}
$result = $(git show-ref --tag $version) | Select-Object -Last 1
$result.split(" ")[0]
}
function Get-Url {
param (
[Parameter(Mandatory=$true)]
[string]
$source
)
$hash=Get-ModuleHash $source
$splitter=$source.split("/")
return "git::https://github.com/$($splitter[0])/terraform-$($splitter[2])-$($splitter[1]).git?ref=$($hash)"
}
function Get-ModuleHash {
param (
[Parameter(Mandatory=$true)]
[string]
$source
)
$splitter=$source.split("/")
$repo="https://github.com/$($splitter[0])/terraform-$($splitter[2])-$($splitter[1])"
write-debug $repo
$($(git -c 'versionsort.suffix=-' `
ls-remote --exit-code --refs --sort='version:refname' --tags $repo '*.*.*' `
| Select-Object -Last 1).split("refs") | Select-Object -First 1).trim()
}
Get-Hash -version $version