Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes microsoft#962
Fixes microsoft#792 

Add "shell" as a property under DeployTo, allowing you to control which
shell to use on a self hosted runner f.eks. - not forcing you to use the
same shell as for other jobs.

---------

Co-authored-by: freddydk <[email protected]>
  • Loading branch information
freddydk and freddydk authored Apr 15, 2024
1 parent c4cf36c commit 49b8ce2
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ if (!($environments)) {
"SyncMode" = $null
"continuousDeployment" = !($getEnvironments -like '* (PROD)' -or $getEnvironments -like '* (Production)' -or $getEnvironments -like '* (FAT)' -or $getEnvironments -like '* (Final Acceptance Test)')
"runs-on" = @($settings."runs-on".Split(',').Trim())
"shell" = $settings."shell"
}
}
$unknownEnvironment = 1
Expand All @@ -130,6 +131,7 @@ else {
# - projects: all
# - continuous deployment: only for environments not tagged with PROD or FAT
# - runs-on: same as settings."runs-on"
# - shell: same as settings."shell"
$deploymentSettings = @{
"EnvironmentType" = "SaaS"
"EnvironmentName" = $envName
Expand All @@ -139,18 +141,22 @@ else {
"SyncMode" = $null
"continuousDeployment" = $null
"runs-on" = @($settings."runs-on".Split(',').Trim())
"shell" = $settings."shell"
}

# Check DeployTo<environmentName> setting
$settingsName = "DeployTo$envName"
if ($settings.ContainsKey($settingsName)) {
# If a DeployTo<environmentName> setting exists - use values from this (over the defaults)
$deployTo = $settings."$settingsName"
foreach($key in 'EnvironmentType','EnvironmentName','Branches','Projects','SyncMode','ContinuousDeployment','runs-on') {
foreach($key in 'EnvironmentType','EnvironmentName','Branches','Projects','SyncMode','ContinuousDeployment','runs-on','shell') {
if ($deployTo.ContainsKey($key)) {
$deploymentSettings."$key" = $deployTo."$key"
}
}
if ($deploymentSettings."shell" -ne 'pwsh' -and $deploymentSettings."shell" -ne 'powershell') {
throw "The shell setting in $settingsName must be either 'pwsh' or 'powershell'"
}
}

# Get Branch policies on GitHub Environment
Expand Down Expand Up @@ -203,7 +209,7 @@ else {
$json = @{"matrix" = @{ "include" = @() }; "fail-fast" = $false }
$deploymentEnvironments.Keys | Sort-Object | ForEach-Object {
$deploymentEnvironment = $deploymentEnvironments."$_"
$json.matrix.include += @{ "environment" = $_; "os" = "$(ConvertTo-Json -InputObject $deploymentEnvironment."runs-on" -compress)" }
$json.matrix.include += @{ "environment" = $_; "os" = "$(ConvertTo-Json -InputObject $deploymentEnvironment."runs-on" -compress)"; "shell" = $deploymentEnvironment."shell" }
}
$environmentsMatrixJson = $json | ConvertTo-Json -Depth 99 -compress
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "EnvironmentsMatrixJson=$environmentsMatrixJson"
Expand Down
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ Note that when using the preview version of AL-Go for GitHub, we recommend you U
- Issue 987 Resource not accessible by integration when creating release from specific version
- Issue 979 Publish to AppSource Documentation
- Issue 1008 Allow PullRequestHandler to use ubuntu or self hosted runners for all jobs except for pregateCheck
- Issue 962 Finer control of "shell"-property

### New Settings
- `deliverToAppSource`: a JSON object containing the following properties
- **productId** must be the product Id from partner Center.
- **mainAppFolder** specifies the appFolder of the main app if you have multiple apps in the same project.
- **continuousDelivery** can be set to true to enable continuous delivery of every successful build to AppSource Validation. Note that the app will only be in preview in AppSource and you will need to manually press GO LIVE in order for the app to be promoted to production.
- **includeDependencies** can be set to an array of file names (incl. wildcards) which are the names of the dependencies to include in the AppSource submission. Note that you need to set `generateDependencyArtifact` in the project settings file to true in order to include dependencies.
- Add `shell` as a property under `DeployTo` structure

### Deprecated Settings
- `appSourceContinuousDelivery` is moved to the `deliverToAppSource` structure
Expand Down
3 changes: 2 additions & 1 deletion Scenarios/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The repository settings are only read from the repository settings file (.github
| <a id="githubRunnerShell"></a>githubRunnerShell | Specifies which shell is used for build jobs in workflows including a build job. The default is to use the same as defined in **shell**. If the shell setting isn't defined, **powershell** is the default, which results in using _PowerShell 5.1_. Use **pwsh** for _PowerShell 7_. |
| <a id="environments"></a>environments | Array of logical environment names. You can specify environments in GitHub environments or in the repo settings file. If you specify environments in the settings file, you can create your AUTHCONTEXT secret using **&lt;environmentname&gt;_AUTHCONTEXT**. You can specify additional information about environments in a setting called **DeployTo&lt;environmentname&gt;** |
| <a id="deliverto"></a>DeliverTo&lt;deliveryTarget&gt; | Structure with additional properties for the deliveryTarget specified. Some properties are deliveryTarget specific. The structure can contain the following properties:<br />**Branches** = an array of branch patterns, which are allowed to deliver to this deliveryTarget. (Default main)<br />**CreateContainerIfNotExist** = *[Only for DeliverToStorage]* Create Blob Storage Container if it doesn't already exist. (Default false)<br /> |
| <a id="deployto"></a>DeployTo&lt;environmentname&gt; | Structure with additional properties for the environment specified. The structure can contain the following properties:<br />**EnvironmentType** = specifies the type of environment. The environment type can be used to invoke a custom deployment. (Default SaaS)<br />**EnvironmentName** = specifies the "real" name of the environment if it differs from the GitHub environment.<br />**Branches** = an array of branch patterns, which are allowed to deploy to this environment. These branches can also be defined under the environment in GitHub settings and both settings are honored. If neither setting is defined, the default is the **main** branch only.<br />**Projects** = In multi-project repositories, this property can be a comma separated list of project patterns to deploy to this environment. (Default *)<br />**SyncMode** = ForceSync if deployment to this environment should happen with ForceSync, else Add. If deploying to the development endpoint you can also specify Development or Clean. (Default Add)<br />**ContinuousDeployment** = true if this environment should be used for continuous deployment, else false. (Default: AL-Go will continuously deploy to sandbox environments or environments, which doesn't end in (PROD) or (FAT)<br />**runs-on** = specifies which runner to use when deploying to this environment. (Default is settings.runs-on)<br /> |
| <a id="deployto"></a>DeployTo&lt;environmentname&gt; | Structure with additional properties for the environment specified. The structure can contain the following properties:<br />**EnvironmentType** = specifies the type of environment. The environment type can be used to invoke a custom deployment. (Default SaaS)<br />**EnvironmentName** = specifies the "real" name of the environment if it differs from the GitHub environment.<br />**Branches** = an array of branch patterns, which are allowed to deploy to this environment. These branches can also be defined under the environment in GitHub settings and both settings are honored. If neither setting is defined, the default is the **main** branch only.<br />**Projects** = In multi-project repositories, this property can be a comma separated list of project patterns to deploy to this environment. (Default *)<br />**SyncMode** = ForceSync if deployment to this environment should happen with ForceSync, else Add. If deploying to the development endpoint you can also specify Development or Clean. (Default Add)<br />**ContinuousDeployment** = true if this environment should be used for continuous deployment, else false. (Default: AL-Go will continuously deploy to sandbox environments or environments, which doesn't end in (PROD) or (FAT)<br />**runs-on** = specifies which runner to use when deploying to this environment. (Default is settings.runs-on)<br />**shell** = specifies which shell to use when deploying to this environment, pwsh or powershell. (Default is settings.shell)<br /> |
| <a id="aldoc"></a>alDoc | Structure with properties for the aldoc reference document generation. The structure can contain the following properties:<br />**continuousDeployment** = Determines if reference documentation will be deployed continuously as part of CI/CD. You can run the **Deploy Reference Documentation** workflow to deploy manually or on a schedule. (Default false)<br />**deployToGitHubPages** = Determines whether or not the reference documentation site should be deployed to GitHub Pages for the repository. In order to deploy to GitHub Pages, GitHub Pages must be enabled and set to GitHub Actuibs. (Default true)<br />**maxReleases** = Maximum number of releases to include in the reference documentation. (Default 3)<br />**groupByProject** = Determines whether projects in multi-project repositories are used as folders in reference documentation<br />**includeProjects** = An array of projects to include in the reference documentation. (Default all)<br />**excludeProjects** = An array of projects to exclude in the reference documentation. (Default none)<br />**header** = Header for the documentation site. (Default: Documentation for...)<br />**footer** = Footer for the documentation site. (Default: Made with...)<br />**defaultIndexMD** = Markdown for the landing page of the documentation site. (Default: Reference documentation...)<br />**defaultReleaseMD** = Markdown for the landing page of the release sites. (Default: Release reference documentation...)<br />*Note that in header, footer, defaultIndexMD and defaultReleaseMD you can use the following placeholders: {REPOSITORY}, {VERSION}, {INDEXTEMPLATERELATIVEPATH}, {RELEASENOTES}* |
| <a id="useProjectDependencies"></a>useProjectDependencies | Determines whether your projects are built using a multi-stage built workflow or single stage. After setting useProjectDependencies to true, you need to run Update AL-Go System Files and your workflows including a build job will change to have multiple build jobs, depending on each other. The number of build jobs will be determined by the dependency depth in your projects.<br />You can change dependencies between your projects, but if the dependency **depth** changes, AL-Go will warn you that updates for your AL-Go System Files are available and you will need to run the workflow. |
| <a id="CICDPushBranches"></a>CICDPushBranches | CICDPushBranches can be specified as an array of branches, which triggers a CI/CD workflow on commit. You need to run the Update AL-Go System Files workflow for the schedule to take effect.<br />Default is [ "main", "release/\*", "feature/\*" ] |
Expand Down Expand Up @@ -258,6 +258,7 @@ Here are the parameters to use in your custom script:
| `$parameters.Projects` | Projects to deploy to this environment | |
| `$parameters.ContinuousDeployment` | Is this environment setup for continuous deployment | false |
| `$parameters."runs-on"` | GitHub runner to be used to run the deployment script | windows-latest |
| `$parameters."shell"` | Shell used to run the deployment script, pwsh or powershell | powershell |

## Run-AlPipeline script override

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 @@ -226,10 +226,11 @@ jobs:
- name: Read settings
uses: microsoft/AL-Go-Actions/ReadSettings@main
with:
shell: powershell
shell: ${{ matrix.shell }}

- name: EnvName
id: envName
shell: ${{ matrix.shell }}
run: |
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
$envName = '${{ matrix.environment }}'.split(' ')[0]
Expand All @@ -239,7 +240,7 @@ jobs:
id: ReadSecrets
uses: microsoft/AL-Go-Actions/ReadSecrets@main
with:
shell: powershell
shell: ${{ matrix.shell }}
gitHubSecrets: ${{ toJson(secrets) }}
getSecrets: '${{ steps.envName.outputs.envName }}-AuthContext,${{ steps.envName.outputs.envName }}_AuthContext,AuthContext,${{ steps.envName.outputs.envName }}-EnvironmentName,${{ steps.envName.outputs.envName }}_EnvironmentName,EnvironmentName,projects'

Expand All @@ -249,7 +250,7 @@ jobs:
env:
Secrets: '${{ steps.ReadSecrets.outputs.Secrets }}'
with:
shell: powershell
shell: ${{ matrix.shell }}
environmentName: ${{ matrix.environment }}
artifacts: '.artifacts'
type: 'CD'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ jobs:

- name: EnvName
id: envName
shell: ${{ matrix.shell }}
run: |
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
$envName = '${{ matrix.environment }}'.split(' ')[0]
Expand All @@ -140,13 +141,13 @@ jobs:
- name: Read settings
uses: microsoft/AL-Go-Actions/ReadSettings@main
with:
shell: powershell
shell: ${{ matrix.shell }}

- name: Read secrets
id: ReadSecrets
uses: microsoft/AL-Go-Actions/ReadSecrets@main
with:
shell: powershell
shell: ${{ matrix.shell }}
gitHubSecrets: ${{ toJson(secrets) }}
getSecrets: '${{ steps.envName.outputs.envName }}-AuthContext,${{ steps.envName.outputs.envName }}_AuthContext,AuthContext,${{ steps.envName.outputs.envName }}-EnvironmentName,${{ steps.envName.outputs.envName }}_EnvironmentName,EnvironmentName,projects'

Expand All @@ -156,7 +157,7 @@ jobs:
env:
Secrets: '${{ steps.ReadSecrets.outputs.Secrets }}'
with:
shell: powershell
shell: ${{ matrix.shell }}
environmentName: ${{ matrix.environment }}
artifacts: ${{ github.event.inputs.appVersion }}
type: 'Publish'
Expand Down
7 changes: 4 additions & 3 deletions Templates/Per Tenant Extension/.github/workflows/CICD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,11 @@ jobs:
- name: Read settings
uses: microsoft/AL-Go-Actions/ReadSettings@main
with:
shell: powershell
shell: ${{ matrix.shell }}

- name: EnvName
id: envName
shell: ${{ matrix.shell }}
run: |
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
$envName = '${{ matrix.environment }}'.split(' ')[0]
Expand All @@ -239,7 +240,7 @@ jobs:
id: ReadSecrets
uses: microsoft/AL-Go-Actions/ReadSecrets@main
with:
shell: powershell
shell: ${{ matrix.shell }}
gitHubSecrets: ${{ toJson(secrets) }}
getSecrets: '${{ steps.envName.outputs.envName }}-AuthContext,${{ steps.envName.outputs.envName }}_AuthContext,AuthContext,${{ steps.envName.outputs.envName }}-EnvironmentName,${{ steps.envName.outputs.envName }}_EnvironmentName,EnvironmentName,projects'

Expand All @@ -249,7 +250,7 @@ jobs:
env:
Secrets: '${{ steps.ReadSecrets.outputs.Secrets }}'
with:
shell: powershell
shell: ${{ matrix.shell }}
environmentName: ${{ matrix.environment }}
artifacts: '.artifacts'
type: 'CD'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ jobs:

- name: EnvName
id: envName
shell: ${{ matrix.shell }}
run: |
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
$envName = '${{ matrix.environment }}'.split(' ')[0]
Expand All @@ -140,13 +141,13 @@ jobs:
- name: Read settings
uses: microsoft/AL-Go-Actions/ReadSettings@main
with:
shell: powershell
shell: ${{ matrix.shell }}

- name: Read secrets
id: ReadSecrets
uses: microsoft/AL-Go-Actions/ReadSecrets@main
with:
shell: powershell
shell: ${{ matrix.shell }}
gitHubSecrets: ${{ toJson(secrets) }}
getSecrets: '${{ steps.envName.outputs.envName }}-AuthContext,${{ steps.envName.outputs.envName }}_AuthContext,AuthContext,${{ steps.envName.outputs.envName }}-EnvironmentName,${{ steps.envName.outputs.envName }}_EnvironmentName,EnvironmentName,projects'

Expand All @@ -156,7 +157,7 @@ jobs:
env:
Secrets: '${{ steps.ReadSecrets.outputs.Secrets }}'
with:
shell: powershell
shell: ${{ matrix.shell }}
environmentName: ${{ matrix.environment }}
artifacts: ${{ github.event.inputs.appVersion }}
type: 'Publish'
Expand Down
Loading

0 comments on commit 49b8ce2

Please sign in to comment.