Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added 'Publish from tag' pipeline for AVM #673

Merged
merged 81 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
20ac8b7
Added skeleton
AlexanderSehr Nov 7, 2023
4939b4d
Implemented first new tests
AlexanderSehr Nov 7, 2023
4e1d86f
Changed to warning
AlexanderSehr Nov 8, 2023
94fff0b
Expanded test verbosity & added additional tets
AlexanderSehr Nov 8, 2023
c18ce6b
Finalized further tests
AlexanderSehr Nov 8, 2023
a343694
Update to latest
AlexanderSehr Nov 8, 2023
3a6f0a2
Update to latest
AlexanderSehr Nov 8, 2023
4ab6a5b
Added module name + small fix
AlexanderSehr Nov 8, 2023
9bb64bd
Fixed kvlt
AlexanderSehr Nov 8, 2023
68e2bd2
Small caching fix
AlexanderSehr Nov 8, 2023
1a013c2
Small fix and enabled passthru of warnings to GH
AlexanderSehr Nov 8, 2023
1c2fc8a
More updates
AlexanderSehr Nov 8, 2023
d9c6dd5
Update to latest
AlexanderSehr Nov 8, 2023
dd0c343
Updated test names
AlexanderSehr Nov 8, 2023
2ebd458
JSON rollback
AlexanderSehr Nov 8, 2023
f6caf7e
Updated regex
AlexanderSehr Nov 8, 2023
f56f66a
Removed assertion
AlexanderSehr Nov 8, 2023
282b640
Update to latest
AlexanderSehr Nov 8, 2023
c025f52
Update avm/utilities/pipelines/staticValidation/compliance/module.tes…
AlexanderSehr Nov 9, 2023
405901a
Update avm/utilities/pipelines/staticValidation/compliance/module.tes…
AlexanderSehr Nov 9, 2023
904c82f
Merge branch 'main' into users/alsehr/testFileCompliance
AlexanderSehr Nov 9, 2023
ef24d1f
Rollback of unrelated changes
AlexanderSehr Nov 9, 2023
9393aa1
Merge branch 'Azure:main' into main
AlexanderSehr Nov 9, 2023
cb39086
Merge branch 'Azure:main' into main
AlexanderSehr Nov 9, 2023
89eac40
Merge branch 'Azure:main' into main
AlexanderSehr Nov 10, 2023
712a673
Merge branch 'Azure:main' into main
AlexanderSehr Nov 13, 2023
55e095f
Resolved conflict
AlexanderSehr Nov 14, 2023
3121335
Update to latest
AlexanderSehr Nov 14, 2023
e9d736c
Merge branch 'Azure:main' into main
AlexanderSehr Nov 15, 2023
abfa1b9
Merge branch 'Azure:main' into main
AlexanderSehr Nov 15, 2023
c6707f6
Merge branch 'Azure:main' into main
AlexanderSehr Nov 16, 2023
246f9ba
Merge branch 'Azure:main' into main
AlexanderSehr Nov 16, 2023
6e9729d
Merge branch 'Azure:main' into main
AlexanderSehr Nov 16, 2023
26ea9f6
Merge branch 'Azure:main' into main
AlexanderSehr Nov 17, 2023
c2d183b
Merge branch 'Azure:main' into main
AlexanderSehr Nov 18, 2023
0c6650e
Merge branch 'Azure:main' into main
AlexanderSehr Nov 19, 2023
65094a5
Merge branch 'Azure:main' into main
AlexanderSehr Nov 21, 2023
968cd9a
Merge branch 'Azure:main' into main
AlexanderSehr Nov 21, 2023
3c9589b
Merge branch 'Azure:main' into main
AlexanderSehr Nov 24, 2023
eb34ddf
Merge branch 'Azure:main' into main
AlexanderSehr Nov 25, 2023
d16099e
Added publish from tag pipeline
AlexanderSehr Nov 26, 2023
57dab9d
Update to latest
AlexanderSehr Nov 26, 2023
7f8ec0c
Temp disabled login for testing
AlexanderSehr Nov 26, 2023
3d4f5c6
Added pipeline to main for testing
AlexanderSehr Nov 26, 2023
283fd03
Update to latest
AlexanderSehr Nov 26, 2023
1130cc3
Renamed pipeline
AlexanderSehr Nov 26, 2023
f885851
Update to latest
AlexanderSehr Nov 26, 2023
b6121d7
Update to latest
AlexanderSehr Nov 26, 2023
776c4f9
Update to latest
AlexanderSehr Nov 26, 2023
b4d4694
Update to latest
AlexanderSehr Nov 26, 2023
5c5a0af
Update to latest
AlexanderSehr Nov 26, 2023
536ce01
Re-enabled commented test code
AlexanderSehr Nov 26, 2023
70154f3
Merge branch 'Azure:main' into main
AlexanderSehr Nov 27, 2023
18bd2ad
Merge branch 'Azure:main' into main
AlexanderSehr Nov 27, 2023
940b34f
Merge branch 'Azure:main' into main
AlexanderSehr Nov 28, 2023
fbb840f
Merge branch 'Azure:main' into main
AlexanderSehr Nov 29, 2023
381e366
Merge branch 'Azure:main' into main
AlexanderSehr Nov 29, 2023
1707367
Update .github/workflows/avm.platform.publish.tag.yml
AlexanderSehr Dec 1, 2023
817ca3f
Update .github/workflows/avm.platform.publish.tag.yml
AlexanderSehr Dec 1, 2023
06bcda3
Merge branch 'Azure:main' into main
AlexanderSehr Dec 1, 2023
0858beb
Merge branch 'Azure:main' into main
AlexanderSehr Dec 1, 2023
72b5fbb
Merge branch 'Azure:main' into main
AlexanderSehr Dec 1, 2023
917a761
TEst disable pipe
AlexanderSehr Dec 4, 2023
1b89452
Merge branch 'Azure:main' into main
AlexanderSehr Dec 4, 2023
feb981e
Update to latest
AlexanderSehr Dec 4, 2023
dda85a8
Merge branch 'Azure:main' into main
AlexanderSehr Dec 4, 2023
1543390
Resolved conflicts
AlexanderSehr Dec 6, 2023
e19a408
Merge branch 'users/alsehr/releaseFromTag' of https://github.com/Alex…
AlexanderSehr Dec 6, 2023
60007dd
Addressed feedback
AlexanderSehr Dec 6, 2023
dfe2a6f
Update to latest
AlexanderSehr Dec 6, 2023
0373f46
Merge branch 'Azure:main' into main
AlexanderSehr Dec 6, 2023
72dcc2c
Moved script
AlexanderSehr Dec 6, 2023
80247e4
Merge branch 'Azure:main' into main
AlexanderSehr Dec 9, 2023
2b5a791
Merge branch 'Azure:main' into main
AlexanderSehr Dec 10, 2023
39c5173
Merge branch 'main' into users/alsehr/releaseFromTag
AlexanderSehr Dec 10, 2023
1d3c70b
Merge branch 'main' into users/alsehr/releaseFromTag
eriqua Dec 10, 2023
a4eeb6a
Merge branch 'main' into users/alsehr/releaseFromTag
AlexanderSehr Dec 11, 2023
052c4e7
Update to latest
AlexanderSehr Dec 11, 2023
68afc1b
Merge branch 'main' into users/alsehr/releaseFromTag
AlexanderSehr Dec 11, 2023
f73a97f
Update to latest
AlexanderSehr Dec 11, 2023
3395117
Update to latest
AlexanderSehr Dec 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/actions/templates/avm-publishModule/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ runs:
# Load used functions
. (Join-Path $env:GITHUB_WORKSPACE 'avm' 'utilities' 'pipelines' 'publish' 'Publish-ModuleFromPathToPBR.ps1')

