Skip to content

Commit

Permalink
Calculate BaselineWorkflowRunId as part of "Determine Projects To Bui…
Browse files Browse the repository at this point in the history
…ld" Action (#850)
  • Loading branch information
mazhelez authored Dec 12, 2023
1 parent 1753468 commit 4aa78c8
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 98 deletions.

This file was deleted.

23 changes: 0 additions & 23 deletions Actions/DetermineBaselineWorkflowRun/README.md

This file was deleted.

33 changes: 0 additions & 33 deletions Actions/DetermineBaselineWorkflowRun/action.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 ', ')"
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions Actions/DetermineProjectsToBuild/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
3 changes: 3 additions & 0 deletions Actions/DetermineProjectsToBuild/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions Actions/Github-Helper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -933,22 +933,22 @@ function GetArtifacts {
[Parameter(Mandatory = $true)]
[string] $version,
[Parameter(Mandatory = $false)]
[string] $baselineWorkflowID = 'none'
[string] $baselineWorkflowID
)

$headers = GetHeader -token $token
if ($version -eq 'latest') { $version = '*' }

# 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 }}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 }}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 4aa78c8

Please sign in to comment.