11name : Build and stage
2+
23on :
34 push :
45 branches :
@@ -13,30 +14,36 @@ concurrency:
1314
1415permissions :
1516 contents : read
16- pull-requests : ' write'
17+ pull-requests : write
1718
1819env :
1920 IMAGE_NAME : net-core-tool-service
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
3329 with :
3430 fetch-depth : 0 # avoid shallow clone so nbgv can do its work.
3531
36- - name : Login to Azure
37- uses : azure/login@v1
38- with :
39- creds : ${{ secrets.AZURE_CREDENTIALS }}
32+ - name : Detect template source from PR body
33+ env :
34+ PullRequestBody : ${{ github.event.pull_request.body }}
35+ run : |
36+ cat << EOF > /tmp/pull_request_body.txt
37+ $PullRequestBody
38+ EOF
39+
40+ CheckoutTarget=$(grep "template_checkout_target=" /tmp/pull_request_body.txt | awk -F= '{print $2}')
41+ if [ "$CheckoutTarget" = "" ]; then
42+ echo "Did not find a checkout target for templates."
43+ else
44+ echo "Found checkout target '$CheckoutTarget' in PR body, this build will use templates from source."
45+ echo "TEMPLATE_CHECKOUT_TARGET=$CheckoutTarget" >> $GITHUB_ENV
46+ fi
4047
4148 - name : Login to container registry
4249 uses : azure/docker-login@v1
@@ -46,33 +53,48 @@ jobs:
4653 password : " ${{ secrets.DOCKER_PASSWORD }}"
4754
4855 - name : Build image
49- run : docker build . --file "Dockerfile" - t ${{ vars.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
56+ run : docker build . -t ${{ vars.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} --build-arg TEMPLATE_CHECKOUT_TARGET=${{ env.TEMPLATE_CHECKOUT_TARGET }}
5057
5158 - name : Push image
5259 run : docker push ${{ vars.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
5360
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+
5477 - name : If PR, create a new staging slot
5578 if : ${{ github.event_name == 'pull_request' }}
5679 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 }}
5780
5881 - name : Deploy to staging slot
59- uses : azure/webapps-deploy@v3
6082 id : deploy-to-webapp
61- with :
83+ uses : azure/webapps-deploy@v3
84+ with :
6285 app-name : ${{ vars.AZURE_WEBAPP_NAME }}
6386 images : ${{ vars.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
6487 slot-name : ${{ env.SLOT_NAME }}
65-
88+
6689 - name : If PR, comment with the preview link
6790 if : ${{ github.event_name == 'pull_request' }}
6891 uses : mshick/add-pr-comment@v2
6992 with :
7093 message : |
71- ## Preview link: https://${{ vars.AZURE_WEBAPP_NAME }}-${{ env.SLOT_NAME }}.azurewebsites.net
72-
94+ ## Preview link: https://${{ vars.AZURE_WEBAPP_NAME }}-${{ env.SLOT_NAME }}.azurewebsites.net
95+
7396 - Your changes have been deployed to the preview site. The preview site will update as you add more commits to this branch.
7497 - The preview link is shareable, but will be deleted when the pull request is merged or closed.
7598
7699 > *This is an automated message.*
77100 repo-token : ${{ secrets.GITHUB_TOKEN }}
78-
0 commit comments