Skip to content

Commit

Permalink
Merge pull request #385 from Lombiq/issue/OSOE-899
Browse files Browse the repository at this point in the history
OSOE-899: Fixing swap workflow tag management
  • Loading branch information
DemeSzabolcs authored Sep 24, 2024
2 parents 32df384 + 7757d36 commit 4480671
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions .github/workflows/swap-azure-web-app-slots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,8 @@ jobs:
repository: ${{ inputs.app-code-repository }}
token: ${{ secrets.CODE_REPOSITORY_WRITE_TOKEN }}
submodules: false

- name: Remove Old Latest Tags
uses: Lombiq/GitHub-Actions/.github/actions/remove-old-latest-tags@dev
with:
tag-prefix: ${{ inputs.tag-prefix }}
# We need the full history for the tags, and it's not necessarily the default branch that's swapped out.
fetch-depth: 0

- name: Move Latest Tag (Swap) and Add Timestamp Tag
id: move-latest-tag
Expand All @@ -168,28 +165,48 @@ jobs:
throw 'Tag prefix not set, exiting'
}
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git config user.name 'github-actions[bot]'
$tagExists = (git tag --list '${{ inputs.swap-prefix }}/latest')
if ([string]::IsNullOrEmpty($tagExists))
{
throw 'No latest tag found for swap prefix'
throw 'No latest tag found for the swap prefix in the code repo.'
}
$latest = (git rev-list -n 1 '${{ inputs.swap-prefix }}/latest')
if ($latest)
$stagingLatest = (git rev-list --max-count=1 '${{ inputs.swap-prefix }}/latest')
if ($stagingLatest)
{
git tag --annotate '${{ inputs.tag-prefix }}/latest' $latest --message 'Latest tag for ${{ inputs.tag-prefix }}'
git fetch --tags
$stagingLatestTag = (git tag --list '${{ inputs.tag-prefix }}/latest')
if ($stagingLatestTag)
{
# Move the staging/latest tag to the commit of production/latest.
$productionLatest = (git rev-list --max-count=1 '${{ inputs.tag-prefix }}/latest')
git tag --delete '${{ inputs.tag-prefix }}/latest'
git push origin ':refs/tags/${{ inputs.tag-prefix }}/latest'
git tag --delete '${{ inputs.swap-prefix }}/latest'
git push origin ':refs/tags/${{ inputs.swap-prefix }}/latest'
git tag --annotate '${{ inputs.swap-prefix }}/latest' $productionLatest --message 'Latest tag for ${{ inputs.swap-prefix }}'
git push origin 'refs/tags/${{ inputs.swap-prefix }}/latest'
}
git tag --annotate '${{ inputs.tag-prefix }}/latest' $stagingLatest --message 'Latest tag for ${{ inputs.tag-prefix }}'
git push origin 'refs/tags/${{ inputs.tag-prefix }}/latest'
$gitMessage = 'Swap tagged at ${{ steps.create-timestamp.outputs.timestamp-tag }}'
git tag --annotate '${{ inputs.tag-prefix }}/${{ steps.create-timestamp.outputs.timestamp-tag }}' $latest --message $gitMessage
git tag --annotate '${{ inputs.tag-prefix }}/${{ steps.create-timestamp.outputs.timestamp-tag }}' $stagingLatest --message $gitMessage
git push origin 'refs/tags/${{ inputs.tag-prefix }}/${{ steps.create-timestamp.outputs.timestamp-tag }}'
}
else
{
throw "No latest tag found for swap prefix"
throw 'No latest tag found for the swap prefix in the code repo.'
}
Write-Output "::notice::The commit from the app code repository with the SHA $latest was swapped out."
"commit-sha=$latest" >> $Env:GITHUB_OUTPUT
Write-Output "::notice::The commit from the app code repository with the SHA $stagingLatest was swapped out."
"commit-sha=$stagingLatest" >> $Env:GITHUB_OUTPUT
- name: Add Azure Application Insights Release Annotation
uses: Lombiq/GitHub-Actions/.github/actions/add-azure-application-insights-release-annotation@dev
Expand Down

0 comments on commit 4480671

Please sign in to comment.