-
Notifications
You must be signed in to change notification settings - Fork 8
101 lines (81 loc) · 2.98 KB
/
deploy-pull-request.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: Deploy PR to staging env
# Note: For this to work you must
# 1) Create the service principal:
# az ad sp create-for-rbac --name "mars-rover-sp" --sdk-auth --role contributor --scopes /subscriptions/53a27438-41b3-4bcb-90fc-76fa03e0b11f/resourceGroups/mars_rover/providers/Microsoft.Web/sites/snow-rover
# Then put the json you get back from that command into a secret named AZURE_CREDENTIALS
# 2) change the WEBAPP_NAME and RESOURCE_NAME below
on:
pull_request:
branches:
- main
concurrency: ci-${{ github.event.number }}
env:
WEBAPP_NAME: snow-rover
RESOURCE_GROUP: mars_rover
SLOT_NAME: pr-${{ github.event.number }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '7.x'
include-prerelease: true
- name: Run Tests
working-directory: src
run: dotnet test MarsRover.sln
- name: dotnet publish
working-directory: src/Mars.Web
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v2
with:
name: .net-app
path: ${{env.DOTNET_ROOT}}/myapp
set-up-test-env:
name: Create test env
runs-on: ubuntu-latest
steps:
- name: Log into Azure CLI with service principal
uses: azure/[email protected]
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Create slot on staging site
run: az webapp deployment slot create --resource-group $RESOURCE_GROUP --name $WEBAPP_NAME --slot $SLOT_NAME
deploy:
name: Deploy to test env
runs-on: ubuntu-latest
needs: [build, set-up-test-env]
environment:
name: "PR #${{ github.event.number }}"
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
permissions:
pull-requests: write
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v2
with:
name: .net-app
- name: Log into Azure CLI with service principal
uses: azure/[email protected]
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Deploy to slot on staging site
uses: azure/webapps-deploy@v2
id: deploy-to-webapp
with:
app-name: ${{ env.WEBAPP_NAME }}
slot-name: ${{ env.SLOT_NAME }}
package: .
- name: Comment on PR with the preview link
uses: mshick/add-pr-comment@v1
with:
message: |
## Preview link: https://${{ env.WEBAPP_NAME }}-${{env.SLOT_NAME }}.azurewebsites.net
- Your changes have been deployed to the preview site. The preview site will update as you add more commits to this branch.
- The preview link is shareable, but will be deleted when the pull request is merged or closed.
> *This is an automated message.*
repo-token: ${{ secrets.GITHUB_TOKEN }}
repo-token-user-login: 'github-actions[bot]'