Skip to content

Commit 47f82bd

Browse files
so we can decompile armtemplates into bicep files from github
1 parent 8eb72a8 commit 47f82bd

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Decompile-GithubArmTemplate.ps1

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function Decompile-GithubArmTemplate {
2+
[CmdletBinding()]
3+
param (
4+
[Parameter()]
5+
[string]
6+
$GithubPath,
7+
8+
[Parameter()]
9+
[string]
10+
$Path,
11+
12+
[Parameter()]
13+
[string]
14+
$FileName
15+
)
16+
17+
if($GithubPath.StartsWith('https://raw.githubusercontent.com')){
18+
Write-Verbose "Well it looks like raw content URL"
19+
} elseif ($GithubPath.StartsWith('https://github.com')) {
20+
Write-Verbose "Well it looks like a base Github URL"
21+
$GithubPath = $GithubPath -replace 'github', 'raw.githubusercontent' -replace '/blob',''
22+
$Name = $GithubPath.Split('/')[-2]
23+
24+
}else{
25+
Write-Warning "Use the right path and start with https://"
26+
Return
27+
}
28+
29+
$DownloadFile = "$env:TEMP\{0}.{1}" -f $Name, 'json'
30+
31+
($Path) ? ($outputPath = $Path) : ($outputPath = $Pwd.Path)
32+
($FileName) ? ($FileName) : ($FileName = "$Name.{0}" -f 'bicep')
33+
34+
$wc = New-Object System.Net.WebClient
35+
$wc.DownloadFile($GithubPath, $DownloadFile)
36+
37+
bicep decompile $DownloadFile --outfile "$outputPath\$FileName"
38+
39+
Write-Output "Decompiled $GithubPath to $outputPath\$FileName"
40+
}

0 commit comments

Comments
 (0)