################################
## Get modules to publish ##
################################
$functionInput = @{
TemplateFilePath = Join-Path $env:GITHUB_WORKSPACE "${{ inputs.templateFilePath }}"
PublicRegistryServer = ConvertTo-SecureString '${{ env.PUBLISH_REGISTRY_SERVER }}' -AsPlainText -Force
Expand All @@ -67,7 +64,6 @@ runs:
Write-Verbose "Invoke function with" -Verbose
Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose

# Get the modified child resources
Publish-ModuleFromPathToPBR @functionInput -Verbose

Write-Output '::endgroup::'
Expand Down
63 changes: 63 additions & 0 deletions .github/workflows/avm.platform.publish.tag.yml
AlexanderSehr marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: "avm.platform.publish-tag"

on:
workflow_dispatch:
inputs:
tag:
description: "The git tag of the module to publish."
eriqua marked this conversation as resolved.
Show resolved Hide resolved
required: true
type: string

permissions:
id-token: write
contents: read

jobs:
job_publish_module_with_tag:
runs-on: ubuntu-latest
name: "Publish module with tag"
steps:
- name: Checkout tag
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.tag }}

- name: Log in to Azure
uses: azure/login@v1
with:
client-id: ${{ env.PUBLISH_CLIENT_ID }}
tenant-id: ${{ env.PUBLISH_TENANT_ID }}
subscription-id: ${{ env.PUBLISH_SUBSCRIPTION_ID }}

# Adding a step to explicitly install the latest Bicep CLI because there is
# always a delay in updating Bicep CLI in the job runner environments.
- name: Install the latest Bicep CLI
shell: bash
run: |
curl -Lo bicep https://github.com/Azure/bicep/releases/latest/download/bicep-linux-x64
chmod +x ./bicep
sudo mv ./bicep /usr/local/bin/bicep
bicep --version

- name: "Publish tagged module to public bicep registry"
uses: azure/powershell@v1
with:
azPSVersion: "latest"
inlineScript: |
# Grouping task logs
Write-Output '::group::Publish tagged module to public bicep registry'

# Load used functions
. (Join-Path $env:GITHUB_WORKSPACE 'avm' 'utilities' 'pipelines' 'publish' 'Publish-ModuleFromTagToPBR.ps1')
eriqua marked this conversation as resolved.
Show resolved Hide resolved

