Skip to content

Commit 92365fb

Browse files
freddydkaholstrup1
andauthored
Automate release process (#1064)
Automate: - The generation of modifying release notes with the version number (and revert) - Creation of a release in AL-Go repo Adds: - Check that a successful end 2 end test was run on the same commit you are releasing --------- Co-authored-by: freddydk <[email protected]> Co-authored-by: Alexander Holstrup <[email protected]>
1 parent bb22cfd commit 92365fb

File tree

3 files changed

+80
-9
lines changed

3 files changed

+80
-9
lines changed

.github/workflows/Deploy.yaml

+71-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ on:
1818
description: Push directly to the target branch. If not set, a PR will be created.
1919
required: false
2020
default: false
21+
requireEndToEndTests:
22+
type: boolean
23+
description: Require successful end 2 end tests before deploying
24+
required: false
25+
default: true
26+
createRelease:
27+
type: boolean
28+
description: Create a release in this repository
29+
required: false
30+
default: true
2131
defaultBcContainerHelperVersion:
2232
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 (or preview for preview branches)'
2333
required: false
@@ -28,24 +38,46 @@ defaults:
2838
shell: pwsh
2939

3040
jobs:
41+
CheckEndToEnd:
42+
runs-on: [ ubuntu-latest ]
43+
steps:
44+
- name: Check successful end 2 end tests have run
45+
if: github.repository_owner == 'microsoft' && github.event.inputs.requireEndToEndTests == 'true'
46+
env:
47+
GH_TOKEN: ${{ github.token }}
48+
run: |
49+
$errorActionPreference = "Stop"
50+
$end2endRuns = (gh api /repos/$($env:GITHUB_REPOSITORY)/actions/runs?per_page=100 | ConvertFrom-Json).workflow_runs | Where-Object { $_.name -eq 'End 2 End Tests' }
51+
$latestSha = (gh api /repos/$($env:GITHUB_REPOSITORY)/commits/main | ConvertFrom-Json).sha
52+
$latestRun = $end2endruns | Where-Object { $_.head_sha -eq $latestSha }
53+
if (!$latestRun) {
54+
throw "No End 2 End Tests run found for the latest commit on main"
55+
}
56+
if ($latestRun.status -ne 'completed') {
57+
throw "End 2 End Tests run for the latest commit on main is not completed"
58+
}
59+
if ($latestRun.conclusion -ne 'success') {
60+
throw "End 2 End Tests run for the latest commit on main did not succeed"
61+
}
62+
3163
Deploy:
3264
runs-on: [ ubuntu-latest ]
65+
needs: [ CheckEndToEnd ]
3366
environment: Production
3467
steps:
3568
- name: Validate Deployment
3669
if: github.repository_owner == 'microsoft'
3770
env:
3871
GH_TOKEN: ${{ github.token }}
3972
branch: ${{ github.event.inputs.branch }}
40-
repository: ${{ github.repository }}
4173
runId: ${{ github.run_id }}
4274
run: |
4375
$errorActionPreference = "Stop"
4476
if ($env:branch -eq 'preview') {
4577
Write-Host "Deploying to preview branch. No validation required"
4678
} else {
47-
$approval = gh api /repos/$($env:repository)/actions/runs/$($env:runId)/approvals | ConvertFrom-Json
48-
$run = gh api /repos/$($env:repository)/actions/runs/$($env:runId) | ConvertFrom-Json
79+
$approval = gh api /repos/$($env:GITHUB_REPOSITORY)/actions/runs/$($env:runId)/approvals | ConvertFrom-Json
80+
$run = gh api /repos/$($env:GITHUB_REPOSITORY)/actions/runs/$($env:runId) | ConvertFrom-Json
4981
5082
if ($approval.user.login -eq $run.actor.login) {
5183
throw "You cannot approve your own deployment"
@@ -67,7 +99,7 @@ jobs:
6799
if (!$token) {
68100
throw "In order to run the Deploy workflow, you need a Secret called OrgPAT containing a valid Personal Access Token"
69101
}
70-
$githubOwner = "$ENV:GITHUB_REPOSITORY_OWNER"
102+
$githubOwner = "$env:GITHUB_REPOSITORY_OWNER"
71103
if ("$env:defaultBcContainerHelperVersion" -eq "") {
72104
if ($env:branch -eq 'preview') {
73105
$env:defaultBcContainerHelperVersion = 'preview'
@@ -90,3 +122,38 @@ jobs:
90122
Write-Host "::Error::Error deploying repositories. The error was $($_.Exception.Message)"
91123
exit 1
92124
}
125+
126+
- name: Calculate Release Notes
127+
if: github.repository_owner == 'microsoft' && github.event.inputs.createRelease == 'true'
128+
run: |
129+
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
130+
$releaseNotesFile = Join-Path $env:GITHUB_WORKSPACE "RELEASENOTES.md"
131+
$releaseNotes = (Get-Content -Encoding utf8 -Path $releaseNotesFile) -join "`n"
132+
$lastVersion = $releaseNotes.indexof("`n## ")
133+
$releaseNotes = $releaseNotes.Substring(0, $lastVersion)
134+
Add-Content -encoding UTF8 -Path $env:GITHUB_ENV -Value "ReleaseNotes=$([Uri]::EscapeDataString($releaseNotes))"
135+
136+
- name: Create release
137+
if: github.repository_owner == 'microsoft' && github.event.inputs.createRelease == 'true'
138+
uses: actions/github-script@v7
139+
id: createrelease
140+
env:
141+
branch: ${{ github.event.inputs.branch }}
142+
bodyMD: ${{ env.ReleaseNotes }}
143+
with:
144+
github-token: ${{ secrets.OrgPAT }}
145+
script: |
146+
var bodyMD = process.env.bodyMD
147+
const createReleaseResponse = await github.rest.repos.createRelease({
148+
owner: context.repo.owner,
149+
repo: context.repo.repo,
150+
tag_name: '${{ env.branch }}',
151+
name: '${{ env.branch }}',
152+
body: decodeURIComponent(bodyMD),
153+
draft: false,
154+
prerelease: false
155+
});
156+
const {
157+
data: { id: releaseId, html_url: htmlUrl, upload_url: uploadUrl }
158+
} = createReleaseResponse;
159+
core.setOutput('releaseId', releaseId);

Internal/Deploy.ps1

+9-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,15 @@ try {
242242
[System.IO.File]::WriteAllText($dstFile, "$($lines -join "`n")`n")
243243
}
244244
if (Test-Path -Path (Join-Path '.' '.github') -PathType Container) {
245-
Copy-Item -Path (Join-Path $baseRepoPath "RELEASENOTES.md") -Destination (Join-Path "./.github" "RELEASENOTES.copy.md") -Force
245+
$releaseNotesFile = Join-Path $baseRepoPath "RELEASENOTES.md"
246+
$releaseNotes = (Get-Content -Encoding utf8 -Path $releaseNotesFile) -join "`n"
247+
if ($config.branch -eq 'preview') {
248+
$releaseNotes = "## $($config.branch)`n`nNote that when using the preview version of AL-Go for GitHub, we recommend you Update your AL-Go system files, as soon as possible when informed that an update is available.`n`n$reserveReleaseNotes"
249+
}
250+
else {
251+
$releaseNotes = "## $($config.branch)`n`n$releaseNotes"
252+
}
253+
Set-Content -Path (Join-Path "./.github" "RELEASENOTES.copy.md") -Value $releaseNotes -Encoding utf8
246254
}
247255
PushChanges -BaseBranch $branch -CommitMessage "Deploying AL-Go from $algoBranch ($srcSHA) to $branch" -DirectCommit $directCommit
248256

RELEASENOTES.md

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
## Preview
2-
3-
Note that when using the preview version of AL-Go for GitHub, we recommend you Update your AL-Go system files, as soon as possible when informed that an update is available.
4-
51
### Issues
62

73
- Issue 1019 CI/CD Workflow still being scheduled after it was disabled

0 commit comments

Comments
 (0)