1
1
name : Build and stage
2
+
2
3
on :
3
4
push :
4
5
branches :
@@ -13,30 +14,36 @@ concurrency:
13
14
14
15
permissions :
15
16
contents : read
16
- pull-requests : ' write'
17
+ pull-requests : write
17
18
18
19
env :
19
20
IMAGE_NAME : net-core-tool-service
20
21
IMAGE_TAG : ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || github.run_id }}
21
22
22
23
jobs :
23
- build-push-deploy :
24
+ build-push :
24
25
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 }}
30
26
runs-on : ubuntu-latest
31
27
steps :
32
28
- uses : actions/checkout@v4
33
29
with :
34
30
fetch-depth : 0 # avoid shallow clone so nbgv can do its work.
35
31
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
40
47
41
48
- name : Login to container registry
42
49
uses : azure/docker-login@v1
@@ -46,33 +53,48 @@ jobs:
46
53
password : " ${{ secrets.DOCKER_PASSWORD }}"
47
54
48
55
- 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 }}
50
57
51
58
- name : Push image
52
59
run : docker push ${{ vars.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
53
60
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
+
54
77
- name : If PR, create a new staging slot
55
78
if : ${{ github.event_name == 'pull_request' }}
56
79
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 }}
57
80
58
81
- name : Deploy to staging slot
59
- uses : azure/webapps-deploy@v3
60
82
id : deploy-to-webapp
61
- with :
83
+ uses : azure/webapps-deploy@v3
84
+ with :
62
85
app-name : ${{ vars.AZURE_WEBAPP_NAME }}
63
86
images : ${{ vars.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
64
87
slot-name : ${{ env.SLOT_NAME }}
65
-
88
+
66
89
- name : If PR, comment with the preview link
67
90
if : ${{ github.event_name == 'pull_request' }}
68
91
uses : mshick/add-pr-comment@v2
69
92
with :
70
93
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
+
73
96
- Your changes have been deployed to the preview site. The preview site will update as you add more commits to this branch.
74
97
- The preview link is shareable, but will be deleted when the pull request is merged or closed.
75
98
76
99
> *This is an automated message.*
77
100
repo-token : ${{ secrets.GITHUB_TOKEN }}
78
-
0 commit comments