Skip to content

Deploy from [main] to [preview] #134

Deploy from [main] to [preview]

Deploy from [main] to [preview] #134

Workflow file for this run

name: Deploy
run-name: "Deploy from [${{ github.ref_name }}] to [${{ inputs.branch }}]"
on:
workflow_dispatch:
inputs:
branch:
description: 'Branch to deploy to (NOTE: Use preview when deploying preview releases on microsoft/al-go)'
required: true
copyToMain:
type: boolean
description: 'Additionally deploy templates to main+preview branch? Set if this is a release to PROD on microsoft/al-go'
required: false
default: false
directCommit:
type: boolean
description: Push directly to the target branch. If not set, a PR will be created.
required: false
default: false
defaultBcContainerHelperVersion:
description: 'Which version of BcContainerHelper to use? (latest, preview, private, a specific version number or a direct download URL like https://github.com/freddydk/navcontainerhelper/archive/master.zip - leave empty to use latest)'
required: false
default: ''
defaults:
run:
shell: pwsh
jobs:
Deploy:
runs-on: [ ubuntu-latest ]
environment: Production
steps:
- name: Validate Deployment
if: github.repository_owner == 'microsoft'
env:
GH_TOKEN: ${{ github.token }}
branch: ${{ github.event.inputs.branch }}
repository: ${{ github.repository }}
runId: ${{ github.run_id }}
run: |
$errorActionPreference = "Stop"
if ($env:branch -eq 'preview') {
Write-Host "Deploying to preview branch. No validation required"
} else {
$approval = gh api /repos/$($env:repository)/actions/runs/$($env:runId)/approvals | ConvertFrom-Json
$run = gh api /repos/$($env:repository)/actions/runs/$($env:runId) | ConvertFrom-Json
if ($approval.user.login -eq $run.actor.login) {
throw "You cannot approve your own deployment"
}
}
- uses: actions/checkout@v3
- name: Deploy
env:
branch: ${{ github.event.inputs.branch }}
copyToMain: ${{ github.event.inputs.copyToMain }}
directCommit: ${{ github.event.inputs.directCommit }}
defaultBcContainerHelperVersion: ${{ github.event.inputs.defaultBcContainerHelperVersion }}
run: |
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
try {
$token = '${{ Secrets.OrgPAT }}'
if (!$token) {
throw "In order to run the Deploy workflow, you need a Secret called OrgPAT containing a valid Personal Access Token"
}
$githubOwner = "$ENV:GITHUB_REPOSITORY_OWNER"
$config = @{
"githubOwner" = $githubOwner
"actionsRepo" = "AL-Go-Actions"
"perTenantExtensionRepo" = "AL-Go-PTE"
"appSourceAppRepo" = "AL-Go-AppSource"
"branch" = $env:branch
"copyToMain" = ($env:copyToMain -eq 'true')
"defaultBcContainerHelperVersion" = $env:defaultBcContainerHelperVersion
}
. ".\Internal\Deploy.ps1" -config $config -token $token -directCommit ($env:directCommit -eq 'true')
}
catch {
Write-Host "::Error::Error deploying repositories. The error was $($_.Exception.Message)"
exit 1
}