11name : Build and stage
2+
23on :
34 push :
45 branches :
2021 IMAGE_TAG : ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || github.run_id }}
2122
2223jobs :
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
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 }}
0 commit comments