Skip to content

Commit d3fa90e

Browse files
committed
separate build and deploy as jobs, update actions, align styles
1 parent 500b421 commit d3fa90e

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

.github/workflows/build-and-stage.yml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: Build and stage
2+
23
on:
34
push:
45
branches:
@@ -20,13 +21,8 @@ env:
2021
IMAGE_TAG: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || github.run_id }}
2122

2223
jobs:
23-
build-push-deploy:
24+
build-push:
2425
name: Build and push image
25-
environment:
26-
name: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || vars.STAGING_SLOT_NAME }}
27-
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
28-
env:
29-
SLOT_NAME: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || vars.STAGING_SLOT_NAME }}
3026
runs-on: ubuntu-latest
3127
steps:
3228
- uses: actions/checkout@v4
@@ -49,11 +45,6 @@ jobs:
4945
echo "TEMPLATE_CHECKOUT_TARGET=$CheckoutTarget" >> $GITHUB_ENV
5046
fi
5147
52-
- name: Login to Azure
53-
uses: azure/login@v1
54-
with:
55-
creds: ${{ secrets.AZURE_CREDENTIALS }}
56-
5748
- name: Login to container registry
5849
uses: azure/docker-login@v1
5950
with:
@@ -67,13 +58,29 @@ jobs:
6758
- name: Push image
6859
run: docker push ${{ vars.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
6960

61+
deploy:
62+
name: Deploy
63+
if: ${{ github.secret_source == 'Actions' }}
64+
environment:
65+
name: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || vars.STAGING_SLOT_NAME }}
66+
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
67+
env:
68+
SLOT_NAME: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || vars.STAGING_SLOT_NAME }}
69+
needs: build-push
70+
runs-on: ubuntu-latest
71+
steps:
72+
- name: Login to Azure
73+
uses: azure/login@v2
74+
with:
75+
creds: ${{ secrets.AZURE_CREDENTIALS }}
76+
7077
- name: If PR, create a new staging slot
7178
if: ${{ github.event_name == 'pull_request' }}
7279
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 }}
7380

7481
- name: Deploy to staging slot
75-
uses: azure/webapps-deploy@v3
7682
id: deploy-to-webapp
83+
uses: azure/webapps-deploy@v3
7784
with:
7885
app-name: ${{ vars.AZURE_WEBAPP_NAME }}
7986
images: ${{ vars.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}

.github/workflows/pr-cleanup.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ name: Delete a preview environment
22

33
on:
44
pull_request:
5-
types: [closed]
5+
types:
6+
- closed
67

78
env:
89
SLOT_NAME: pr-${{ github.event.number }}
@@ -13,20 +14,20 @@ jobs:
1314

1415
steps:
1516
- name: Log into Azure CLI with service principal
16-
uses: azure/login@v1
17+
uses: azure/login@v2
1718
with:
1819
creds: ${{ secrets.AZURE_CREDENTIALS }}
19-
20+
2021
- name: Delete slot on staging site
2122
run: az webapp deployment slot delete --resource-group ${{ vars.AZURE_RESOURCE_GROUP }} --name ${{ vars.AZURE_WEBAPP_NAME}} --slot ${{ env.SLOT_NAME }}
2223

2324
delete-deployment:
2425
runs-on: ubuntu-latest
26+
permissions: write-all
2527

2628
steps:
2729
- name: Delete Deployment Environment
28-
uses: strumwolf/delete-deployment-environment@v2
30+
uses: strumwolf/delete-deployment-environment@v3
2931
with:
3032
environment: "pr-${{ github.event.number }}"
3133
token: ${{ secrets.GITHUB_TOKEN }}
32-
onlyRemoveDeployments: true

.github/workflows/stage-prod-swap.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ jobs:
88
name: Promote to production
99
runs-on: ubuntu-latest
1010
environment:
11-
name: 'Production'
11+
name: Production
1212
url: 'https://${{ vars.AZURE_WEBAPP_NAME }}.azurewebsites.net/'
1313

1414
steps:
1515
- name: Log into Azure CLI with service principal
16-
uses: azure/login@v1
16+
uses: azure/login@v2
1717
with:
1818
creds: ${{ secrets.AZURE_CREDENTIALS }}
1919

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

0 commit comments

Comments
 (0)