forked from dotnet/try
-
Notifications
You must be signed in to change notification settings - Fork 1
251 lines (210 loc) · 9.25 KB
/
Build-Test-And-Deploy.yaml
File metadata and controls
251 lines (210 loc) · 9.25 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
name: Build, Test, and Deploy Try .NET API
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
workflow_dispatch:
permissions:
id-token: write
contents: read
jobs:
build-and-test:
runs-on: ubuntu-latest
environment: "BuildAndUploadImage"
steps:
- uses: actions/checkout@v6
- name: Set up Node.js environment
uses: ./.github/actions/setup-node
- name: Set up .NET environment
uses: ./.github/actions/setup-dotnet
- name: Run ciTest for microsoft-trydotnet
working-directory: src/microsoft-trydotnet
run: npm run ciTest
- name: Run ciTest for microsoft-trydotnet-editor
working-directory: src/microsoft-trydotnet-editor
run: npm run ciTest
- name: Run .NET Tests
id: run-dotnet-tests
run: dotnet test --no-build --configuration Release --blame-hang-timeout 15m --blame-hang-dump-type full -l trx --results-directory ./TestResults --filter TestType!=Integration
env:
POCKETLOGGER_LOG_PATH: ${{ github.workspace }}/artifacts/logs/pocketlogger.log
- name: Convert TRX to Playlist
if: ${{ steps.run-dotnet-tests.outcome == 'failure' || failure() }}
uses: BenjaminMichaelis/trx-to-vsplaylist@v3
with:
trx-file-path: './TestResults/*.trx'
test-outcomes: 'Failed'
artifact-name: 'linux-test-playlists'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Build but no push with a PR
- name: Docker build (no push)
if: github.event_name == 'pull_request' || github.event_name == 'merge_group'
uses: docker/build-push-action@v6
with:
push: false
tags: temp-pr-validation
file: ./Dockerfile
- name: Build Container Image
if: github.event_name != 'pull_request_target' && github.event_name != 'pull_request'
uses: docker/build-push-action@v6
with:
tags: ${{ vars.DEVCONTAINER_REGISTRY }}/try:${{ github.sha }},${{ vars.DEVCONTAINER_REGISTRY }}/try:latest,${{ vars.PRODCONTAINER_REGISTRY }}/try:${{ github.sha }},${{ vars.PRODCONTAINER_REGISTRY }}/try:latest
file: ./Dockerfile
context: .
outputs: type=docker,dest=${{ github.workspace }}/tryimage.tar
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Upload artifact
if: github.event_name != 'pull_request_target' && github.event_name != 'pull_request'
uses: actions/upload-artifact@v6
with:
name: tryimage
path: ${{ github.workspace }}/tryimage.tar
build-and-test-windows:
# Ensures .NET build and unit tests pass on Windows, matching the original
# Azure DevOps Windows_NT job. Integration tests are covered separately.
runs-on: windows-latest
steps:
- uses: actions/checkout@v6
- name: Set up Node.js environment
uses: ./.github/actions/setup-node
- name: Set up .NET environment
uses: ./.github/actions/setup-dotnet
- name: Run .NET Tests
id: run-dotnet-tests
run: dotnet test --no-build --configuration Release --blame-hang-timeout 15m --blame-hang-dump-type full -l trx --results-directory ./TestResults --filter TestType!=Integration
env:
POCKETLOGGER_LOG_PATH: ${{ github.workspace }}/artifacts/logs/pocketlogger.log
- name: Convert TRX to Playlist
if: ${{ steps.run-dotnet-tests.outcome == 'failure' || failure() }}
uses: BenjaminMichaelis/trx-to-vsplaylist@v3
with:
trx-file-path: './TestResults/*.trx'
test-outcomes: 'Failed'
artifact-name: 'windows-test-playlists'
integration-tests:
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
browser: [chromium, firefox, webkit]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6
- name: Set up Node.js environment
uses: ./.github/actions/setup-node
- name: Set up .NET environment
uses: ./.github/actions/setup-dotnet
with:
configuration: Debug
- name: Ensure browsers are installed
run: pwsh bin/Debug/net10.0/playwright.ps1 install --with-deps
- name: Run .NET Integration Tests
id: run-dotnet-integration-tests
run: dotnet test --no-build --configuration Debug --blame-hang-timeout 15m --blame-hang-dump-type full -l trx --results-directory ./TestResults --filter TestType=Integration -- Playwright.BrowserName=${{ matrix.browser }}
env:
RunIntegrationTests: true
POCKETLOGGER_LOG_PATH: ${{ github.workspace }}/artifacts/logs/pocketlogger.log
TRYDOTNET_PREBUILDS_PATH: ${{ github.workspace }}/artifacts/trydotnet-prebuilds
- name: Convert TRX to Playlist
if: ${{ steps.run-dotnet-integration-tests.outcome == 'failure' || failure() }}
uses: BenjaminMichaelis/trx-to-vsplaylist@v3
with:
trx-file-path: './TestResults/*.trx'
test-outcomes: 'Failed'
artifact-name: 'integration-test-playlists'
deploy-development:
if: github.event_name != 'pull_request_target' && github.event_name != 'pull_request'
runs-on: ubuntu-latest
needs: [build-and-test, build-and-test-windows, integration-tests]
environment:
name: "Development"
permissions:
id-token: write
contents: read
steps:
- name: Azure Login
uses: azure/login@v2
with:
client-id: ${{ secrets.ESSENTIALCSHARPDEV_CLIENT_ID }}
tenant-id: ${{ secrets.ESSENTIALCSHARP_TENANT_ID }}
subscription-id: ${{ secrets.ESSENTIALCSHARP_SUBSCRIPTION_ID }}
- name: Download artifact
uses: actions/download-artifact@v7
with:
name: tryimage
path: ${{ github.workspace }}
- name: Load image
run: |
docker load --input ${{ github.workspace }}/tryimage.tar
docker image ls -a
- name: Log in to container registry
uses: docker/login-action@v3
with:
registry: ${{ vars.DEVCONTAINER_REGISTRY }}
username: ${{ secrets.ESSENTIALCSHARP_ACR_USERNAME }}
password: ${{ secrets.ESSENTIALCSHARP_ACR_PASSWORD }}
- name: Push Image to Container Registry
env:
REGISTRY_URL: ${{ vars.DEVCONTAINER_REGISTRY }}
run: docker push --all-tags $REGISTRY_URL/try
- name: Create and Deploy to Container App
uses: azure/CLI@v2
env:
CONTAINER_APP_NAME: ${{ vars.CONTAINER_APP_NAME }}
RESOURCEGROUP: ${{ vars.RESOURCEGROUP }}
CONTAINER_APP_ENVIRONMENT: ${{ vars.CONTAINER_APP_ENVIRONMENT }}
REGISTRY_URL: ${{ vars.DEVCONTAINER_REGISTRY }}
ACR_USERNAME: ${{ secrets.ESSENTIALCSHARP_ACR_USERNAME }}
ACR_PASSWORD: ${{ secrets.ESSENTIALCSHARP_ACR_PASSWORD }}
with:
inlineScript: |
az config set extension.use_dynamic_install=yes_without_prompt
az containerapp up -n $CONTAINER_APP_NAME -g $RESOURCEGROUP --image $REGISTRY_URL/try:${{ github.sha }} --environment $CONTAINER_APP_ENVIRONMENT --registry-server $REGISTRY_URL --ingress external --registry-username $ACR_USERNAME --registry-password $ACR_PASSWORD --target-port 80 --debug
deploy-production:
if: github.event_name != 'pull_request_target' && github.event_name != 'pull_request'
runs-on: ubuntu-latest
needs: deploy-development
environment:
name: "Production"
permissions:
id-token: write
contents: read
steps:
- name: Azure Login
uses: azure/login@v2
with:
client-id: ${{ secrets.ESSENTIALCSHARP_CLIENT_ID }}
tenant-id: ${{ secrets.ESSENTIALCSHARP_TENANT_ID }}
subscription-id: ${{ secrets.ESSENTIALCSHARP_SUBSCRIPTION_ID }}
- name: Download artifact
uses: actions/download-artifact@v7
with:
name: tryimage
path: ${{ github.workspace }}
- name: Load image
run: |
docker load --input ${{ github.workspace }}/tryimage.tar
docker image ls -a
- name: Log in to container registry
uses: docker/login-action@v3
with:
registry: ${{ vars.PRODCONTAINER_REGISTRY }}
username: ${{ secrets.ESSENTIALCSHARP_CLIENT_ID }}
password: ${{ secrets.ESSENTIALCSHARP_CLIENT_SECRET }}
- name: Push Image to Container Registry
run: docker push --all-tags ${{ vars.PRODCONTAINER_REGISTRY }}/try
- name: Create and Deploy to Container App
uses: azure/CLI@v2
env:
CONTAINER_APP_NAME: ${{ vars.CONTAINER_APP_NAME }}
RESOURCEGROUP: ${{ vars.RESOURCEGROUP }}
CONTAINER_APP_ENVIRONMENT: ${{ vars.CONTAINER_APP_ENVIRONMENT }}
REGISTRY_URL: ${{ vars.PRODCONTAINER_REGISTRY }}
ACR_USERNAME: ${{ secrets.ESSENTIALCSHARP_ACR_USERNAME }}
ACR_PASSWORD: ${{ secrets.ESSENTIALCSHARP_ACR_PASSWORD }}
with:
inlineScript: |
az config set extension.use_dynamic_install=yes_without_prompt
az containerapp up -n $CONTAINER_APP_NAME -g $RESOURCEGROUP --image $REGISTRY_URL/try:${{ github.sha }} --environment $CONTAINER_APP_ENVIRONMENT --registry-server $REGISTRY_URL --ingress external --target-port 80 --debug