Skip to content

Commit

Permalink
Allow using latest BCArtifact instead of hardcoded version (#1743)
Browse files Browse the repository at this point in the history
<!-- Thank you for submitting a Pull Request. If you're new to
contributing to BCApps please read our pull request guideline below
* https://github.com/microsoft/BCApps/Contributing.md
-->
#### Summary <!-- Provide a general summary of your changes -->

* Allow the "artifact" setting to use latest available version instead
of a hardcoded version
* Run stability jobs on all official branches 


#### Work Item(s) <!-- Add the issue number here after the #. The issue
needs to be open and approved. Submitting PRs with no linked issues or
unapproved issues is highly discouraged. -->
Fixes
[AB#543528](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/543528)
  • Loading branch information
aholstrup1 authored Aug 9, 2024
1 parent 9c4f554 commit b656871
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 12 deletions.
35 changes: 35 additions & 0 deletions .github/actions/RunAutomation/SubmitStabilityJob/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
param (
[Parameter(Mandatory=$true)]
$runParameters
)

$repository = $runParameters.Repository
$targetBranch = $runParameters.TargetBranch
$workflowName = " CI/CD"
$workflowRunTime = Get-Date -AsUTC

Write-Host "Running the workflow '$workflowName' on branch $targetBranch"
gh workflow run --repo $repository --ref $targetBranch $workflowName

# Get the workflow run URL to display in the message

while((Get-Date -AsUTC) -lt $workflowRunTime.AddMinutes(1)) {
Start-Sleep -Seconds 5 # wait for 5 seconds for the workflow to start
$workflowRun = gh run list --branch $targetBranch --event workflow_dispatch --workflow $workflowName --repo $repository --json createdAt,url --limit 1 | ConvertFrom-Json

if ($workflowRun -and ($workflowRun.createdAt -gt $workflowRunTime)) {
break
}
}


$result = @{
'Files' = @()
'Message' = "Could not start the '$workflowName' workflow. Please check the workflow status."
}

if ($workflowRun.createdAt -gt $workflowRunTime) {
$result.Message = "'$workflowName' workflow started: $($workflowRun.url)"
}

return $result
13 changes: 6 additions & 7 deletions .github/actions/RunAutomation/UpdateALGo/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ param (

$repository = $runParameters.Repository
$targetBranch = $runParameters.TargetBranch

Write-Host "Running the workflow Update AL-Go System Files on branch $targetBranch"

$workflowName = " Update AL-Go System Files"
$workflowRunTime = Get-Date
$workflowRunTime = Get-Date -AsUTC

Write-Host "Running the workflow '$workflowName' on branch $targetBranch"
gh workflow run --repo $repository --ref $targetBranch $workflowName

# Get the workflow run URL to display in the message

while((Get-Date) -lt $workflowRunTime.AddMinutes(1)) {
while((Get-Date -AsUTC) -lt $workflowRunTime.AddMinutes(1)) {
Start-Sleep -Seconds 5 # wait for 5 seconds for the workflow to start
$workflowRun = gh run list --branch $targetBranch --event workflow_dispatch --workflow $workflowName --repo $repository --json createdAt,url --limit 1 | ConvertFrom-Json

Expand All @@ -26,11 +25,11 @@ while((Get-Date) -lt $workflowRunTime.AddMinutes(1)) {

$result = @{
'Files' = @()
'Message' = "Could not start the Update AL-Go System Files workflow. Please check the workflow status."
'Message' = "Could not start the '$workflowName' workflow. Please check the workflow status."
}

if ($workflowRun.createdAt -gt $workflowRunTime) {
$result.Message = "'Update AL-Go System Files' workflow started: $($workflowRun.url)"
$result.Message = "'$workflowName' workflow started: $($workflowRun.url)"
}

return $result
41 changes: 41 additions & 0 deletions .github/workflows/SubmitStabilityJobs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Submit Stability Job On Official Branches

on:
workflow_dispatch:
schedule:
- cron: "0 04 * * *" # Run at 04:00 UTC every day

permissions: read-all

jobs:
GetBranches:
name: Get Official Branches
if: github.repository_owner == 'microsoft'
runs-on: ubuntu-latest
outputs:
officialBranches: ${{ steps.getOfficialBranches.outputs.branchesJson }}
steps:
- name: Get Official Branches
id: getOfficialBranches
uses: microsoft/BCApps/.github/actions/GetGitBranches@main
with:
include: "['releases/*']"

SubmitStabilityJobs:
name: "[${{ matrix.branch }}] Submit Stability Job"
if: github.repository_owner == 'microsoft'
runs-on: ubuntu-latest
environment: Official-Build
needs: GetBranches
strategy:
matrix:
branch: ${{ fromJson(needs.GetBranches.outputs.officialBranches) }}
fail-fast: false
steps:
- name: Submit Stability Job
env:
GH_TOKEN: ${{ secrets.GHTOKENWORKFLOW }}
uses: microsoft/BCApps/.github/actions/RunAutomation@main
with:
automations: SubmitStabilityJob
targetBranch: ${{ matrix.branch }}
2 changes: 2 additions & 0 deletions .github/workflows/UpdateALGoOnOfficialBranches.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ permissions: read-all
jobs:
GetBranches:
name: Get Official Branches
if: github.repository_owner == 'microsoft'
runs-on: ubuntu-latest
outputs:
updateBranches: ${{ steps.getOfficialBranches.outputs.branchesJson }}
Expand All @@ -22,6 +23,7 @@ jobs:

UpdateALGo:
name: "[${{ matrix.branch }}] Update AL-Go"
if: github.repository_owner == 'microsoft'
runs-on: ubuntu-latest
environment: Official-Build
needs: GetBranches
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/UpdateBCArtifactVersion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ permissions: read-all
jobs:
GetBranches:
name: Get Official Branches
if: github.repository_owner == 'microsoft'
runs-on: ubuntu-latest
outputs:
updateBranches: ${{ steps.getOfficialBranches.outputs.branchesJson }}
Expand All @@ -27,6 +28,7 @@ jobs:

UpdateBCArtifactVersion:
name: "[${{ matrix.branch }}] Update BC Artifact Version"
if: github.repository_owner == 'microsoft'
permissions:
contents: write
environment: Official-Build
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/UpdatePackageVersions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ permissions: read-all
jobs:
GetBranches:
name: Get Official Branches
if: github.repository_owner == 'microsoft'
runs-on: ubuntu-latest
outputs:
updateBranches: ${{ steps.getOfficialBranches.outputs.branchesJson }}
Expand All @@ -26,6 +27,7 @@ jobs:

UpdatePackageVersions:
name: "[${{ matrix.branch }}] Update Package Versions"
if: github.repository_owner == 'microsoft'
permissions:
contents: write
runs-on: windows-latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/scorecard-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ permissions: read-all
jobs:
analysis:
name: Scorecard analysis
if: github.repository_owner == 'microsoft'
runs-on: ubuntu-latest
permissions:
security-events: write # Needed for Code scanning upload
Expand Down
24 changes: 19 additions & 5 deletions build/scripts/EnlistmentHelperFunctions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ function Get-LatestBCArtifactUrl
[Parameter(Mandatory=$true)]
$minimumVersion,
[Parameter(Mandatory=$false)]
$storageAccountOrder = @("bcartifacts", "bcinsider")
$storageAccountOrder = @("bcartifacts", "bcinsider"),
[Parameter(Mandatory=$false)]
[switch] $asPattern
)
{
$artifactUrl = Get-BCArtifactUrl -type Sandbox -country base -version $minimumVersion -select Latest -storageAccount $storageAccountOrder[0] -accept_insiderEula
Expand All @@ -296,6 +298,14 @@ function Get-LatestBCArtifactUrl
throw "No artifact found for version $minimumVersion"
}

if ($asPattern) {
if ($artifactUrl -match $storageAccountOrder[0]) {
$artifactUrl = "$($storageAccountOrder[0])/Sandbox/$minimumVersion/base/latest"
} else {
$artifactUrl = "$($storageAccountOrder[1])/Sandbox/$minimumVersion/base/latest"
}
}

return $artifactUrl
}

Expand All @@ -307,12 +317,16 @@ function Get-LatestBCArtifactUrl
#>
function Update-BCArtifactVersion {
$currentArtifactUrl = Get-ConfigValue -Key "artifact" -ConfigType AL-Go

Write-Host "Current BCArtifact URL: $currentArtifactUrl"

$currentVersion = Get-ConfigValue -Key "repoVersion" -ConfigType AL-Go
$latestArtifactUrl = Get-LatestBCArtifactUrl -minimumVersion $currentVersion
Write-Host "Current BCArtifact URL: $currentArtifactUrl"

if ($currentArtifactUrl -notlike "https*") {
Write-Host "Getting latest BCArtifact version as pattern with minimum version $currentVersion"
$latestArtifactUrl = Get-LatestBCArtifactUrl -minimumVersion $currentVersion -asPattern
} else {
Write-Host "Getting latest BCArtifact version as URL with minimum version $currentVersion"
$latestArtifactUrl = Get-LatestBCArtifactUrl -minimumVersion $currentVersion
}
Write-Host "Latest BCArtifact URL: $latestArtifactUrl"

$result = $null
Expand Down

0 comments on commit b656871

Please sign in to comment.