$functionInput = @{
ModuleReleaseTagName = '${{ github.event.inputs.tag }}'
PublicRegistryServer = ConvertTo-SecureString '${{ secrets.PUBLISH_REGISTRY_SERVER }}' -AsPlainText -Force
}

Write-Verbose "Invoke function with" -Verbose
Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose

Publish-ModuleFromTagToPBR @functionInput -Verbose

Write-Output '::endgroup::'
72 changes: 34 additions & 38 deletions avm/utilities/pipelines/publish/Publish-ModuleFromTagToPBR.ps1
Original file line number Diff line number Diff line change
@@ -1,66 +1,62 @@
<#
.SYNOPSIS
Publish a module based on the provided git tag

.DESCRIPTION
Publish a module based on the provided git tag

.PARAMETER ModuleReleaseTagName
Mandatory. The git tag to identify the module with & publish its code state of

.PARAMETER PublicRegistryServer
Mandatory. The public registry server.

.EXAMPLE
Publish-ModuleFromTagToPBR -ModuleReleaseTagName 'avm/res/key-vault/vault/0.3.0' -PublicRegistryServer (ConvertTo-SecureString 'myServer' -AsPlainText -Force)

Publish the module 'avm/res/key-vault/vault' of git tag 'avm/res/key-vault/vault/0.3.0' to the public registry server 'myServer'
#>
function Publish-ModuleFromTagToPBR {

[CmdletBinding()]
[CmdletBinding(SupportsShouldProcess)]
param (
[Parameter(Mandatory = $true)]
[Parameter(Mandatory)]
[string] $ModuleReleaseTagName,

[Parameter(Mandatory = $true)]
[Parameter(Mandatory)]
[secureString] $PublicRegistryServer
)

# Load used functions
. (Join-Path $PSScriptRoot 'helper' 'Get-BRMRepositoryName.ps1')
. (Join-Path $PSScriptRoot 'helper' 'Get-ModuleReadmeLink.ps1')
. (Join-Path (Split-Path $PSScriptRoot -Parent) 'sharedScripts' 'tokenReplacement' 'Convert-TokensInFileList.ps1')

# TODO: Diff in between tag & tag^-1 to find modules to publish?

# 1. Find tag as per function input
$repositoryRoot = (Get-Item $PSScriptRoot).Parent.Parent.Parent.Parent.Parent
$repositoryRoot = (Get-Item $PSScriptRoot).Parent.Parent.Parent.Parent.Parent.FullName
eriqua marked this conversation as resolved.
Show resolved Hide resolved
$targetVersion = Split-Path $ModuleReleaseTagName -Leaf
$moduleRelativeFolderPath = $ModuleReleaseTagName -replace "\/$targetVersion$", ''
$moduleFolderPath = Join-Path $repositoryRoot $moduleRelativeFolderPath
$moduleJsonFilePath = Join-Path $moduleFolderPath 'main.json'
Write-Verbose "Determined JSON template Path [$moduleJsonFilePath]"


# 2. Get Target Published Module Name
$publishedModuleName = Get-BRMRepositoryName -TemplateFilePath $moduleJsonFilePath

# 3. Get the documentation link
$documentationUri = Get-ModuleReadmeLink -TagName $ModuleReleaseTagName -ModuleRelativeFolderPath $moduleRelativeFolderPath

# 4. Replace telemetry version value (in JSON)
$tokenConfiguration = @{
FilePathList = @($moduleJsonFilePath)
AbsoluteTokens = @{
'-..--..-' = $targetVersion
}
}
$null = Convert-TokensInFileList @tokenConfiguration

# Double-check that tokens are correctly replaced
$templateContent = Get-Content -Path $moduleJsonFilePath
$incorrectLines = @()
for ($index = 0; $index -lt $templateContent.Count; $index++) {
if ($templateContent[$index] -match '-..--..-') {
$incorrectLines += ('You have the token [{0}] in line [{1}] of file [{2}]. Please seek advice from the AVM team.' -f $matches[0], ($index + 1), $moduleJsonFilePath)
}
}
if ($incorrectLines) {
throw ($incorrectLines | ConvertTo-Json)
}
# 2. Get the documentation link
$documentationUri = Get-ModuleReadmeLink -TagName $ModuleReleaseTagName -ModuleFolderPath $moduleFolderPath
Write-Verbose "Determined documentation URI [$documentationUri]"

###################
## 5. Publish ##
## 3. Publish ##
###################
$plainPublicRegistryServer = ConvertFrom-SecureString $PublicRegistryServer -AsPlainText

$publishInput = @(
$moduleJsonFilePath
'--target', ("br:{0}/public/bicep/{1}:{2}" -f $plainPublicRegistryServer, $publishedModuleName, $targetVersion)
'--target', ("br:{0}/public/bicep/{1}:{2}" -f $plainPublicRegistryServer, $moduleRelativeFolderPath, $targetVersion)
'--documentationUri', $documentationUri
'--force'
)
# bicep publish @publishInput

Write-Verbose "Publish Input:`n $($publishInput | ConvertTo-Json -Depth 10)" -Verbose

if ($PSCmdlet.ShouldProcess("Module of tag [$ModuleReleaseTagName]", "Publish")) {
bicep publish @publishInput
}
}