6
6
pull_request :
7
7
branches :
8
8
- main
9
- env :
10
- DOTNET_CLI_TELEMETRY_OPTOUT : 1
11
- DOTNET_SKIP_FIRST_TIME_EXPERIENCE : true
12
- DOTNET_VERSION : ' 8.0'
13
9
14
10
concurrency :
15
11
group : ${{ github.workflow }}-${{ github.ref }}
16
12
cancel-in-progress : true
17
13
18
14
permissions :
19
- checks : write
20
15
contents : read
21
- statuses : write
16
+ pull-requests : ' write'
17
+
18
+ env :
19
+ IMAGE_NAME : net-core-tool-service
20
+ IMAGE_TAG : ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || github.run_id }}
22
21
23
22
jobs :
24
- build :
25
- name : Build and publish app
23
+ build-push-deploy :
24
+ 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 }}
26
30
runs-on : ubuntu-latest
27
31
steps :
28
32
- uses : actions/checkout@v4
29
33
with :
30
34
fetch-depth : 0 # avoid shallow clone so nbgv can do its work.
31
35
32
- - name : Set up .NET Core
33
- uses : actions/setup-dotnet@v4
36
+ - name : Login to Azure
37
+ uses : azure/login@v1
34
38
with :
35
- dotnet-version : ${{ env.DOTNET_VERSION }}
39
+ creds : ${{ secrets.AZURE_CREDENTIALS }}
36
40
37
- - name : Set up dependency caching for faster builds
38
- uses : actions/cache@v4
41
+ - name : Login to container registry
42
+ uses : azure/docker-login@v1
39
43
with :
40
- path : ~/.nuget/packages
41
- key : ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
42
- restore-keys : |
43
- ${{ runner.os }}-nuget-
44
-
45
- - name : dotnet restore
46
- run : dotnet restore
44
+ login-server : " ${{ vars.DOCKER_REGISTRY }}"
45
+ username : " ${{ secrets.DOCKER_USERNAME }}"
46
+ password : " ${{ secrets.DOCKER_PASSWORD }}"
47
47
48
- - name : dotnet build
49
- run : dotnet build --no-restore /p:TreatWarningsAsErrors=True
48
+ - name : Build image
49
+ run : docker build . --file "Dockerfile" -t ${{ vars.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
50
50
51
- - name : dotnet test
52
- run : dotnet test --logger trx --results-directory " ${{ runner.temp }}" --no-build
51
+ - name : Push image
52
+ run : docker push ${{ vars.DOCKER_REGISTRY }}/ ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
53
53
54
- - name : dotnet test
55
- uses : NasAmin/trx-parser@v0.5.0
56
- with :
57
- TRX_PATH : " ${{ runner.temp }}"
58
- REPO_TOKEN : " ${{ secrets.GITHUB_TOKEN }}"
59
-
60
- - name : dotnet publish
61
- run : dotnet publish src/NetCoreToolService/Steeltoe.NetCoreToolService.csproj -o publish
62
-
63
- - name : Upload artifact for deployment job
64
- if : ${{ github.event_name != 'pull_request' }}
65
- uses : actions/upload-artifact@v4
66
- with :
67
- name : published-app
68
- path : publish
54
+ - name : If PR, create a new staging slot
55
+ if : ${{ github.event_name == 'pull_request' }}
56
+ 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 }}
69
57
70
- deploy :
71
- name : Deploy
72
- environment : production
73
- needs :
74
- - build
75
- runs-on : ubuntu-latest
76
- if : ${{ github.event_name != 'pull_request' }}
77
- steps :
78
- - name : Download artifact from build job
79
- uses : actions/download-artifact@v4
80
- with :
81
- name : published-app
82
-
83
- - name : Log into Azure CLI with service principal
84
- uses : azure/login@v1
85
- with :
86
- creds : ${{ secrets.AZURE_CREDENTIALS }}
87
-
88
- - name : Deploy to Azure Web App
89
- id : deploy-to-webapp
58
+ - name : Deploy to staging slot
90
59
uses : azure/webapps-deploy@v3
91
- with :
60
+ id : deploy-to-webapp
61
+ with :
92
62
app-name : ${{ vars.AZURE_WEBAPP_NAME }}
93
- package : ' .'
94
- slot-name : ' production'
63
+ images : ${{ vars.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
64
+ slot-name : ${{ env.SLOT_NAME }}
65
+
66
+ - name : If PR, comment with the preview link
67
+ if : ${{ github.event_name == 'pull_request' }}
68
+ uses : mshick/add-pr-comment@v2
69
+ with :
70
+ message : |
71
+ ## Preview link: https://${{ vars.AZURE_WEBAPP_NAME }}-${{ env.SLOT_NAME }}.azurewebsites.net
72
+
73
+ - Your changes have been deployed to the preview site. The preview site will update as you add more commits to this branch.
74
+ - The preview link is shareable, but will be deleted when the pull request is merged or closed.
75
+
76
+ > *This is an automated message.*
77
+ repo-token : ${{ secrets.GITHUB_TOKEN }}
78
+
0 commit comments