From 4aa78c89b0c0c3a54c38d2815dfae789239db8b7 Mon Sep 17 00:00:00 2001 From: Maria Zhelezova <43066499+mazhelez@users.noreply.github.com> Date: Tue, 12 Dec 2023 08:37:39 +0100 Subject: [PATCH] Calculate BaselineWorkflowRunId as part of "Determine Projects To Build" Action (#850) --- .../DetermineBaselineWorkflowRun.ps1 | 15 --------- .../DetermineBaselineWorkflowRun/README.md | 23 ------------- .../DetermineBaselineWorkflowRun/action.yaml | 33 ------------------- .../DetermineProjectsToBuild.Action.ps1 | 10 ++++++ Actions/DetermineProjectsToBuild/README.md | 1 + Actions/DetermineProjectsToBuild/action.yaml | 3 ++ Actions/Github-Helper.psm1 | 14 ++++---- .../.github/workflows/PullRequestHandler.yaml | 11 ++----- .../.github/workflows/_BuildALGoProject.yaml | 2 +- .../.github/workflows/PullRequestHandler.yaml | 11 ++----- .../.github/workflows/_BuildALGoProject.yaml | 2 +- 11 files changed, 27 insertions(+), 98 deletions(-) delete mode 100644 Actions/DetermineBaselineWorkflowRun/DetermineBaselineWorkflowRun.ps1 delete mode 100644 Actions/DetermineBaselineWorkflowRun/README.md delete mode 100644 Actions/DetermineBaselineWorkflowRun/action.yaml diff --git a/Actions/DetermineBaselineWorkflowRun/DetermineBaselineWorkflowRun.ps1 b/Actions/DetermineBaselineWorkflowRun/DetermineBaselineWorkflowRun.ps1 deleted file mode 100644 index 3968ac5ac..000000000 --- a/Actions/DetermineBaselineWorkflowRun/DetermineBaselineWorkflowRun.ps1 +++ /dev/null @@ -1,15 +0,0 @@ -Param( - [Parameter(Mandatory = $true)] - [string] $repository, - [Parameter(Mandatory = $true)] - [string] $branch, - [Parameter(Mandatory = $true)] - [string] $token -) - -Import-Module (Join-Path $PSScriptRoot '..\Github-Helper.psm1' -Resolve) - -$workflowRunID = FindLatestSuccessfulCICDRun -token $token -repository $repository -branch $branch - -# Set output variables -Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "WorkflowRunID=$workflowRunID" \ No newline at end of file diff --git a/Actions/DetermineBaselineWorkflowRun/README.md b/Actions/DetermineBaselineWorkflowRun/README.md deleted file mode 100644 index c8d9900d3..000000000 --- a/Actions/DetermineBaselineWorkflowRun/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# Determine Baseline Workflow Run -Finds the latest CICD workflow run that completed and built all the AL-Go projects successfully. -This workflow run is to be used as a baseline for all the build jobs in the current workflow run in case incremental build is required. - -## INPUT - -### ENV variables -none - -### Parameters -| Name | Required | Description | Default value | -| :-- | :-: | :-- | :-- | -| shell | | The shell (powershell or pwsh) in which the PowerShell script in this action should run | powershell | - -## OUTPUT - -### ENV variables -none - -### OUTPUT variables -| Name | Description | -| :-- | :-- | -| BaselineWorkflowRunId | The workflow run ID to use as a baseline. 0, if no baseline CICD was found. diff --git a/Actions/DetermineBaselineWorkflowRun/action.yaml b/Actions/DetermineBaselineWorkflowRun/action.yaml deleted file mode 100644 index 073018169..000000000 --- a/Actions/DetermineBaselineWorkflowRun/action.yaml +++ /dev/null @@ -1,33 +0,0 @@ -name: Determine Baseline Workflow Run -author: Microsoft Corporation -inputs: - shell: - description: Shell in which you want to run the action (powershell or pwsh) - required: false - default: powershell -outputs: - BaselineWorkflowRunId: - description: The ID of the baseline workflow run - value: ${{ steps.determineBaselineWorkflowRun.outputs.WorkflowRunID }} -runs: - using: composite - steps: - - name: Determine Projects to Build - shell: ${{ inputs.shell }} - id: determineBaselineWorkflowRun - env: - _gitHubToken: ${{ github.token }} - _branch: ${{ github.base_ref }} - _repository: ${{ github.repository }} - run: | - $errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0 - try { - ${{ github.action_path }}/DetermineBaselineWorkflowRun.ps1 -branch $env:_branch -repository $env:_repository -token $env:_gitHubToken - } - catch { - Write-Host "::ERROR::Unexpected error when running action. Error Message: $($_.Exception.Message.Replace("`r",'').Replace("`n",' ')), StackTrace: $($_.ScriptStackTrace.Replace("`r",'').Replace("`n",' <- '))"; - exit 1 - } -branding: - icon: terminal - color: blue diff --git a/Actions/DetermineProjectsToBuild/DetermineProjectsToBuild.Action.ps1 b/Actions/DetermineProjectsToBuild/DetermineProjectsToBuild.Action.ps1 index 51141a2e7..ca0a6135f 100644 --- a/Actions/DetermineProjectsToBuild/DetermineProjectsToBuild.Action.ps1 +++ b/Actions/DetermineProjectsToBuild/DetermineProjectsToBuild.Action.ps1 @@ -32,6 +32,13 @@ try { $buildAllProjects = Get-BuildAllProjects -modifiedFiles $modifiedFiles -baseFolder $baseFolder Write-Host "::endgroup::" + Write-Host "::group::Determine Baseline Workflow ID" + $baselineWorkflowRunId = 0 #default to 0, which means no baseline workflow run ID is set + if(-not $buildAllProjects) { + $baselineWorkflowRunId = FindLatestSuccessfulCICDRun -repository "$env:GITHUB_REPOSITORY" -branch "$env:GITHUB_BASE_REF" -token $token + } + Write-Host "::endgroup::" + Write-Host "::group::Get Projects To Build" $allProjects, $projectsToBuild, $projectDependencies, $buildOrder = Get-ProjectsToBuild -baseFolder $baseFolder -buildAllProjects $buildAllProjects -modifiedFiles $modifiedFiles -maxBuildDepth $maxBuildDepth AddTelemetryProperty -telemetryScope $telemetryScope -key "projects" -value "$($allProjects -join ', ')" @@ -48,11 +55,14 @@ try { Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "ProjectDependenciesJson=$projectDependenciesJson" Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "BuildOrderJson=$buildOrderJson" Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "BuildAllProjects=$([int] $buildAllProjects)" + Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "BaselineWorkflowRunId=$baselineWorkflowRunId" + Write-Host "ProjectsJson=$projectsJson" Write-Host "ProjectDependenciesJson=$projectDependenciesJson" Write-Host "BuildOrderJson=$buildOrderJson" Write-Host "BuildAllProjects=$buildAllProjects" + Write-Host "BaselineWorkflowRunId=$baselineWorkflowRunId" #endregion TrackTrace -telemetryScope $telemetryScope diff --git a/Actions/DetermineProjectsToBuild/README.md b/Actions/DetermineProjectsToBuild/README.md index ee436f35c..b24526642 100644 --- a/Actions/DetermineProjectsToBuild/README.md +++ b/Actions/DetermineProjectsToBuild/README.md @@ -27,3 +27,4 @@ none | ProjectDependenciesJson | An object that holds the project dependencies in compressed JSON format | | BuildOrderJson | An array of objects that determine that build order, including build dimensions | | BuildAllProjects | A flag that indicates whether to build all projects or only the modified ones | +| BaselineWorkflowRunId | The ID of the workflow run from where to fetch artifacts in case when not all projects are built | diff --git a/Actions/DetermineProjectsToBuild/action.yaml b/Actions/DetermineProjectsToBuild/action.yaml index 6f02de1c3..be7e770f9 100644 --- a/Actions/DetermineProjectsToBuild/action.yaml +++ b/Actions/DetermineProjectsToBuild/action.yaml @@ -27,6 +27,9 @@ outputs: BuildAllProjects: description: A flag that indicates whether to build all projects or only the modified ones value: ${{ steps.determineProjectsToBuild.outputs.BuildAllProjects }} + BaselineWorkflowRunId: + description: The ID of the workflow run from where to fetch artifacts in case when not all projects are built + value: ${{ steps.determineProjectsToBuild.outputs.BaselineWorkflowRunId }} runs: using: composite steps: diff --git a/Actions/Github-Helper.psm1 b/Actions/Github-Helper.psm1 index 06762ec02..f75aa674e 100644 --- a/Actions/Github-Helper.psm1 +++ b/Actions/Github-Helper.psm1 @@ -933,7 +933,7 @@ function GetArtifacts { [Parameter(Mandatory = $true)] [string] $version, [Parameter(Mandatory = $false)] - [string] $baselineWorkflowID = 'none' + [string] $baselineWorkflowID ) $headers = GetHeader -token $token @@ -941,14 +941,14 @@ function GetArtifacts { # For latest version, use the artifacts from the last successful CICD run if($version -eq '*') { - if($baselineWorkflowID -eq '0' -or $baselineWorkflowID -eq '') { - # If the baseline workflow ID is 0 or empty, it means that there is no baseline workflow ID - return @() + if($baselineWorkflowID -eq '') { + # If the baseline workflow ID is empty, it means that we need to find the latest successful CICD run + $baselineWorkflowID = FindLatestSuccessfulCICDRun -repository $repository -branch $branch -token $token } - if($baselineWorkflowID -eq 'none') { - # If the baseline workflow ID is 'none', it means that we need to find the latest successful CICD run - $baselineWorkflowID = FindLatestSuccessfulCICDRun -repository $repository -branch $branch -token $token + if($baselineWorkflowID -eq '0') { + # If the baseline workflow ID is 0, it means that there is no baseline workflow ID + return @() } $result = GetArtifactsFromWorkflowRun -workflowRun $baselineWorkflowID -token $token -api_url $api_url -repository $repository -mask $mask -projects $projects diff --git a/Templates/AppSource App/.github/workflows/PullRequestHandler.yaml b/Templates/AppSource App/.github/workflows/PullRequestHandler.yaml index c2dd74ec9..0200d1aaa 100644 --- a/Templates/AppSource App/.github/workflows/PullRequestHandler.yaml +++ b/Templates/AppSource App/.github/workflows/PullRequestHandler.yaml @@ -40,8 +40,8 @@ jobs: projects: ${{ steps.determineProjectsToBuild.outputs.ProjectsJson }} projectDependenciesJson: ${{ steps.determineProjectsToBuild.outputs.ProjectDependenciesJson }} buildOrderJson: ${{ steps.determineProjectsToBuild.outputs.BuildOrderJson }} + baselineWorkflowRunId: ${{ steps.determineProjectsToBuild.outputs.BaselineWorkflowRunId }} workflowDepth: ${{ steps.DetermineWorkflowDepth.outputs.WorkflowDepth }} - baselineWorkflowRunId: ${{ steps.DetermineBaselineWorkflowRun.outputs.BaselineWorkflowRunId }} steps: - name: Dump Workflow Information uses: microsoft/AL-Go-Actions/DumpWorkflowInfo@main @@ -79,13 +79,6 @@ jobs: shell: powershell maxBuildDepth: ${{ env.workflowDepth }} - - name: Determine Baseline Workflow Run - id: DetermineBaselineWorkflowRun - if: steps.determineProjectsToBuild.outputs.BuildAllProjects == '0' - uses: microsoft/AL-Go-Actions/DetermineBaselineWorkflowRun@main - with: - shell: powershell - Build: needs: [ Initialization ] if: (!failure()) && (!cancelled()) && fromJson(needs.Initialization.outputs.buildOrderJson)[0].projectsCount > 0 @@ -105,7 +98,7 @@ jobs: projectName: ${{ matrix.projectName }} buildMode: ${{ matrix.buildMode }} projectDependenciesJson: ${{ needs.Initialization.outputs.projectDependenciesJson }} - baselineWorkflowRunId: '${{ needs.Initialization.outputs.baselineWorkflowRunId }}' + baselineWorkflowRunId: ${{ needs.Initialization.outputs.baselineWorkflowRunId }} secrets: 'licenseFileUrl,keyVaultCertificateUrl,*keyVaultCertificatePassword,keyVaultClientId,gitHubPackagesContext,applicationInsightsConnectionString' publishThisBuildArtifacts: ${{ needs.Initialization.outputs.workflowDepth > 1 }} artifactsNameSuffix: 'PR${{ github.event.number }}' diff --git a/Templates/AppSource App/.github/workflows/_BuildALGoProject.yaml b/Templates/AppSource App/.github/workflows/_BuildALGoProject.yaml index ae55e47aa..c9e7c4737 100644 --- a/Templates/AppSource App/.github/workflows/_BuildALGoProject.yaml +++ b/Templates/AppSource App/.github/workflows/_BuildALGoProject.yaml @@ -39,7 +39,7 @@ on: baselineWorkflowRunId: description: ID of the baseline workflow run, from where to download the current project dependencies, in case they are not built in the current workflow run required: false - default: 'none' + default: '0' type: string secrets: description: A comma-separated string with the names of the secrets, required for the workflow. diff --git a/Templates/Per Tenant Extension/.github/workflows/PullRequestHandler.yaml b/Templates/Per Tenant Extension/.github/workflows/PullRequestHandler.yaml index c2dd74ec9..0200d1aaa 100644 --- a/Templates/Per Tenant Extension/.github/workflows/PullRequestHandler.yaml +++ b/Templates/Per Tenant Extension/.github/workflows/PullRequestHandler.yaml @@ -40,8 +40,8 @@ jobs: projects: ${{ steps.determineProjectsToBuild.outputs.ProjectsJson }} projectDependenciesJson: ${{ steps.determineProjectsToBuild.outputs.ProjectDependenciesJson }} buildOrderJson: ${{ steps.determineProjectsToBuild.outputs.BuildOrderJson }} + baselineWorkflowRunId: ${{ steps.determineProjectsToBuild.outputs.BaselineWorkflowRunId }} workflowDepth: ${{ steps.DetermineWorkflowDepth.outputs.WorkflowDepth }} - baselineWorkflowRunId: ${{ steps.DetermineBaselineWorkflowRun.outputs.BaselineWorkflowRunId }} steps: - name: Dump Workflow Information uses: microsoft/AL-Go-Actions/DumpWorkflowInfo@main @@ -79,13 +79,6 @@ jobs: shell: powershell maxBuildDepth: ${{ env.workflowDepth }} - - name: Determine Baseline Workflow Run - id: DetermineBaselineWorkflowRun - if: steps.determineProjectsToBuild.outputs.BuildAllProjects == '0' - uses: microsoft/AL-Go-Actions/DetermineBaselineWorkflowRun@main - with: - shell: powershell - Build: needs: [ Initialization ] if: (!failure()) && (!cancelled()) && fromJson(needs.Initialization.outputs.buildOrderJson)[0].projectsCount > 0 @@ -105,7 +98,7 @@ jobs: projectName: ${{ matrix.projectName }} buildMode: ${{ matrix.buildMode }} projectDependenciesJson: ${{ needs.Initialization.outputs.projectDependenciesJson }} - baselineWorkflowRunId: '${{ needs.Initialization.outputs.baselineWorkflowRunId }}' + baselineWorkflowRunId: ${{ needs.Initialization.outputs.baselineWorkflowRunId }} secrets: 'licenseFileUrl,keyVaultCertificateUrl,*keyVaultCertificatePassword,keyVaultClientId,gitHubPackagesContext,applicationInsightsConnectionString' publishThisBuildArtifacts: ${{ needs.Initialization.outputs.workflowDepth > 1 }} artifactsNameSuffix: 'PR${{ github.event.number }}' diff --git a/Templates/Per Tenant Extension/.github/workflows/_BuildALGoProject.yaml b/Templates/Per Tenant Extension/.github/workflows/_BuildALGoProject.yaml index ae55e47aa..c9e7c4737 100644 --- a/Templates/Per Tenant Extension/.github/workflows/_BuildALGoProject.yaml +++ b/Templates/Per Tenant Extension/.github/workflows/_BuildALGoProject.yaml @@ -39,7 +39,7 @@ on: baselineWorkflowRunId: description: ID of the baseline workflow run, from where to download the current project dependencies, in case they are not built in the current workflow run required: false - default: 'none' + default: '0' type: string secrets: description: A comma-separated string with the names of the secrets, required for the workflow.