diff --git a/Actions/CalculateArtifactNames/CalculateArtifactNames.ps1 b/Actions/CalculateArtifactNames/CalculateArtifactNames.ps1 index f0478b3b4..8b82d9e5d 100644 --- a/Actions/CalculateArtifactNames/CalculateArtifactNames.ps1 +++ b/Actions/CalculateArtifactNames/CalculateArtifactNames.ps1 @@ -3,8 +3,6 @@ [string] $project, [Parameter(HelpMessage = "Build mode used when building the artifacts", Mandatory = $true)] [string] $buildMode, - [Parameter(HelpMessage = "Name of the branch the workflow is running on", Mandatory = $true)] - [string] $branchName, [Parameter(HelpMessage = "Suffix to add to the artifacts names", Mandatory = $false)] [string] $suffix ) @@ -20,6 +18,12 @@ if ($project -eq ".") { $project = $settings.repoName } +$branchName = $ENV:GITHUB_HEAD_REF +# $ENV:GITHUB_HEAD_REF is specified only for pull requests, so if it is not specified, use GITHUB_REF_NAME +if (!$branchName) { + $branchName = $ENV:GITHUB_REF_NAME +} + $branchName = $branchName.Replace('\', '_').Replace('/', '_') $projectName = $project.Replace('\', '_').Replace('/', '_') diff --git a/Actions/CalculateArtifactNames/README.md b/Actions/CalculateArtifactNames/README.md index 637b31f09..050d6e990 100644 --- a/Actions/CalculateArtifactNames/README.md +++ b/Actions/CalculateArtifactNames/README.md @@ -14,7 +14,6 @@ Calculate Artifact Names for AL-Go workflows | shell | | The shell (powershell or pwsh) in which the PowerShell script in this action should run | powershell | | project | Yes | Name of the built project or . if the repository is setup for single project | | | buildMode | Yes |Build mode used when building the artifacts | | -| branchName | Yes | Name of the branch the workflow is running on | | | suffix | | A suffix to add to artifacts names. **Note:** if a suffix is specified, the current date will be added extra | Build version | ## OUTPUT diff --git a/Actions/CalculateArtifactNames/action.yaml b/Actions/CalculateArtifactNames/action.yaml index beeaf5c6c..dc9c49bab 100644 --- a/Actions/CalculateArtifactNames/action.yaml +++ b/Actions/CalculateArtifactNames/action.yaml @@ -11,9 +11,6 @@ inputs: buildMode: description: Build mode used when building the artifacts required: true - branchName: - description: Name of the branch the workflow is running on - required: true suffix: description: Suffix to add to the artifacts names required: false @@ -58,12 +55,11 @@ runs: env: _project: ${{ inputs.project }} _buildMode: ${{ inputs.buildMode }} - _branchName: ${{ inputs.branchName }} _suffix: ${{ inputs.suffix }} run: | $errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0 try { - ${{ github.action_path }}/CalculateArtifactNames.ps1 -project $ENV:_project -buildMode $ENV:_buildMode -branchName $ENV:_branchName -suffix $ENV:_suffix + ${{ github.action_path }}/CalculateArtifactNames.ps1 -project $ENV:_project -buildMode $ENV:_buildMode -suffix $ENV:_suffix } catch { Write-Host "::ERROR::Unexpected error when running action. Error Message: $($_.Exception.Message.Replace("`r",'').Replace("`n",' ')), StackTrace: $($_.ScriptStackTrace.Replace("`r",'').Replace("`n",' <- '))"; diff --git a/Actions/DownloadProjectDependencies/DownloadProjectDependencies.Action.ps1 b/Actions/DownloadProjectDependencies/DownloadProjectDependencies.Action.ps1 index d7ab34b4b..81ee9a021 100644 --- a/Actions/DownloadProjectDependencies/DownloadProjectDependencies.Action.ps1 +++ b/Actions/DownloadProjectDependencies/DownloadProjectDependencies.Action.ps1 @@ -40,12 +40,16 @@ function DownloadDependenciesFromCurrentBuild($baseFolder, $project, $projectsDe $dependencyBuildMode = 'Default'; } - $currentBranch = $ENV:GITHUB_REF_NAME + $headBranch = $ENV:GITHUB_HEAD_REF + # $ENV:GITHUB_HEAD_REF is specified only for pull requests, so if it is not specified, use GITHUB_REF_NAME + if (!$headBranch) { + $headBranch = $ENV:GITHUB_REF_NAME + } - $baseBranch = $ENV:GITHUB_BASE_REF_NAME - # $ENV:GITHUB_BASE_REF_NAME is specified only for pull requests, so if it is not specified, use the current branch + $baseBranch = $ENV:GITHUB_BASE_REF + # $ENV:GITHUB_BASE_REF is specified only for pull requests, so if it is not specified, use GITHUB_REF_NAME if (!$baseBranch) { - $baseBranch = $currentBranch + $baseBranch = $ENV:GITHUB_REF_NAME } $dependeciesProbingPaths += @(@{ @@ -54,7 +58,7 @@ function DownloadDependenciesFromCurrentBuild($baseFolder, $project, $projectsDe "buildMode" = $dependencyBuildMode "projects" = $dependencyProject "repo" = "$ENV:GITHUB_SERVER_URL/$ENV:GITHUB_REPOSITORY" - "branch" = $currentBranch + "branch" = $headBranch "baseBranch" = $baseBranch "authTokenSecret" = $token }) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index b15b6d3c3..90e2266dd 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -13,6 +13,7 @@ AL-Go for GitHub allows you to build and test using insider builds without any e - Issue 739 Workflow specific KeyVault settings doesn't work for localDevEnv - Using self-hosted runners while using Azure KeyVault for secrets or signing might fail with C:\Modules doesn't exist - PullRequestHandler wasn't triggered if only .md files where changes. This lead to PRs which couldn't be merged if a PR status check was mandatory. +- Artifacts names for PR Builds were using the merge branch instead of the head branch. ### New Settings - `enableExternalRulesets`: set this setting to true if you want to allow AL-Go to automatically download external references in rulesets. diff --git a/Templates/AppSource App/.github/workflows/_BuildALGoProject.yaml b/Templates/AppSource App/.github/workflows/_BuildALGoProject.yaml index d8f26e906..da153af1f 100644 --- a/Templates/AppSource App/.github/workflows/_BuildALGoProject.yaml +++ b/Templates/AppSource App/.github/workflows/_BuildALGoProject.yaml @@ -161,7 +161,6 @@ jobs: shell: ${{ inputs.shell }} project: ${{ inputs.project }} buildMode: ${{ inputs.buildMode }} - branchName: ${{ github.ref_name }} suffix: ${{ inputs.artifactsNameSuffix }} - name: Upload thisbuild artifacts - apps diff --git a/Templates/Per Tenant Extension/.github/workflows/_BuildALGoProject.yaml b/Templates/Per Tenant Extension/.github/workflows/_BuildALGoProject.yaml index d8f26e906..da153af1f 100644 --- a/Templates/Per Tenant Extension/.github/workflows/_BuildALGoProject.yaml +++ b/Templates/Per Tenant Extension/.github/workflows/_BuildALGoProject.yaml @@ -161,7 +161,6 @@ jobs: shell: ${{ inputs.shell }} project: ${{ inputs.project }} buildMode: ${{ inputs.buildMode }} - branchName: ${{ github.ref_name }} suffix: ${{ inputs.artifactsNameSuffix }} - name: Upload thisbuild artifacts - apps diff --git a/Tests/CalculateArtifactNames.Test.ps1 b/Tests/CalculateArtifactNames.Test.ps1 index f23e7b394..95376866b 100644 --- a/Tests/CalculateArtifactNames.Test.ps1 +++ b/Tests/CalculateArtifactNames.Test.ps1 @@ -28,11 +28,10 @@ Describe 'CalculateArtifactNames Action Tests' { It 'should include buildmode name in artifact name if buildmode is not default' { $buildMode = "Clean" - $branchName = "main" + $env:GITHUB_HEAD_REF = "main" & $scriptPath ` -project $project ` - -buildMode $buildMode ` - -branchName $branchName + -buildMode $buildMode $generatedOutPut = Get-Content $env:GITHUB_OUTPUT -Encoding UTF8 $generatedOutPut | Should -Contain "ThisBuildAppsArtifactsName=thisbuild-ALGOProject-CleanApps" @@ -50,11 +49,10 @@ Describe 'CalculateArtifactNames Action Tests' { It 'should not include buildmode name in artifact name if buildmode is default' { $buildMode = "Default" - $branchName = "main" + $env:GITHUB_HEAD_REF = "main" & $scriptPath ` -project $project ` - -buildMode $buildMode ` - -branchName $branchName + -buildMode $buildMode $generatedOutPut = Get-Content $env:GITHUB_OUTPUT -Encoding UTF8 $generatedOutPut | Should -Contain "ThisBuildAppsArtifactsName=thisbuild-ALGOProject-Apps" @@ -70,11 +68,10 @@ Describe 'CalculateArtifactNames Action Tests' { It 'should escape slashes and backslashes in artifact name' { $buildMode = "Default" - $branchName = "releases/1.0" + $env:GITHUB_HEAD_REF = "releases/1.0" & $scriptPath ` -project $project ` - -buildMode $buildMode ` - -branchName $branchName + -buildMode $buildMode $generatedOutPut = Get-Content $env:GITHUB_OUTPUT -Encoding UTF8 $generatedOutPut | Should -Contain "ThisBuildAppsArtifactsName=thisbuild-ALGOProject-Apps" @@ -90,12 +87,11 @@ Describe 'CalculateArtifactNames Action Tests' { It 'should use the specified suffix if provided' { $buildMode = "Default" - $branchName = "releases/1.0" + $env:GITHUB_HEAD_REF = "releases/1.0" $suffix = "Current" & $scriptPath ` -project $project ` -buildMode $buildMode ` - -branchName $branchName ` -suffix $suffix # In rare cases, when this test is run at the end of the day, the date will change between the time the script is run and the time the test is run. @@ -117,12 +113,11 @@ Describe 'CalculateArtifactNames Action Tests' { It 'handles special characters in project name' { $project = "ALGOProject_øåæ" $buildMode = "Default" - $branchName = "releases/1.0" + $env:GITHUB_HEAD_REF = "releases/1.0" $suffix = "Current" & $scriptPath ` -project $project ` -buildMode $buildMode ` - -branchName $branchName ` -suffix $suffix # In rare cases, when this test is run at the end of the day, the date will change between the time the script is run and the time the test is run.