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

Support release branches that start with "releases/" #877

Merged
merged 19 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function ModifyCICDWorkflow {
}
# update the branches: line with the new branches
if ($CICDPushBranches) {
$yaml.Replace('on:/push:/branches:', "branches: [ '$($cicdPushBranches -join "', '")' ]")
$yaml.Replace('on:/push:/branches:', "branches: [ '$($CICDPushBranches -join "', '")' ]")
}
else {
$yaml.Replace('on:/push:',@())
Expand Down
14 changes: 7 additions & 7 deletions Actions/CreateReleaseNotes/CreateReleaseNotes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ try {
# Check that tag is SemVer
$SemVerObj = SemVerStrToSemVerObj -semVerStr $tag_name

# Calculate release branch
$releaseBranch = "release/$($SemVerObj.Prefix)$($SemVerObj.Major).$($SemVerObj.Minor)"
# Calculate release version
$releaseVersion = "$($SemVerObj.Prefix)$($SemVerObj.Major).$($SemVerObj.Minor)"
if ($SemVerObj.Patch -or $SemVerObj.addt0 -ne 'zzz') {
$releaseBranch += ".$($SemVerObj.Patch)"
$releaseVersion += ".$($SemVerObj.Patch)"
if ($SemVerObj.addt0 -ne 'zzz') {
$releaseBranch += "-$($SemVerObj.addt0)"
$releaseVersion += "-$($SemVerObj.addt0)"
1..4 | ForEach-Object {
if ($SemVerObj."addt$($_)" -ne 'zzz') {
$releaseBranch += ".$($SemVerObj."addt$($_)")"
$releaseVersion += ".$($SemVerObj."addt$($_)")"
}
}
}
}
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "releaseBranch=$releaseBranch"
Write-Host "releaseBranch=$releaseBranch"
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "releaseVersion=$releaseVersion"
Write-Host "releaseVersion=$releaseVersion"

$latestRelease = GetLatestRelease -token $token -api_url $ENV:GITHUB_API_URL -repository $ENV:GITHUB_REPOSITORY -ref $ENV:GITHUB_REF_NAME
if ($latestRelease -and $latestRelease.PSobject.Properties.name -eq "target_commitish") {
Expand Down
2 changes: 1 addition & 1 deletion Actions/CreateReleaseNotes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ none
### OUTPUT variables
| Name | Description |
| :-- | :-- |
| ReleaseBranch | Name of the release branch |
| ReleaseVersion | The release version |
| ReleaseNotes | Release notes generated based on the changes |
6 changes: 3 additions & 3 deletions Actions/CreateReleaseNotes/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ inputs:
required: false
default: ''
outputs:
ReleaseBranch:
description: Name of the release branch
value: ${{ steps.createreleasenotes.outputs.ReleaseBranch }}
ReleaseVersion:
description: The release version
value: ${{ steps.createreleasenotes.outputs.releaseVersion }}
ReleaseNotes:
description: Release note generated based on the changes
value: ${{ steps.createreleasenotes.outputs.ReleaseNotes }}
Expand Down
6 changes: 4 additions & 2 deletions Actions/Github-Helper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,10 @@ function GetLatestRelease {

# Get Latest release
$latestRelease = $releases | Where-Object { -not ($_.prerelease -or $_.draft) } | Select-Object -First 1
$releaseBranchPrefix = 'release/'
if ($ref -like "$releaseBranchPrefix*") {
$releaseBranchesFormats = 'release/*', 'releases/*'
$isReleaseBranch = [boolean] $($releaseBranchesFormats | Where-Object { $ref -like $_ })

if ($isReleaseBranch) {
# If release branch, get the latest release from that the release branch
# This is given by the latest release with the same major.minor as the release branch
$semVerObj = SemVerStrToSemVerObj -semVerStr $ref.SubString($releaseBranchPrefix.Length) -allowMajorMinorOnly
Expand Down
8 changes: 7 additions & 1 deletion Actions/ReadSettings/ReadSettings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ $settings.Keys | ForEach-Object {
}
$outSettings += @{ "$setting" = $settingValue }
if ($getSettings -contains $setting) {
if ($settingValue -is [System.Collections.Specialized.OrderedDictionary] -or $settingValue -is [hashtable]) {
if ($settingValue -is [System.Collections.Specialized.OrderedDictionary] -or $settingValue -is [hashtable] -or $settingValue -is [array]) {
Add-Content -Encoding UTF8 -Path $env:GITHUB_ENV -Value "$setting=$(ConvertTo-Json $settingValue -Depth 99 -Compress)"
}
else {
Expand All @@ -66,6 +66,12 @@ $settings.Keys | ForEach-Object {
}
}

# Add default values for settings that are not set
# CICDPushBranches is not present in the settings object, although it can be set there.
if('CICDPushBranches' -in $getSettings -and 'CICDPushBranches' -notin $settings.Keys) {
mazhelez marked this conversation as resolved.
Show resolved Hide resolved
Add-Content -Encoding UTF8 -Path $env:GITHUB_ENV -Value "CICDPushBranches=$(Convert-ToJson $defaultCICDPushBranches -Depth 99 -Compress))"
}

Write-Host "SETTINGS:"
$outSettings | ConvertTo-Json -Depth 99 | Out-Host
Add-Content -Encoding UTF8 -Path $env:GITHUB_ENV -Value "Settings=$($outSettings | ConvertTo-Json -Depth 99 -Compress)"
Expand Down
27 changes: 25 additions & 2 deletions Templates/Per Tenant Extension/.github/workflows/CICD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
projectDependenciesJson: ${{ steps.determineProjectsToBuild.outputs.ProjectDependenciesJson }}
buildOrderJson: ${{ steps.determineProjectsToBuild.outputs.BuildOrderJson }}
workflowDepth: ${{ steps.DetermineWorkflowDepth.outputs.WorkflowDepth }}
publishArtifacts: ${{ steps.DeterminePublishArtifacts.outputs.PublishArtifacts }}
steps:
- name: Dump Workflow Information
uses: microsoft/AL-Go-Actions/DumpWorkflowInfo@main
Expand All @@ -63,7 +64,7 @@ jobs:
uses: microsoft/AL-Go-Actions/ReadSettings@main
with:
shell: powershell
get: type
get: type, CICDPushBranches
mazhelez marked this conversation as resolved.
Show resolved Hide resolved

- name: Determine Workflow Depth
id: DetermineWorkflowDepth
Expand Down Expand Up @@ -113,6 +114,28 @@ jobs:
getEnvironments: '*'
type: 'CD'

- name: Determine Publish Artifacts
id: DeterminePublishArtifacts
run: |
$publishArtifacts = $false
mazhelez marked this conversation as resolved.
Show resolved Hide resolved
$pushBranches = $env:CICDPushBranches | ConvertFrom-Json
$currentBranch = $env:GITHUB_REF_NAME

Write-Host "Current branch: $currentBranch"

foreach($pushBranch in $pushBranches) {
if($currentBranch -like $pushBranch) {
$publishArtifacts = $true
break
}
}
$deliveryTargets = "${{ steps.DetermineDeliveryTargets.outputs.DeliveryTargetsJson }}" | ConvertFrom-Json
$environmentCount = ${{ steps.DetermineDeploymentEnvironments.outputs.EnvironmentCount }}

$publishArtifacts = $publishArtifacts -or ($deliveryTargets.Count -gt 0) -or ($environmentCount -gt 0)
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "PublishArtifacts=$publishArtifacts"
Write-Host "PublishArtifacts=$publishArtifacts"

CheckForUpdates:
needs: [ Initialization ]
runs-on: [ windows-latest ]
Expand Down Expand Up @@ -153,7 +176,7 @@ jobs:
projectDependenciesJson: ${{ needs.Initialization.outputs.projectDependenciesJson }}
secrets: 'licenseFileUrl,codeSignCertificateUrl,*codeSignCertificatePassword,keyVaultCertificateUrl,*keyVaultCertificatePassword,keyVaultClientId,gitHubPackagesContext,applicationInsightsConnectionString'
publishThisBuildArtifacts: ${{ needs.Initialization.outputs.workflowDepth > 1 }}
publishArtifacts: ${{ github.ref_name == 'main' || startswith(github.ref_name, 'release/') || needs.Initialization.outputs.deliveryTargetsJson != '[]' || needs.Initialization.outputs.environmentCount > 0 }}
publishArtifacts: ${{ needs.Initialization.outputs.PublishArtifacts == 'True' }}
mazhelez marked this conversation as resolved.
Show resolved Hide resolved
signArtifacts: true
useArtifactCache: true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ on:
description: Create Release Branch?
type: boolean
default: false
releaseBranchPrefix:
description: The preffix for the release branch. Used only if 'Create Release Branch?' is checked.
mazhelez marked this conversation as resolved.
Show resolved Hide resolved
type: string
default: release/
updateVersionNumber:
description: New Version Number in main branch. Use Major.Minor for absolute change, use +Major.Minor for incremental change.
required: false
Expand Down Expand Up @@ -64,7 +68,7 @@ jobs:
artifacts: ${{ steps.analyzeartifacts.outputs.artifacts }}
releaseId: ${{ steps.createrelease.outputs.releaseId }}
commitish: ${{ steps.analyzeartifacts.outputs.commitish }}
releaseBranch: ${{ steps.createreleasenotes.outputs.releaseBranch }}
releaseVersion: ${{ steps.createreleasenotes.outputs.releaseVersion }}
steps:
- name: Dump Workflow Information
uses: microsoft/AL-Go-Actions/DumpWorkflowInfo@main
Expand Down Expand Up @@ -304,11 +308,13 @@ jobs:
- name: Create Release Branch
run: |
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
git checkout -b ${{ needs.CreateRelease.outputs.releaseBranch }}
$releaseBranch = '${{ github.event.inputs.releaseBranchPrefix }}${{ needs.CreateRelease.outputs.releaseVersion }}'
Write-Host "Creating release branch $releaseBranch"
git checkout -b $releaseBranch
git config user.name ${{ github.actor}}
git config user.email ${{ github.actor}}@users.noreply.github.com
git commit --allow-empty -m "Release branch ${{ needs.CreateRelease.outputs.releaseBranch }}"
git push origin ${{ needs.CreateRelease.outputs.releaseBranch }}
git commit --allow-empty -m "Release branch $releaseBranch"
git push origin $releaseBranch

UpdateVersionNumber:
needs: [ CreateRelease, UploadArtifacts ]
Expand Down
2 changes: 1 addition & 1 deletion Tests/CreateReleaseNotes.Test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Describe 'CreateReleaseNotes Tests' {
"pull-requests" = "write"
}
$outputs = [ordered]@{
"ReleaseBranch" = "Name of the release branch"
"ReleaseVersion" = "The release version"
"ReleaseNotes" = "Release note generated based on the changes"
}
YamlTest -scriptRoot $scriptRoot -actionName $actionName -actionScript $actionScript -permissions $permissions -outputs $outputs
Expand Down
Loading