diff --git a/.github/workflows/Deploy.yaml b/.github/workflows/Deploy.yaml index 2db6ba29b..2daad115a 100644 --- a/.github/workflows/Deploy.yaml +++ b/.github/workflows/Deploy.yaml @@ -18,6 +18,16 @@ on: description: Push directly to the target branch. If not set, a PR will be created. required: false default: false + requireEndToEndTests: + type: boolean + description: Require successful end 2 end tests before deploying + required: false + default: true + createRelease: + type: boolean + description: Create a release in this repository + required: false + default: true 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 (or preview for preview branches)' required: false @@ -28,8 +38,31 @@ defaults: shell: pwsh jobs: + CheckEndToEnd: + runs-on: [ ubuntu-latest ] + steps: + - name: Check successful end 2 end tests have run + if: github.repository_owner == 'microsoft' && github.event.inputs.requireEndToEndTests == 'true' + env: + GH_TOKEN: ${{ github.token }} + run: | + $errorActionPreference = "Stop" + $end2endRuns = (gh api /repos/$($env:GITHUB_REPOSITORY)/actions/runs?per_page=100 | ConvertFrom-Json).workflow_runs | Where-Object { $_.name -eq 'End 2 End Tests' } + $latestSha = (gh api /repos/$($env:GITHUB_REPOSITORY)/commits/main | ConvertFrom-Json).sha + $latestRun = $end2endruns | Where-Object { $_.head_sha -eq $latestSha } + if (!$latestRun) { + throw "No End 2 End Tests run found for the latest commit on main" + } + if ($latestRun.status -ne 'completed') { + throw "End 2 End Tests run for the latest commit on main is not completed" + } + if ($latestRun.conclusion -ne 'success') { + throw "End 2 End Tests run for the latest commit on main did not succeed" + } + Deploy: runs-on: [ ubuntu-latest ] + needs: [ CheckEndToEnd ] environment: Production steps: - name: Validate Deployment @@ -37,15 +70,14 @@ jobs: 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 + $approval = gh api /repos/$($env:GITHUB_REPOSITORY)/actions/runs/$($env:runId)/approvals | ConvertFrom-Json + $run = gh api /repos/$($env:GITHUB_REPOSITORY)/actions/runs/$($env:runId) | ConvertFrom-Json if ($approval.user.login -eq $run.actor.login) { throw "You cannot approve your own deployment" @@ -67,7 +99,7 @@ jobs: 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" + $githubOwner = "$env:GITHUB_REPOSITORY_OWNER" if ("$env:defaultBcContainerHelperVersion" -eq "") { if ($env:branch -eq 'preview') { $env:defaultBcContainerHelperVersion = 'preview' @@ -90,3 +122,38 @@ jobs: Write-Host "::Error::Error deploying repositories. The error was $($_.Exception.Message)" exit 1 } + + - name: Calculate Release Notes + if: github.repository_owner == 'microsoft' && github.event.inputs.createRelease == 'true' + run: | + $errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0 + $releaseNotesFile = Join-Path $env:GITHUB_WORKSPACE "RELEASENOTES.md" + $releaseNotes = (Get-Content -Encoding utf8 -Path $releaseNotesFile) -join "`n" + $lastVersion = $releaseNotes.indexof("`n## ") + $releaseNotes = $releaseNotes.Substring(0, $lastVersion) + Add-Content -encoding UTF8 -Path $env:GITHUB_ENV -Value "ReleaseNotes=$([Uri]::EscapeDataString($releaseNotes))" + + - name: Create release + if: github.repository_owner == 'microsoft' && github.event.inputs.createRelease == 'true' + uses: actions/github-script@v7 + id: createrelease + env: + branch: ${{ github.event.inputs.branch }} + bodyMD: ${{ env.ReleaseNotes }} + with: + github-token: ${{ secrets.OrgPAT }} + script: | + var bodyMD = process.env.bodyMD + const createReleaseResponse = await github.rest.repos.createRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + tag_name: '${{ env.branch }}', + name: '${{ env.branch }}', + body: decodeURIComponent(bodyMD), + draft: false, + prerelease: false + }); + const { + data: { id: releaseId, html_url: htmlUrl, upload_url: uploadUrl } + } = createReleaseResponse; + core.setOutput('releaseId', releaseId); diff --git a/Internal/Deploy.ps1 b/Internal/Deploy.ps1 index 938e3f494..8229ea0e1 100644 --- a/Internal/Deploy.ps1 +++ b/Internal/Deploy.ps1 @@ -242,7 +242,15 @@ try { [System.IO.File]::WriteAllText($dstFile, "$($lines -join "`n")`n") } if (Test-Path -Path (Join-Path '.' '.github') -PathType Container) { - Copy-Item -Path (Join-Path $baseRepoPath "RELEASENOTES.md") -Destination (Join-Path "./.github" "RELEASENOTES.copy.md") -Force + $releaseNotesFile = Join-Path $baseRepoPath "RELEASENOTES.md" + $releaseNotes = (Get-Content -Encoding utf8 -Path $releaseNotesFile) -join "`n" + if ($config.branch -eq 'preview') { + $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" + } + else { + $releaseNotes = "## $($config.branch)`n`n$releaseNotes" + } + Set-Content -Path (Join-Path "./.github" "RELEASENOTES.copy.md") -Value $releaseNotes -Encoding utf8 } PushChanges -BaseBranch $branch -CommitMessage "Deploying AL-Go from $algoBranch ($srcSHA) to $branch" -DirectCommit $directCommit diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 6c1465287..062706737 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -1,7 +1,3 @@ -## Preview - -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. - ### Issues - Issue 1019 CI/CD Workflow still being scheduled after it was disabled