-
Notifications
You must be signed in to change notification settings - Fork 1
240 lines (207 loc) · 7.81 KB
/
azure-static-web-apps-green-field-0353fee03.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
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
# https://docs.github.com/en/actions/deployment/deploying-to-your-cloud-provider/deploying-to-azure/deploying-to-azure-static-web-app
# For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
# https://learn.microsoft.com/en-us/dotnet/devops/dotnet-test-github-action
name: Kaylumah.nl CI/CD
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, closed, ready_for_review, converted_to_draft]
branches:
- main
permissions:
issues: write
contents: read
pull-requests: write
env:
BuildConfiguration: Release
TargetFramework: net8.0
jobs:
fail_if_pull_request_is_draft:
if: github.event.pull_request.draft == true && (github.event_name == 'pull_request' && github.event.action != 'closed')
runs-on: ubuntu-latest
steps:
- name: Fails in order to indicate that pull request needs to be marked as ready to review and unit tests workflow needs to pass.
run: exit 1
build_and_test:
if: github.event.pull_request.draft == false && (github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed'))
name: Build and Test (for ${{matrix.os}})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest, macOS-latest ]
outputs:
deployUrl: ${{ steps.outputJobVariables.outputs.baseUrl }}
steps:
- uses: actions/checkout@v4
- name: Set TimeZone
uses: hoang-rio/set-timezone@v1.4
with:
timezoneLinux: "Europe/Amsterdam"
timezoneMacos: "Europe/Amsterdam"
timezoneWindows: "W. Europe Standard Time"
- name: Sets env vars for PR
if: github.event_name == 'pull_request'
shell: pwsh
run: |
"PR_BUILD_ID=${{ github.event.number }}" >> $env:GITHUB_ENV
- id: outputJobVariables
shell: pwsh
run: |
$BaseUrl = ./tools/Get-BaseUrl.ps1
"BaseUrl=$BaseUrl" >> $env:GITHUB_OUTPUT
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: Install dependencies
shell: pwsh
run: |
dotnet restore
- name: Install dependencies (tools)
shell: pwsh
run: |
dotnet tool restore
- name: Build
shell: pwsh
run: |
$BuildId = "$env:GITHUB_RUN_ID"
$BuildNumber = "$env:GITHUB_RUN_NUMBER"
$BuildConfiguration = "${{ env.BuildConfiguration }}"
dotnet build --no-restore --configuration $BuildConfiguration /p:BuildId=$BuildId /p:BuildNumber=$BuildNumber /p:Version=1.0.0.$BuildNumber
- name: Test
shell: pwsh
run: |
$BuildConfiguration = "${{ env.BuildConfiguration }}"
dotnet test --no-restore --no-build --configuration $BuildConfiguration --verbosity normal --logger trx test/Unit/Test.Unit.csproj
# Consider naming the log file
# --logger "trx;LogFileName=test-results.trx"
- name: Run SiteGenerator
shell: pwsh
run: |
$BaseUrl = "${{ steps.outputJobVariables.outputs.baseUrl }}"
$BuildConfiguration = "${{ env.BuildConfiguration }}"
$TargetFramework = "${{ env.TargetFramework }}"
dotnet src/Component/Client/SiteGenerator/bin/$BuildConfiguration/$TargetFramework/Kaylumah.Ssg.Client.SiteGenerator.dll Site:Url=$BaseUrl
- name: Upload generated website
uses: actions/upload-artifact@v4
if: matrix.os == 'ubuntu-latest'
with:
name: ${{ format('site-{0}', matrix.os) }}
path: dist
if-no-files-found: error
retention-days: 1
- name: Upload tools
uses: actions/upload-artifact@v4
if: matrix.os == 'ubuntu-latest'
with:
name: ${{ format('tools-{0}', matrix.os) }}
path: tools
if-no-files-found: error
retention-days: 1
- name: Upload API
uses: actions/upload-artifact@v4
if: matrix.os == 'ubuntu-latest'
with:
name: ${{ format('api-{0}', matrix.os) }}
path: api
if-no-files-found: error
retention-days: 1
# Enable the following to do something with snapshot result(s)
# - name: Check Verify Results
# if: always()
# run: |
# $Output = & ./tools/Check-Snapshots.ps1
# # -TargetFolder Test/Unit
# $Output = $Output | % { "." +$_ }
# if ($Output.count -gt 0) {
# New-Item -ItemType Directory "snapshots"
# foreach ($File in $Output) {
# Copy-Item $File -Destination snapshots
# }
# }
# shell: pwsh
# - uses: actions/upload-artifact@v4
# if: always()
# with:
# name: "snapshots-${{matrix.os}}"
# path: snapshots
# if-no-files-found: ignore
# retention-days: 1
deploy:
name: Deploy (for ubuntu-latest)
runs-on: ubuntu-latest
needs: build_and_test
steps:
# Needed until dotnet is publsihed...
- uses: actions/checkout@v4
- name: Download site artifact
uses: actions/download-artifact@v4
with:
name: ${{ format('site-{0}', 'ubuntu-latest') }}
path: dist
- name: Download tools artifact
uses: actions/download-artifact@v4
with:
name: ${{ format('tools-{0}', 'ubuntu-latest') }}
path: tools
- name: Download api artifact
uses: actions/download-artifact@v4
with:
name: ${{ format('api-{0}', 'ubuntu-latest') }}
path: api
- name: Use Node.js v20
uses: actions/setup-node@v4
with:
node-version: 20
- name: Run npm steps
shell: pwsh
run: |
npm i --prefix dist
npm run build:prod --prefix dist
- name: Cleanup
shell: pwsh
run: |
./tools/Clean-Dist.ps1
- name: Print site
shell: pwsh
run: |
tree dist
# Deploy the app to Azure Static Web Apps using the artifacts built previously
- name: Build And Deploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_GREEN_FIELD_0353FEE03 }}
repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
action: "upload"
app_location: "dist"
api_location: "api"
output_location: ""
skip_app_build: true
skip_api_build: false
# Dotnet build is needed so we can use the playwright install
- name: Run E2e
shell: pwsh
env:
PLAYWRIGHT_TEST_BASE_URL: ${{ needs.build_and_test.outputs.deployUrl }}
run: |
Write-Host "Will run E2e against $Env:PLAYWRIGHT_TEST_BASE_URL"
$BuildConfiguration = "${{ env.BuildConfiguration }}"
$TargetFramework = "${{ env.TargetFramework }}"
dotnet build test/E2e --configuration $BuildConfiguration
& ./test/E2e/bin/$BuildConfiguration/$TargetFramework/playwright.ps1 install chromium --with-deps
dotnet test --no-build --configuration $BuildConfiguration test/E2e
close_pull_request:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
name: Close Pull Request
steps:
- name: Close Pull Request
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_GREEN_FIELD_0353FEE03 }}
action: "close"