Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSOE-899: Fixing swap workflow tag management #385

Merged
merged 8 commits into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading