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

Remove thisbuild artifacts and support preprocessor symbols #1374

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions Actions/AL-Go-Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ function ReadSettings {
[string] $baseFolder = "$ENV:GITHUB_WORKSPACE",
[string] $repoName = "$ENV:GITHUB_REPOSITORY",
[string] $project = '.',
[string] $buildMode = "Default",
[string] $workflowName = "$ENV:GITHUB_WORKFLOW",
[string] $userName = "$ENV:GITHUB_ACTOR",
[string] $branchName = "$ENV:GITHUB_REF_NAME",
Expand Down Expand Up @@ -686,6 +687,8 @@ function ReadSettings {
}
"useGitSubmodules" = "false"
"gitSubmodulesTokenSecretName" = "gitSubmodulesToken"
"shortLivedArtifactsRetentionDays" = 1
"longLivedArtifactsRetentionDays" = 0 # 0 means use GitHub default
}

# Read settings from files and merge them into the settings object
Expand Down Expand Up @@ -730,6 +733,10 @@ function ReadSettings {
if ("$conditionalSetting" -ne "") {
$conditionMet = $true
$conditions = @()
if ($conditionalSetting.PSObject.Properties.Name -eq "buildModes") {
$conditionMet = $conditionMet -and ($conditionalSetting.buildModes | Where-Object { $buildMode -like $_ })
$conditions += @("buildMode: $buildMode")
}
if ($conditionalSetting.PSObject.Properties.Name -eq "branches") {
$conditionMet = $conditionMet -and ($conditionalSetting.branches | Where-Object { $branchName -like $_ })
$conditions += @("branchName: $branchName")
Expand Down
7 changes: 0 additions & 7 deletions Actions/CalculateArtifactNames/CalculateArtifactNames.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,3 @@ else {
$value = "$($projectName)-$($branchName)-$buildMode$_-$suffix"
Set-OutputVariable -name $name -value $value
}

# Set this build artifacts name
'Apps', 'Dependencies', 'TestApps' | ForEach-Object {
$name = "ThisBuild$($_)ArtifactsName"
$value = "thisbuild-$($projectName)-$($buildMode)$($_)"
Set-OutputVariable -name $name -value $value
}
3 changes: 0 additions & 3 deletions Actions/CalculateArtifactNames/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ none

| Name | Description |
| :-- | :-- |
| ThisBuildAppsArtifactsName | Artifact name for apps being built in the current workflow run |
| ThisBuildDependenciesArtifactsName | Artifact name for dependencies of apps being built in the current workflow run |
| ThisBuildTestAppsArtifactsName | Artifact name for test apps being built in the current workflow run |
| AppsArtifactsName | Artifacts name for Apps |
| PowerPlatformSolutionArtifactsName | Artifacts name for PowerPlatform Solution |
| DependenciesArtifactsName | Artifacts name for Dependencies |
Expand Down
9 changes: 0 additions & 9 deletions Actions/CalculateArtifactNames/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ inputs:
required: false
default: ''
outputs:
ThisBuildAppsArtifactsName:
description: Artifact name for apps being built in the current workflow run
value: ${{ steps.calculateartifactnames.outputs.ThisBuildAppsArtifactsName }}
ThisBuildDependenciesArtifactsName:
description: Artifact name for dependencies of apps being built in the current workflow run
value: ${{ steps.calculateartifactnames.outputs.ThisBuildDependenciesArtifactsName }}
ThisBuildTestAppsArtifactsName:
description: Artifact name for test apps being built in the current workflow run
value: ${{ steps.calculateartifactnames.outputs.ThisBuildTestAppsArtifactsName }}
AppsArtifactsName:
description: Artifacts name for Apps
value: ${{ steps.calculateartifactnames.outputs.AppsArtifactsName }}
Expand Down
3 changes: 2 additions & 1 deletion Actions/Github-Helper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ function GetDependencies {
if ($dependency.release_status -eq "thisBuild") {
$missingProjects = @()
foreach($project in $projects.Split(',')) {
$branchName = $dependency.branch.Replace('\', '_').Replace('/', '_')
$project = $project.Replace('\','_').Replace('/','_') # sanitize project name

$downloadName = Join-Path $saveToPath "thisbuild-$project-$($mask)"
$downloadName = Join-Path $saveToPath "$project-$branchName-$mask-*"

if (Test-Path $downloadName -PathType Container) {
$folder = Get-Item $downloadName
Expand Down
1 change: 1 addition & 0 deletions Actions/ReadSettings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ none
| :-- | :-: | :-- | :-- |
| shell | | The shell (powershell or pwsh) in which the PowerShell script in this action should run | powershell |
| project | | Project name if the repository is setup for multiple projects | . |
| buildMode | | Build mode. Only set when called from \_BuildALGoProject | Default |
| get | | Specifies which properties to get from the settings file, default is all | |

## OUTPUT
Expand Down
4 changes: 3 additions & 1 deletion Actions/ReadSettings/ReadSettings.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
Param(
[Parameter(HelpMessage = "Project folder", Mandatory = $false)]
[string] $project = ".",
[Parameter(HelpMessage = "Build mode", Mandatory = $false)]
[string] $buildMode = "Default",
[Parameter(HelpMessage = "Specifies which properties to get from the settings file, default is all", Mandatory = $false)]
[string] $get = ""
)

. (Join-Path -Path $PSScriptRoot -ChildPath "..\AL-Go-Helper.ps1" -Resolve)

$settings = ReadSettings -project $project
$settings = ReadSettings -project $project -buildMode $buildMode
if ($get) {
$getSettings = $get.Split(',').Trim()
}
Expand Down
7 changes: 6 additions & 1 deletion Actions/ReadSettings/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ inputs:
description: Project folder
required: false
default: '.'
buildMode:
description: Build mode
required: false
default: 'Default'
get:
description: Specifies which properties to get from the settings file, default is all
required: false
Expand All @@ -28,10 +32,11 @@ runs:
id: readsettings
env:
_project: ${{ inputs.project }}
_buildMode: ${{ inputs.buildMode }}
_get: ${{ inputs.get }}
run: |
${{ github.action_path }}/../Invoke-AlGoAction.ps1 -ActionName "ReadSettings" -Action {
${{ github.action_path }}/ReadSettings.ps1 -project $ENV:_project -get $ENV:_get
${{ github.action_path }}/ReadSettings.ps1 -project $ENV:_project -buildMode $ENV:_buildMode -get $ENV:_get
}
branding:
icon: terminal
Expand Down
22 changes: 12 additions & 10 deletions Actions/RunPipeline/RunPipeline.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -370,18 +370,9 @@ try {

switch($buildMode){
'Clean' {
$preprocessorsymbols = $settings.cleanModePreprocessorSymbols

if (!$preprocessorsymbols) {
if (-not $settings.ContainsKey('cleanModePreprocessorSymbols')) {
throw "No cleanModePreprocessorSymbols defined in settings.json for this project. Please add the preprocessor symbols to use when building in clean mode or disable CLEAN mode."
}

if ($runAlPipelineParams.Keys -notcontains 'preprocessorsymbols') {
$runAlPipelineParams["preprocessorsymbols"] = @()
}

Write-Host "Adding Preprocessor symbols: $preprocessorsymbols"
$runAlPipelineParams["preprocessorsymbols"] += $preprocessorsymbols
}
'Translated' {
if ($runAlPipelineParams.Keys -notcontains 'features') {
Expand All @@ -391,6 +382,17 @@ try {
}
}

if ($runAlPipelineParams.Keys -notcontains 'preprocessorsymbols') {
$runAlPipelineParams["preprocessorsymbols"] = @()
}
foreach($preprocessorSymbolsSettingsName in @("preprocessorSymbols", "$($buildMode)ModePreprocessorSymbols")) {
if ($settings.ContainsKey($preprocessorSymbolsSettingsName)) {
$preprocessorsymbols = $settings."$preprocessorSymbolsSettingsName"
Write-Host "Adding Preprocessor symbols from setting $preprocessorSymbolsSettingsName : $($preprocessorsymbols -join ',')"
$runAlPipelineParams["preprocessorsymbols"] += $preprocessorsymbols
}
}

Write-Host "Invoke Run-AlPipeline with buildmode $buildMode"
Run-AlPipeline @runAlPipelineParams `
-accept_insiderEula `
Expand Down
17 changes: 17 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,27 @@

- It is now possible to skip the modification of dependency version numbers when running the Increment Version number workflow or the Create Release workflow

### New Repository Settings

- [`shortLivedArtifactsRetentionDays`](https://aka.ms/algosettings#shortLivedArtifactsRetentionDays) determines the number of days to keep short lived build artifacts (f.ex build artifacts from pull request builds, next minor or next major builds). 1 is default. 0 means use GitHub default.
- [`longLivedArtifactsRetentionDays`](https://aka.ms/algosettings#longLivedArtifactsRetentionDays) determines the number of days to keep long lived build artifacts (f.ex build artifacts from CI/CD builds). 0 is the default and means use GitHub default.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use GitHubs default, why not just let people control this setting through GitHub? Is there a need for an AL-Go setting?
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could remove the longLivedArtifactsRetentionDays

- [`preProcessorSymbols`](https://aka.ms/algosettings#preProcessorSymbols) is a list of preprocessor symbols to use when building the apps. This setting can be specified in workflow specific settings files or in conditional settings.
- [`<buildMode>PreProcessorSymbols`](https://aka.ms/algosettings#cleanModePreProcessorSymbols) is a list of preprocessor symbols to be used when building apps in the \<buildMode> build mode. CleanModePreProcessorSymbols is a variation of this.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this PR also adds buildmode as a condition for conditional settings, shouldn't people just create a conditional setting called "preProcessorSymbols"? Similar to what you did here https://github.com/BusinessCentralApps/buildorder/blob/8e64503f243aaf6e24e7deca8d47b80975c97c54/BO-DK/.AL-Go/settings.json#L8

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could - but then we would have cleanModePreprocessorSymbols as a special case for compatibility?
Should we then issue a deprecation warning about that and ask people to modify this to a conditionalsetting instead?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we then issue a deprecation warning about that and ask people to modify this to a conditionalsetting instead?

That sounds like a good plan I think


### New Versioning Strategy

Setting versioning strategy to 3 will allow 3 segments of the version number to be defined in app.json and repoVersion. Only the 4th segment (Revision) will be defined by the GitHub [run_number](https://go.microsoft.com/fwlink/?linkid=2217416&clcid=0x409) for the CI/CD workflow. Increment version number and Create Release now also supports the ability to set a third segment to the RepoVersion and appversion in app.json.

### Change in published artifacts

When using `useProjectDependencies` in a multi-project repository, AL-Go for GitHub used to generate short lived build artifacts called `thisBuild-<projectnaame>-<type>-...`. This is no longer the case. Instead, normal build artifacts will be published and used by depending projects. The retention period for the artifacts generated are controlled by two settings called [`shortLivedArtifactsRetentionDays`](https://aka.ms/algosettings#shortLivedArtifactsRetentionDays) and [`longLivedArtifactsRetentionDays`](https://aka.ms/algosettings#longLivedArtifactsRetentionDays).

### Preprocessor symbols

It is now possible to define preprocessor symbols, which will be used when building your apps using the [`preProcessorSymbols`](https://aka.ms/algosettings#preProcessorSymbols) setting. This setting can be specified in workflow specific settings file or it can be used in conditional settings.

You can also specify preProcessor symbols for custom build modes by using the [`<buildMode>PreProcessorSymbols`](https://aka.ms/algosettings#cleanModePreProcessorSymbols) setting.

## v6.2

### Issues
Expand Down
6 changes: 5 additions & 1 deletion Scenarios/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ When running a workflow or a local script, the settings are applied by reading s
| <a id="doNotRunpageScriptingTests"></a>doNotRunpageScriptingTests | When true, this setting forces the pipeline to NOT run the page scripting tests specified in pageScriptingTests. Note this setting can be set in a [workflow specific settings file](#where-are-the-settings-located) to only apply to that workflow | false |
| <a id="restoreDatabases"></a>restoreDatabases | restoreDatabases should be an array of events, indicating when you want to start with clean databases in the container. Possible events are: `BeforeBcpTests`, `BeforePageScriptingTests`, `BeforeEachTestApp`, `BeforeEachBcptTestApp`, `BeforeEachPageScriptingTest` | \[ \] |
| <a id="appDependencyProbingPaths"></a>appDependencyProbingPaths | Array of dependency specifications, from which apps will be downloaded when the CI/CD workflow is starting. Every dependency specification consists of the following properties:<br />**repo** = repository<br />**version** = version (default latest)<br />**release_status** = latestBuild/release/prerelease/draft (default release)<br />**projects** = projects (default * = all)<br />**branch** = branch (default main)<br />**AuthTokenSecret** = Name of secret containing auth token (default none)<br /> | \[ \] |
| <a id="cleanModePreprocessorSymbols"></a>cleanModePreprocessorSymbols | List of clean tags to be used in _Clean_ build mode | \[ \] |
| <a id="preprocessorSymbols"></a>preprocessorSymbols | List of preprocessor symbols to use when building the apps | \[ \] |
| <a id="cleanModePreprocessorSymbols"></a>cleanModePreprocessorSymbols | List of preprocessor symbols (clean tags) to be used in _Clean_ build mode. If you are using custom build modes, you can also define preprocessor symbols for the build mode using a `<buildmode>ModePreprocessorSymbols` settings | \[ \] |
| <a id="bcptThresholds"></a>bcptThresholds | Structure with properties for the thresholds when running performance tests using the Business Central Performance Toolkit.<br />**DurationWarning** = a warning is shown if the duration of a bcpt test degrades more than this percentage (default 10)<br />**DurationError** - an error is shown if the duration of a bcpt test degrades more than this percentage (default 25)<br />**NumberOfSqlStmtsWarning** - a warning is shown if the number of SQL statements from a bcpt test increases more than this percentage (default 5)<br />**NumberOfSqlStmtsError** - an error is shown if the number of SQL statements from a bcpt test increases more than this percentage (default 10)<br />*Note that errors and warnings on the build in GitHub are only issued when a threshold is exceeded on the codeunit level, when an individual operation threshold is exceeded, it is only shown in the test results viewer.* |

## AppSource specific basic project settings
Expand Down Expand Up @@ -124,6 +125,8 @@ The repository settings are only read from the repository settings file (.github
| <a id="trustMicrosoftNuGetFeeds"></a>trustMicrosoftNuGetFeeds | Unless this setting is set to false, AL-Go for GitHub will trust the NuGet feeds provided by Microsoft. The feeds provided by Microsoft contains all Microsoft apps, all Microsoft symbols and symbols for all AppSource apps. | true |
| <a id="trustedNuGetFeeds"></a>trustedNuGetFeeds | trustedNuGetFeeds can be an array of NuGet feed specifications, which AL-Go for GitHub will use for dependency resolution. Every feed specification must include a URL property and can optionally include a few other properties:<br />**url** = The URL of the feed (examples: https://pkgs.dev.azure.com/myorg/apps/\_packaging/myrepo/nuget/v3/index.json or https://nuget.pkg.github.com/mygithuborg/index.json").<br />**authTokenSecret** = If the NuGet feed specified by URL is private, the authTokenSecret must be the name of a secret containing the authentication token with permissions to search and read packages from the NuGet feed.<br />**patterns** = AL-Go for GitHub will only trust packages, where the ID matches this pattern. Default is all packages (\*).<br />**fingerprints** = If specified, AL-Go for GitHub will only trust packages signed with a certificate with a fingerprint matching one of the fingerprints in this array. | \[ \] |
| <a id="trustedSigning"></a>trustedSigning | Structure defining the properties needed for enabling trusted Signing. Please read [this](https://learn.microsoft.com/en-us/azure/trusted-signing/) to setup your Azure Trusted Signing Account and Certificate Profile and then provide these properties in this setting:<br />**Account** must be the name of your trusted signing account.<br />**Endpoint** must point to the endpoint of your trusted signing account (ex. https://weu.codesigning.azure.net).<br />**CertificateProfile** must be the CertificateProfile in your trusted signing account you want to use for signing.<br />Please note that your Azure_Credentials secret (Microsoft Entra ID App or Managed identity) needs to provide access to your azure subscription and be assigned the `Trusted Signing Certificate Profile Signer` role in the Trusted Signing Account. |
| <a id="shortLivedArtifactsRetentionDays"></a>shortLivedArtifactsRetentionDays | Number of days to keep short lived build artifacts (f.ex build artifacts from pull request builds, next minor or next major builds). 0 means use GitHub default. | 1 |
| <a id="longLivedArtifactsRetentionDays"></a>longLivedArtifactsRetentionDays | Number of days to keep long lived build artifacts (f.ex build artifacts from CI/CD builds). 0 means use GitHub default. | 0 |

## AppSource specific advanced settings

Expand Down Expand Up @@ -156,6 +159,7 @@ to your [project settings file](#where-are-the-settings-located) will ensure tha

- **repositories** settings will be applied to repositories matching the patterns
- **projects** settings will be applied to projects matching the patterns
- **buildModes** settings will be applied when building with these buildModes
- **branches** settings will be applied to branches matching the patterns
- **workflows** settings will be applied to workflows matching the patterns
- **users** settings will be applied for users matching the patterns
Expand Down
7 changes: 4 additions & 3 deletions Templates/AppSource App/.github/workflows/CICD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
buildOrderJson: ${{ steps.determineProjectsToBuild.outputs.BuildOrderJson }}
powerPlatformSolutionFolder: ${{ steps.DeterminePowerPlatformSolutionFolder.outputs.powerPlatformSolutionFolder }}
workflowDepth: ${{ steps.DetermineWorkflowDepth.outputs.WorkflowDepth }}
artifactsRetentionDays: ${{ steps.DetermineWorkflowDepth.outputs.ArtifactsRetentionDays }}
steps:
- name: Dump Workflow Information
uses: microsoft/AL-Go-Actions/DumpWorkflowInfo@main
Expand All @@ -65,7 +66,7 @@ jobs:
uses: microsoft/AL-Go-Actions/ReadSettings@main
with:
shell: powershell
get: type,powerPlatformSolutionFolder,useGitSubmodules
get: type,powerPlatformSolutionFolder,useGitSubmodules,longLivedArtifactsRetentionDays

- name: Read submodules token
id: ReadSubmodulesToken
Expand All @@ -88,6 +89,7 @@ jobs:
id: DetermineWorkflowDepth
run: |
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "WorkflowDepth=$($env:workflowDepth)"
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "ArtifactsRetentionDays=$($env:longLivedArtifactsRetentionDays)"

- name: Determine Projects To Build
id: determineProjectsToBuild
Expand Down Expand Up @@ -176,8 +178,7 @@ jobs:
buildMode: ${{ matrix.buildMode }}
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/') || startswith(github.ref_name, 'releases/') || needs.Initialization.outputs.deliveryTargetsJson != '[]' || needs.Initialization.outputs.environmentCount > 0 }}
artifactsRetentionDays: ${{ fromJson(needs.Initialization.outputs.artifactsRetentionDays) }}
signArtifacts: true
useArtifactCache: true

Expand Down
Loading
Loading