-
Notifications
You must be signed in to change notification settings - Fork 0
183 lines (149 loc) · 5.58 KB
/
deploy_resources.yml
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# This is a basic workflow to help you get started with Actions
name: Azure CI
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
DOTNET_VERSION: '6.0.x'
API_SOLUTION_PATH: src/SwiftTestingFrameworkAPI/SwiftTestingFrameworkAPI.sln
FUNCTION_SOLUTION_PATH: src/Function/Function.sln
# Controls when the workflow will run
on:
# Triggers the workflow on push to "main" branch
push:
branches: [ "main" ]
workflow_dispatch:
jobs:
get-locations:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.get-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3
- name: Read Locations
id: get-matrix
run: |
content=`cat $GITHUB_WORKSPACE/location_matrix.json`
# the following lines are only required for multi line json
content="${content//'%'/'%25'}"
content="${content//$'\n'/}"
content="${content//$'\r'/'%0D'}"
echo "matrix=$content" >> $GITHUB_OUTPUT
create-resources:
if: "!contains(github.event.commits[0].message, '[skip]')"
needs: get-locations
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.get-locations.outputs.matrix) }}
steps:
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Checkout
uses: actions/checkout@v3
- name: Azure CLI script file
uses: azure/CLI@v1
with:
azcliversion: 2.30.0
inlineScript: |
chmod +x $GITHUB_WORKSPACE/deploy.sh
$GITHUB_WORKSPACE/deploy.sh stf-${{ matrix.location }} ${{ matrix.location }} templates/stf-prod.json
build-api-app:
needs: get-locations
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up .NET Core
uses: actions/setup-dotnet@v2
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Build api with dotnet
run: dotnet build ${{ env.API_SOLUTION_PATH }} --configuration Release
- name: dotnet publish api
run: dotnet publish ${{ env.API_SOLUTION_PATH }} -c Release -o ${{env.DOTNET_ROOT}}/api
- name: Upload api artifact for deployment job
uses: actions/upload-artifact@v3
with:
name: api-app
path: ${{env.DOTNET_ROOT}}/api
retention-days: 1
build-function-app:
needs: get-locations
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v1
- name: Setup NuGet
uses: NuGet/[email protected]
- name: Restore Packages
run: nuget restore ${{ env.FUNCTION_SOLUTION_PATH }}
- name: Build Solution
run: |
msbuild.exe ${{ env.FUNCTION_SOLUTION_PATH }} /p:platform="Any CPU" /p:configuration="Release"
- name: Upload function app artifact
uses: actions/upload-artifact@v3
with:
name: function-app
path: "src/Function/bin/Release/net48/"
retention-days: 1
deploy:
needs: [build-api-app, build-function-app, create-resources, get-locations]
runs-on: ubuntu-latest
if: ${{ !failure() && !cancelled()}}
continue-on-error: true
strategy:
matrix: ${{ fromJson(needs.get-locations.outputs.matrix) }}
steps:
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true
- name: Checkout
uses: actions/checkout@v1
- name: Download api artifact from build job
uses: actions/download-artifact@v3
with:
name: api-app
path: api-app
- name: Download function app artifact from build job
uses: actions/download-artifact@v3
with:
name: function-app
path: function-app
- name: Run Azure PowerShell script
uses: azure/powershell@v1
id: getPublishProfile
with:
inlineScript: |
$publish_profile_winapp=Get-AzWebAppPublishingProfile -ResourceGroupName stf-${{ matrix.location }} -Name "stf-${{ matrix.location }}-winapp"
$publish_profile_linuxapp=Get-AzWebAppPublishingProfile -ResourceGroupName stf-${{ matrix.location }} -Name "stf-${{ matrix.location }}-linuxapp"
$publish_profile_functionapp=Get-AzWebAppPublishingProfile -ResourceGroupName stf-${{ matrix.location }} -Name "stf-${{ matrix.location }}-functionapp"
echo "publish_profile_winapp=$($publish_profile_winapp)" >> $GITHUB_OUTPUT
echo "publish_profile_linuxapp=$($publish_profile_linuxapp)" >> $GITHUB_OUTPUT
echo "publish_profile_functionapp=$( $publish_profile_functionapp)" >> $GITHUB_OUTPUT
azPSVersion: "latest"
- name: Deploy to Azure Windows Web App
id: deploy-to-windows-webapp
uses: azure/webapps-deploy@v2
with:
app-name: stf-${{ matrix.location }}-winapp
publish-profile: ${{ steps.getPublishProfile.outputs.publish_profile_winapp }}
package: api-app
- name: Deploy to Azure Linux Web App
id: deploy-to-linux-webapp
uses: azure/webapps-deploy@v2
with:
app-name: stf-${{ matrix.location }}-linuxapp
publish-profile: ${{ steps.getPublishProfile.outputs.publish_profile_linuxapp }}
package: api-app
- name: Deploy to Azure Functions App
id: deploy-to-functionapp
uses: Azure/functions-action@v1
with:
app-name: stf-${{ matrix.location }}-functionapp
publish-profile: ${{ steps.getPublishProfile.outputs.publish_profile_functionapp }}
package: function-app