Skip to content

Commit

Permalink
Enable "latest" version
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderSehr committed Dec 4, 2022
1 parent 918b08f commit ee9daa0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/wiki/The CI environment - Publishing.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The publishing works as follows:
1. The script [`utilities/pipelines/resourcePublish/Get-ModulesToPublish.ps1`](https://github.com/Azure/ResourceModules/blob/main/utilities/pipelines/resourcePublish/Get-ModulesToPublish.ps1) gets all changed module files, including child modules, and handles the logic of propagating the appropriate module version to be used:
1. The major (`x.0`) and minor (`0.x`) version are set based on the `version.json` file in the module folder.
1. The patch (`0.0.x`) version is calculated based on the number of commits on the `HEAD` ref (aka. git height). This will cause the patch version to never reset to 0 with major and/or minor increment, as specified for [semver](https://semver.org/).
1. The module is published with a `major.minor.patch` version (`x.y.z`). For Template Specs and Bicep Registry only, a `major` version (`x`) and a `major.minor` version (`x.y`) are also updated, allowing a consumer to:
1. The module is published with a `major.minor.patch` version (`x.y.z`). For Template Specs and Bicep Registry only, a `major` version (`x`), a `major.minor` version (`x.y`) and a `latest` version are also updated, allowing a consumer to:
- Reference the latest version of a major, i.e., the latest minor and patch of a major version.
> Example: Using Template Specs, the reference to a `major` could look like: `ts/modules:microsoft.resources.resourcegroups:1` which means that the template will always consume whatever the potentially overwritten/updated version `1` contains.
- Reference the latest version of a minor, i.e., the latest patch of a minor version.
Expand Down
6 changes: 6 additions & 0 deletions settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ variables:

location: 'West Europe' # The default location to test deploy resources to

######################################
# Publish: Shared settings
######################################

publishLatest: true # [Only for Template-Specs & Bicep Registry] Publish an absolute latest version. Note: This version may include breaking changes and is not recommended for production environments

######################################
# Publish: Template-Spec settings
######################################
Expand Down
28 changes: 25 additions & 3 deletions utilities/pipelines/resourcePublish/Get-ModulesToPublish.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,13 @@ Generates a hashtable with template file paths to publish with a new version.
.PARAMETER TemplateFilePath
Mandatory. Path to a deploy.bicep/json file.
.PARAMETER PublishLatest
Optional. Publish an absolute latest version.
Note: This version may include breaking changes and is not recommended for production environments
.EXAMPLE
Get-ModulesToPublish -TemplateFilePath 'C:\Repos\Azure\ResourceModules\modules\Microsoft.Storage\storageAccounts\deploy.bicep'
Name Value
---- -----
TemplateFilePath C:\Repos\Azure\ResourceModules\modules\Microsoft.Storage\storageAccounts\fileServices\shares\deploy.bicep
Expand All @@ -361,14 +364,17 @@ Version 0.3.848-prerelease
Generates a hashtable with template file paths to publish and their new versions.
#>#
function Get-ModulesToPublish {

[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string] $TemplateFilePath
[string] $TemplateFilePath,

[Parameter(Mandatory = $false)]
[bool] $PublishLatest = $true

)

$ModuleFolderPath = Split-Path $TemplateFilePath -Parent
Expand Down Expand Up @@ -396,6 +402,14 @@ function Get-ModulesToPublish {
Version = ($ModuleVersion.Split('.')[0])
TemplateFilePath = $TemplateFileToPublish.FullName
}

if ($PublishLatest) {
# Absolute latest
$ModulesToPublish += @{
Version = 'latest'
TemplateFilePath = $TemplateFileToPublish.FullName
}
}
}

$ParentTemplateFilesToPublish = Get-ParentModuleTemplateFile -TemplateFilePath $TemplateFileToPublish.FullName -Recurse
Expand All @@ -420,6 +434,14 @@ function Get-ModulesToPublish {
Version = ($ParentModuleVersion.Split('.')[0])
TemplateFilePath = $ParentTemplateFileToPublish.FullName
}

if ($PublishLatest) {
# Absolute latest
$ModulesToPublish += @{
Version = 'latest'
TemplateFilePath = $ParentTemplateFileToPublish.FullName
}
}
}
}
}
Expand Down

0 comments on commit ee9daa0

Please # to comment.