Skip to content

Commit

Permalink
Deploybug (#1076)
Browse files Browse the repository at this point in the history
2 bugs when deploying to preview

- use of unknown variable (reserveReleaseNotes)
- use of wrong name of end 2 end tests workflow when searching for
workflow results

Also, when testing that end 2 end tests have run - check that no jobs
were skipped (running only partial tests)
autodeploy to preview after successful end 2 end tests.

---------

Co-authored-by: freddydk <[email protected]>
  • Loading branch information
freddydk and freddydk authored May 16, 2024
1 parent a565e16 commit 6a9ef0c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 19 deletions.
75 changes: 57 additions & 18 deletions .github/workflows/Deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,49 +27,88 @@ on:
type: boolean
description: Create a release in this repository
required: false
default: true
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 (or preview for preview branches)'
required: false
default: ''
default: 'latest'

permissions:
contents: read
actions: read

defaults:
run:
shell: pwsh

jobs:
Inputs:
runs-on: [ ubuntu-latest ]
outputs:
branch: ${{ steps.CreateInputs.outputs.branch }}
copyToMain: ${{ steps.CreateInputs.outputs.copyToMain }}
directCommit: ${{ steps.CreateInputs.outputs.directCommit }}
requireEndToEndTests: ${{ steps.CreateInputs.outputs.requireEndToEndTests }}
createRelease: ${{ steps.CreateInputs.outputs.createRelease }}
defaultBcContainerHelperVersion: ${{ steps.CreateInputs.outputs.defaultBcContainerHelperVersion }}
steps:
- name: Create inputs
id: CreateInputs
run: |
$branch = '${{ github.event.inputs.branch }}'
$copyToMain = '${{ github.event.inputs.copyToMain }}'
$directCommit = '${{ github.event.inputs.directCommit }}'
$requireEndToEndTests = '${{ github.event.inputs.requireEndToEndTests }}'
$createRelease = '${{ github.event.inputs.createRelease }}'
$defaultBcContainerHelperVersion = '${{ github.event.inputs.defaultBcContainerHelperVersion }}'
Add-Content -encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "branch=$branch"
Add-Content -encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "copyToMain=$copyToMain"
Add-Content -encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "directCommit=$directCommit"
Add-Content -encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "requireEndToEndTests=$requireEndToEndTests"
Add-Content -encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "createRelease=$createRelease"
Add-Content -encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "defaultBcContainerHelperVersion=$defaultBcContainerHelperVersion"
CheckEndToEnd:
runs-on: [ ubuntu-latest ]
needs: [ Inputs ]
steps:
- name: Check successful end 2 end tests have run
if: github.repository_owner == 'microsoft' && github.event.inputs.requireEndToEndTests == 'true'
if: github.repository_owner == 'microsoft' && needs.Inputs.outputs.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' }
$end2endRuns = (gh api "/repos/$($env:GITHUB_REPOSITORY)/actions/workflows/E2E.yaml/runs?per_page=100&branch=main" | ConvertFrom-Json).workflow_runs
$latestSha = (gh api /repos/$($env:GITHUB_REPOSITORY)/commits/main | ConvertFrom-Json).sha
$latestRun = $end2endruns | Where-Object { $_.head_sha -eq $latestSha }
$latestRun = $end2endruns | Where-Object { $_.Name -eq "End to end tests - $latestSha" } | select-object -first 1
if (!$latestRun) {
throw "No End 2 End Tests run found for the latest commit on main"
throw "No End to 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"
throw "End to end tests run for the latest commit on main is not completed - see $($latestRun.html_url)"
}
if ($latestRun.conclusion -ne 'success') {
throw "End 2 End Tests run for the latest commit on main did not succeed"
throw "End to end tests run for the latest commit on main did not succeed - see $($latestRun.html_url)"
}
$allJobs = (gh api --paginate /repos/$($env:GITHUB_REPOSITORY)/actions/runs/$($latestRun.id)/jobs | ConvertFrom-Json).jobs
foreach($job in $allJobs) {
if ($job.conclusion -ne 'success') {
throw "Some jobs in the end to end tests run for the latest commit was skipped, failed or cancelled - see $($latestRun.html_url)"
}
}
Deploy:
runs-on: [ ubuntu-latest ]
needs: [ CheckEndToEnd ]
needs: [ CheckEndToEnd, Inputs ]
environment: Production
permissions:
contents: write
steps:
- name: Validate Deployment
if: github.repository_owner == 'microsoft'
env:
GH_TOKEN: ${{ github.token }}
branch: ${{ github.event.inputs.branch }}
branch: ${{ needs.Inputs.outputs.branch }}
runId: ${{ github.run_id }}
run: |
$errorActionPreference = "Stop"
Expand All @@ -88,10 +127,10 @@ jobs:

- name: Deploy
env:
branch: ${{ github.event.inputs.branch }}
copyToMain: ${{ github.event.inputs.copyToMain }}
directCommit: ${{ github.event.inputs.directCommit }}
defaultBcContainerHelperVersion: ${{ github.event.inputs.defaultBcContainerHelperVersion }}
branch: ${{ needs.Inputs.outputs.branch }}
copyToMain: ${{ needs.Inputs.outputs.copyToMain }}
directCommit: ${{ needs.Inputs.outputs.directCommit }}
defaultBcContainerHelperVersion: ${{ needs.Inputs.outputs.defaultBcContainerHelperVersion }}
run: |
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
try {
Expand Down Expand Up @@ -124,7 +163,7 @@ jobs:
}
- name: Calculate Release Notes
if: github.repository_owner == 'microsoft' && github.event.inputs.createRelease == 'true'
if: github.repository_owner == 'microsoft' && needs.Inputs.outputs.createRelease == 'true'
run: |
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
$releaseNotesFile = Join-Path $env:GITHUB_WORKSPACE "RELEASENOTES.md"
Expand All @@ -134,14 +173,14 @@ jobs:
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'
if: github.repository_owner == 'microsoft' && needs.Inputs.outputs.createRelease == 'true'
uses: actions/github-script@v7
id: createrelease
env:
branch: ${{ github.event.inputs.branch }}
branch: ${{ needs.Inputs.outputs.branch }}
bodyMD: ${{ env.ReleaseNotes }}
with:
github-token: ${{ secrets.OrgPAT }}
github-token: ${{ github.token }}
script: |
var bodyMD = process.env.bodyMD
const createReleaseResponse = await github.rest.repos.createRelease({
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/E2E.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
name: End to end tests

run-name: End to end tests - ${{ github.event.inputs.ref != '' && github.event.inputs.ref || github.sha }}

on:
workflow_dispatch:
inputs:
Expand Down
2 changes: 1 addition & 1 deletion Internal/Deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ try {
$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"
$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$releaseNotes"
}
else {
$releaseNotes = "## $($config.branch)`n`n$releaseNotes"
Expand Down

0 comments on commit 6a9ef0c

Please sign in to comment.