Create release - Version 1.8.34 #9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: ' Create release' | |
run-name: "Create release - Version ${{ inputs.tag }}" | |
on: | |
workflow_dispatch: | |
inputs: | |
appVersion: | |
description: App version to promote to release (default is latest) | |
required: false | |
default: 'latest' | |
name: | |
description: Name of this release | |
required: true | |
default: '' | |
tag: | |
description: Tag of this release (needs to be semantic version string https://semver.org, ex. 1.0.0) | |
required: true | |
default: '' | |
releaseType: | |
description: Release, prerelease or draft? | |
type: choice | |
options: | |
- Release | |
- Prerelease | |
- Draft | |
default: Release | |
createReleaseBranch: | |
description: Create Release Branch? | |
type: boolean | |
default: false | |
releaseBranchPrefix: | |
description: The prefix for the release branch. Used only if 'Create Release Branch?' is checked. | |
type: string | |
default: release/ | |
updateVersionNumber: | |
description: New Version Number in main branch. Use Major.Minor (optionally add .Build for versioningstrategy 3) for absolute change, or +1, +0.1 (or +0.0.1 for versioningstrategy 3) incremental change. | |
required: false | |
default: '' | |
skipUpdatingDependencies: | |
description: Skip updating dependency version numbers in all apps. | |
type: boolean | |
default: false | |
directCommit: | |
description: Direct Commit? | |
type: boolean | |
default: false | |
useGhTokenWorkflow: | |
description: Use GhTokenWorkflow for PR/Commit? | |
type: boolean | |
default: false | |
permissions: | |
actions: read | |
contents: write | |
id-token: write | |
pull-requests: write | |
concurrency: release | |
defaults: | |
run: | |
shell: pwsh | |
env: | |
ALGoOrgSettings: ${{ vars.ALGoOrgSettings }} | |
ALGoRepoSettings: ${{ vars.ALGoRepoSettings }} | |
jobs: | |
CreateRelease: | |
needs: [ ] | |
runs-on: [ ubuntu-latest ] | |
outputs: | |
artifacts: ${{ steps.analyzeartifacts.outputs.artifacts }} | |
releaseId: ${{ steps.createrelease.outputs.releaseId }} | |
commitish: ${{ steps.analyzeartifacts.outputs.commitish }} | |
releaseVersion: ${{ steps.createreleasenotes.outputs.releaseVersion }} | |
telemetryScopeJson: ${{ steps.init.outputs.telemetryScopeJson }} | |
steps: | |
- name: Dump Workflow Information | |
uses: microsoft/AL-Go-Actions/DumpWorkflowInfo@v6.3 | |
with: | |
shell: pwsh | |
- name: Checkout | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: Initialize the workflow | |
id: init | |
uses: microsoft/AL-Go-Actions/WorkflowInitialize@v6.3 | |
with: | |
shell: pwsh | |
- name: Read settings | |
id: ReadSettings | |
uses: microsoft/AL-Go-Actions/ReadSettings@v6.3 | |
with: | |
shell: pwsh | |
get: templateUrl,repoName,type,powerPlatformSolutionFolder | |
- name: Read secrets | |
id: ReadSecrets | |
uses: microsoft/AL-Go-Actions/ReadSecrets@v6.3 | |
with: | |
shell: pwsh | |
gitHubSecrets: ${{ toJson(secrets) }} | |
getSecrets: 'TokenForPush' | |
useGhTokenWorkflowForPush: '${{ github.event.inputs.useGhTokenWorkflow }}' | |
- name: Determine Projects | |
id: determineProjects | |
uses: microsoft/AL-Go-Actions/DetermineProjectsToBuild@v6.3 | |
with: | |
shell: pwsh | |
- name: Check for updates to AL-Go system files | |
uses: microsoft/AL-Go-Actions/CheckForUpdates@v6.3 | |
with: | |
shell: pwsh | |
templateUrl: ${{ env.templateUrl }} | |
downloadLatest: true | |
- name: Analyze Artifacts | |
id: analyzeartifacts | |
env: | |
_appVersion: ${{ github.event.inputs.appVersion }} | |
run: | | |
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0 | |
$projects = '${{ steps.determineProjects.outputs.ProjectsJson }}' | ConvertFrom-Json | |
Write-Host "projects:" | |
$projects | ForEach-Object { Write-Host "- $_" } | |
if ($env:type -eq "PTE" -and $env:powerPlatformSolutionFolder -ne "") { | |
Write-Host "PowerPlatformSolution:" | |
Write-Host "- $($env:powerPlatformSolutionFolder)" | |
$projects += @($env:powerPlatformSolutionFolder) | |
} | |
$include = @() | |
$sha = '' | |
$allArtifacts = @() | |
$page = 1 | |
$headers = @{ | |
"Authorization" = "token ${{ github.token }}" | |
"X-GitHub-Api-Version" = "2022-11-28" | |
"Accept" = "application/vnd.github+json; charset=utf-8" | |
} | |
do { | |
$repoArtifacts = Invoke-RestMethod -UseBasicParsing -Headers $headers -Uri "$($ENV:GITHUB_API_URL)/repos/$($ENV:GITHUB_REPOSITORY)/actions/artifacts?per_page=100&page=$page" | |
$allArtifacts += $repoArtifacts.Artifacts | Where-Object { !$_.expired } | |
$page++ | |
} | |
while ($repoArtifacts.Artifacts.Count -gt 0) | |
Write-Host "Repo Artifacts count: $($repoArtifacts.total_count)" | |
Write-Host "Downloaded Artifacts count: $($allArtifacts.Count)" | |
$projects | ForEach-Object { | |
$thisProject = $_ | |
if ($thisProject -and ($thisProject -ne '.')) { | |
$project = $thisProject.Replace('\','_').Replace('/','_') | |
} | |
else { | |
$project = $env:repoName | |
} | |
$refname = "$ENV:GITHUB_REF_NAME".Replace('/','_') | |
Write-Host "Analyzing artifacts for project $project" | |
$appVersion = "$env:_appVersion" | |
if ($appVersion -eq "latest") { | |
Write-Host "Grab latest" | |
$artifact = $allArtifacts | Where-Object { $_.name -like "$project-$refname-Apps-*" -or $_.name -like "$project-$refname-PowerPlatformSolution-*" } | Select-Object -First 1 | |
} | |
else { | |
Write-Host "Search for $project-$refname-Apps-$appVersion or $project-$refname-PowerPlatformSolution-$appVersion" | |
$artifact = $allArtifacts | Where-Object { $_.name -eq "$project-$refname-Apps-$appVersion"-or $_.name -eq "$project-$refname-PowerPlatformSolution-$appVersion" } | Select-Object -First 1 | |
} | |
if ($artifact) { | |
$startIndex = $artifact.name.LastIndexOf('-') + 1 | |
$artifactsVersion = $artifact.name.SubString($startIndex) | |
} | |
else { | |
Write-Host "::Error::No artifacts found for this project" | |
exit 1 | |
} | |
if ($sha) { | |
if ($artifact.workflow_run.head_sha -ne $sha) { | |
Write-Host "::Error::The build selected for release doesn't contain all projects. Please rebuild all projects by manually running the CI/CD workflow and recreate the release." | |
throw "The build selected for release doesn't contain all projects. Please rebuild all projects by manually running the CI/CD workflow and recreate the release." | |
} | |
} | |
else { | |
$sha = $artifact.workflow_run.head_sha | |
} | |
Write-host "Looking for $project-$refname-Apps-$artifactsVersion or $project-$refname-TestApps-$artifactsVersion or $project-$refname-Dependencies-$artifactsVersion or $project-$refname-PowerPlatformSolution-$artifactsVersion" | |
$allArtifacts | Where-Object { ($_.name -like "$project-$refname-Apps-$artifactsVersion" -or $_.name -like "$project-$refname-TestApps-$artifactsVersion" -or $_.name -like "$project-$refname-Dependencies-$artifactsVersion" -or $_.name -like "$project-$refname-PowerPlatformSolution-$artifactsVersion") } | ForEach-Object { | |
$atype = $_.name.SubString(0,$_.name.Length-$artifactsVersion.Length-1) | |
$atype = $atype.SubString($atype.LastIndexOf('-')+1) | |
$include += $( [ordered]@{ "name" = $_.name; "url" = $_.archive_download_url; "atype" = $atype; "project" = $thisproject } ) | |
} | |
if ($include.Count -eq 0) { | |
Write-Host "::Error::No artifacts found for version $artifactsVersion" | |
exit 1 | |
} | |
} | |
$artifacts = @{ "include" = $include } | |
$artifactsJson = $artifacts | ConvertTo-Json -compress | |
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "artifacts=$artifactsJson" | |
Write-Host "artifacts=$artifactsJson" | |
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "commitish=$sha" | |
Write-Host "commitish=$sha" | |
- name: Prepare release notes | |
id: createreleasenotes | |
uses: microsoft/AL-Go-Actions/CreateReleaseNotes@v6.3 | |
with: | |
shell: pwsh | |
tag_name: ${{ github.event.inputs.tag }} | |
target_commitish: ${{ steps.analyzeartifacts.outputs.commitish }} | |
- name: Create release | |
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
id: createrelease | |
env: | |
bodyMD: ${{ steps.createreleasenotes.outputs.releaseNotes }} | |
with: | |
github-token: ${{ steps.ReadSecrets.outputs.TokenForPush }} | |
script: | | |
var bodyMD = process.env.bodyMD | |
const createReleaseResponse = await github.rest.repos.createRelease({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag_name: '${{ github.event.inputs.tag }}', | |
name: '${{ github.event.inputs.name }}', | |
body: bodyMD.replaceAll('\\n','\n').replaceAll('%0A','\n').replaceAll('%0D','\n').replaceAll('%25','%'), | |
draft: ${{ github.event.inputs.releaseType=='Draft' }}, | |
prerelease: ${{ github.event.inputs.releaseType=='Prerelease' }}, | |
make_latest: 'legacy', | |
target_commitish: '${{ steps.analyzeartifacts.outputs.commitish }}' | |
}); | |
const { | |
data: { id: releaseId, html_url: htmlUrl, upload_url: uploadUrl } | |
} = createReleaseResponse; | |
core.setOutput('releaseId', releaseId); | |
UploadArtifacts: | |
needs: [ CreateRelease ] | |
runs-on: [ ubuntu-latest ] | |
strategy: | |
matrix: ${{ fromJson(needs.CreateRelease.outputs.artifacts) }} | |
fail-fast: true | |
steps: | |
- name: Checkout | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: Read settings | |
uses: microsoft/AL-Go-Actions/ReadSettings@v6.3 | |
with: | |
shell: pwsh | |
- name: Read secrets | |
id: ReadSecrets | |
uses: microsoft/AL-Go-Actions/ReadSecrets@v6.3 | |
with: | |
shell: pwsh | |
gitHubSecrets: ${{ toJson(secrets) }} | |
getSecrets: 'nuGetContext,storageContext,TokenForPush' | |
useGhTokenWorkflowForPush: '${{ github.event.inputs.useGhTokenWorkflow }}' | |
- name: Download artifact | |
run: | | |
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0 | |
Write-Host "Downloading artifact ${{ matrix.name}}" | |
$headers = @{ | |
"Authorization" = "token ${{ github.token }}" | |
"X-GitHub-Api-Version" = "2022-11-28" | |
"Accept" = "application/vnd.github+json" | |
} | |
Invoke-WebRequest -UseBasicParsing -Headers $headers -Uri '${{ matrix.url }}' -OutFile '${{ matrix.name }}.zip' | |
- name: Upload release artifacts | |
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
env: | |
releaseId: ${{ needs.createrelease.outputs.releaseId }} | |
with: | |
github-token: ${{ steps.ReadSecrets.outputs.TokenForPush }} | |
script: | | |
const releaseId = process.env.releaseId | |
const assetPath = '${{ matrix.name }}.zip' | |
const assetName = encodeURIComponent('${{ matrix.name }}.zip'.replaceAll(' ','.')).replaceAll('%','') | |
const fs = require('fs'); | |
const uploadAssetResponse = await github.rest.repos.uploadReleaseAsset({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
release_id: releaseId, | |
name: assetName, | |
data: fs.readFileSync(assetPath) | |
}); | |
- name: Deliver to NuGet | |
uses: microsoft/AL-Go-Actions/Deliver@v6.3 | |
if: ${{ fromJson(steps.ReadSecrets.outputs.Secrets).nuGetContext != '' }} | |
env: | |
Secrets: '${{ steps.ReadSecrets.outputs.Secrets }}' | |
with: | |
shell: pwsh | |
type: 'Release' | |
projects: ${{ matrix.project }} | |
deliveryTarget: 'NuGet' | |
artifacts: ${{ github.event.inputs.appVersion }} | |
atypes: 'Apps,TestApps' | |
- name: Deliver to Storage | |
uses: microsoft/AL-Go-Actions/Deliver@v6.3 | |
if: ${{ fromJson(steps.ReadSecrets.outputs.Secrets).storageContext != '' }} | |
env: | |
Secrets: '${{ steps.ReadSecrets.outputs.Secrets }}' | |
with: | |
shell: pwsh | |
type: 'Release' | |
projects: ${{ matrix.project }} | |
deliveryTarget: 'Storage' | |
artifacts: ${{ github.event.inputs.appVersion }} | |
atypes: 'Apps,TestApps,Dependencies' | |
CreateReleaseBranch: | |
needs: [ CreateRelease, UploadArtifacts ] | |
if: ${{ github.event.inputs.createReleaseBranch=='true' }} | |
runs-on: [ ubuntu-latest ] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
ref: '${{ needs.createRelease.outputs.commitish }}' | |
- name: Create Release Branch | |
env: | |
releaseBranchPrefix: ${{ github.event.inputs.releaseBranchPrefix }} | |
run: | | |
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0 | |
$releaseBranch = "$($env:releaseBranchPrefix)" + "${{ needs.CreateRelease.outputs.releaseVersion }}" | |
Write-Host "Creating release branch $releaseBranch" | |
git checkout -b $releaseBranch | |
git config user.name ${{ github.actor}} | |
git config user.email ${{ github.actor}}@users.noreply.github.com | |
git commit --allow-empty -m "Release branch $releaseBranch" | |
git push origin $releaseBranch | |
UpdateVersionNumber: | |
needs: [ CreateRelease, UploadArtifacts ] | |
if: ${{ github.event.inputs.updateVersionNumber!='' }} | |
runs-on: [ ubuntu-latest ] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: Read settings | |
uses: microsoft/AL-Go-Actions/ReadSettings@v6.3 | |
with: | |
shell: pwsh | |
- name: Read secrets | |
id: ReadSecrets | |
uses: microsoft/AL-Go-Actions/ReadSecrets@v6.3 | |
with: | |
shell: pwsh | |
gitHubSecrets: ${{ toJson(secrets) }} | |
getSecrets: 'TokenForPush' | |
useGhTokenWorkflowForPush: '${{ github.event.inputs.useGhTokenWorkflow }}' | |
- name: Update Version Number | |
uses: microsoft/AL-Go-Actions/IncrementVersionNumber@v6.3 | |
with: | |
shell: pwsh | |
token: ${{ steps.ReadSecrets.outputs.TokenForPush }} | |
versionNumber: ${{ github.event.inputs.updateVersionNumber }} | |
skipUpdatingDependencies: ${{ github.event.inputs.skipUpdatingDependencies }} | |
directCommit: ${{ github.event.inputs.directCommit }} | |
PostProcess: | |
needs: [ CreateRelease, UploadArtifacts, CreateReleaseBranch, UpdateVersionNumber ] | |
if: always() | |
runs-on: [ ubuntu-latest ] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: Finalize the workflow | |
id: PostProcess | |
uses: microsoft/AL-Go-Actions/WorkflowPostProcess@v6.3 | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
with: | |
shell: pwsh | |
telemetryScopeJson: ${{ needs.CreateRelease.outputs.telemetryScopeJson }} | |
currentJobContext: ${{ toJson(job) }} |