forked from matsest/bicep-registry-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish-modules.ps1
executable file
·68 lines (59 loc) · 2.18 KB
/
publish-modules.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
[CmdletBinding()]
param (
[Parameter()]
[ValidateScript( { Test-Path $_ })]
[string]
$BicepConfigFile = "$PSScriptRoot/../bicepconfig.json",
[Parameter()]
[string]
$RegistryAliasName = 'demoRegistry'
)
$ErrorActionPreference = 'Stop'
# Check if Bicep is installed
If (!(Get-Command bicep -ErrorAction SilentlyContinue)) {
Write-Warning "Could not find the bicep executable. Not able to publish modules."
exit 1
}
else {
Write-Host "Using $(bicep --version) `n"
}
# Validate Bicep configuration file
If (!(Get-Content $BicepConfigFile -Raw | Select-String $RegistryAliasName -Quiet)) {
Write-Warning "The registry alias $RegistryAliasName was not found in the Bicep configuration file."
exit 1
}
# Get registry settings from Bicep configuration files
$registry = (Get-Content $BicepConfigFile -Raw | ConvertFrom-Json).moduleAliases.br.$RegistryAliasName.registry
$modulePath = (Get-Content $BicepConfigFile -Raw | ConvertFrom-Json).moduleAliases.br.$RegistryAliasName.modulePath
if (!$registry -or !$modulePath) {
Write-Warning "Could not parse configuration from the Bicep configuration file."
exit 1
}
else {
Write-Host "Publishing to $RegistryAliasName [$registry/$modulePath]"
}
# Find git version to publish modules for
# TODO: individual versioning of modules (reconsider versioning after bicep v0.5)
# TODO: Do not republish already published modules (will be supported in Bicep v0.5)
$version = & git describe --tags --abbrev=0
if (($LASTEXITCODE -ne 0) -or (!$version)) {
Write-Warning "Could not determine git tag to use for version"
exit 1
}
# Read modules from modules directory
$modules = Get-ChildItem -Path "$PSScriptRoot/../modules" -Filter "main.bicep" -Recurse
$errors = 0
foreach ($module in $modules) {
$moduleName = $module.Directory.Name
$file = $module.FullName | Resolve-Path -Relative
Write-Host " - Publishing module $($moduleName):$($version) [$($file)]"
bicep publish $module.FullName --target "br:$($registry)/$($modulePath)/$($moduleName):$($version)"
if ($LASTEXITCODE -ne 0) {
Write-Warning "Failed to publish module!"
$errors += 1
}
}
if ($errors -gt 0) {
Write-Warning "Job completed with $errors errors. Please revise!"
exit 1
}