-
Notifications
You must be signed in to change notification settings - Fork 13
78 lines (64 loc) · 1.92 KB
/
deploy-main-branch.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
name: Release to prod
on:
push:
branches:
- main
env:
WEBAPP_NAME: replace-with-your-webapp-name
RESOURCE_GROUP: replace-with-your-rg-name
SLOT_NAME: staging # Create a slot on your web app called "staging"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@v1
- name: Set up Java 11
uses: actions/setup-java@v3
with:
java-version: 11
distribution: microsoft
- name: Build app
run: mvn clean package
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v2
with:
name: java-app
path: '${{ github.workspace }}/target/*.war'
deploy-to-stage:
name: Deploy to staging
needs: build
runs-on: ubuntu-latest
environment:
name: 'Staging'
url: ${{ steps.deploy-to-stage.outputs.webapp-url }}
steps:
- name: Log into Azure CLI with service principal
uses: azure/[email protected]
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Download artifact from build job
uses: actions/download-artifact@v2
with:
name: java-app
- name: Deploy to stage env
uses: azure/webapps-deploy@v1
id: deploy-to-stage
with:
app-name: ${{ env.WEBAPP_NAME }}
slot-name: ${{ env.SLOT_NAME }}
package: '*.war'
release-to-prod:
name: Release to prod
needs: deploy-to-stage
runs-on: ubuntu-latest
environment:
name: 'Production'
url: 'https://${{ env.WEBAPP_NAME }}.azurewebsites.net/'
steps:
- name: Log into Azure CLI with service principal
uses: azure/[email protected]
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Swap slots
run: az webapp deployment slot swap -s ${{ env.SLOT_NAME }} -n ${{ env.WEBAPP_NAME }} -g ${{ env.RESOURCE_GROUP }}