Skip to content

Commit

Permalink
add PR cleanup, swap to prod workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
TimHess committed Feb 9, 2024
1 parent 567e6ec commit 0b7a788
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:

- name: If PR, create a new staging slot
if: ${{ github.event_name == 'pull_request' }}
run: az webapp deployment slot create --resource-group ${{ vars.AZURE_RESOURCE_GROUP }} --name ${{ vars.AZURE_WEBAPP_NAME}} --slot ${{ env.SLOT_NAME }} --configuration-source staging
run: az webapp deployment slot create --resource-group ${{ vars.AZURE_RESOURCE_GROUP }} --name ${{ vars.AZURE_WEBAPP_NAME}} --slot ${{ env.SLOT_NAME }} --configuration-source ${{ vars.STAGING_SLOT_NAME }}

- name: Deploy to staging slot
uses: azure/webapps-deploy@v3
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/pr-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Delete a preview environment

on:
pull_request:
types: [closed]

env:
SLOT_NAME: pr-${{ github.event.number }}

jobs:
delete-slot:
runs-on: ubuntu-latest

steps:
- name: Log into Azure CLI with service principal
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Delete slot on staging site
run: az webapp deployment slot delete --resource-group ${{ vars.AZURE_RESOURCE_GROUP }} --name ${{ vars.AZURE_WEBAPP_NAME}} --slot ${{ env.SLOT_NAME }}

delete-deployment:
runs-on: ubuntu-latest

steps:
- name: Delete Deployment Environment
uses: strumwolf/delete-deployment-environment@v2
with:
environment: "pr-${{ github.event.number }}"
token: ${{ secrets.GITHUB_TOKEN }}
onlyRemoveDeployments: true
22 changes: 22 additions & 0 deletions .github/workflows/stage-prod-swap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Swap staging slot contents into production

on:
workflow_dispatch:

jobs:
promote-to-production:
name: Promote to production
runs-on: ubuntu-latest
environment:
name: 'Production'
url: 'https://${{ vars.AZURE_WEBAPP_NAME }}.azurewebsites.net/'

steps:
- name: Log into Azure CLI with service principal
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Swap slots
run: az webapp deployment slot swap -s ${{ vars.STAGING_SLOT_NAME }} -n ${{ vars.AZURE_WEBAPP_NAME }} -g ${{ vars.AZURE_RESOURCE_GROUP }}

0 comments on commit 0b7a788

Please sign in to comment.