-
Notifications
You must be signed in to change notification settings - Fork 0
199 lines (171 loc) · 6.46 KB
/
continuous.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
name: continuous
on:
push:
branches:
- main
paths-ignore:
- "README.md"
pull_request:
branches:
- main
release:
types:
- released
- prereleased
workflow_dispatch:
inputs:
deployment-environment:
description: "Deployment environment"
type: environment
required: false
jobs:
build_test:
name: "🚦 Build & Test (Ubuntu 🐧)"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache .nuke/temp, ~/.nuget/packages
uses: actions/cache@v4
with:
path: |
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }}
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: "Build and test"
id: build-test
run: ./build.cmd test integration-test
- name: "Publish test result artifact"
uses: actions/upload-artifact@v4
with:
name: test-results
path: artifacts/test-results
- name: "Publish coverage report artifact"
uses: actions/upload-artifact@v4
with:
name: coverage-report.zip
path: artifacts/reports/coverage-report.zip
setup:
name: "🗺 Setup deployment"
runs-on: ubuntu-latest
needs: build_test
# Deploy when:
# - A deployment environment was specified in the workflow dispatch, OR
# - We are building a release, OR
# - We are building the main branch AND we are NOT building a pull request
if: ${{ inputs.deployment-environment || github.event.release || (github.ref == 'refs/heads/main' && !github.event.pull_request)}}
outputs:
deployment-environment: ${{ steps.set-deployment-targets.outputs.target-environment-name }}
deployment-url-api: ${{ steps.set-deployment-targets.outputs.target-environment-url-api }}
deployment-url-app: ${{ steps.set-deployment-targets.outputs.target-environment-url-app }}
steps:
- name: Determine target deployment environment
id: set-deployment-targets
run: |
IS_MAIN_BRANCH=${{ github.ref == 'refs/heads/main' }}
echo "Building main branch? $IS_MAIN_BRANCH"
IS_PRERELEASE=${{ github.event.release.prerelease != '' }}
echo "Building a prerelease? $IS_PRERELEASE"
IS_RELEASE=${{ github.event.release != '' }}
echo "Building a release (will be true for prerelases)? $IS_RELEASE"
if [[ -n "${{ inputs.deployment-environment }}" ]]; then
TARGET_ENV_NAME=${{ inputs.deployment-environment }}
elif $IS_PRERELEASE; then
TARGET_ENV_NAME="production"
elif $IS_RELEASE; then
TARGET_ENV_NAME="production"
else
TARGET_ENV_NAME="test"
fi
case "$TARGET_ENV_NAME" in
"test")
TARGET_ENV_URL_API="https://test-api.spenses.money"
TARGET_ENV_URL_APP="https://test-app.spenses.money"
;;
"staging")
TARGET_ENV_URL_API="https://staging-api.spenses.money"
TARGET_ENV_URL_APP="https://staging-app.spenses.money"
;;
"production")
TARGET_ENV_URL_API="https://api.spenses.money"
TARGET_ENV_URL_APP="https://app.spenses.money"
;;
esac
echo "Target deployment environment is '$TARGET_ENV_NAME'"
echo "Target deployment URL for API is '$TARGET_ENV_URL_API'"
echo "Target deployment URL for web application is '$TARGET_ENV_URL_APP'"
echo "target-environment-name=$TARGET_ENV_NAME" >> $GITHUB_OUTPUT
echo "target-environment-url-api=$TARGET_ENV_URL_API" >> $GITHUB_OUTPUT
echo "target-environment-url-app=$TARGET_ENV_URL_APP" >> $GITHUB_OUTPUT
deploy_api:
name: "🚀⚙ Deploy API"
runs-on: ubuntu-latest
needs: setup
environment:
name: ${{ needs.setup.outputs.deployment-environment }}
url: ${{ needs.setup.outputs.deployment-url-api }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache .nuke/temp, ~/.nuget/packages
uses: actions/cache@v4
with:
path: |
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }}
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: "Deploy API"
run: ./build.cmd deploy-api
env:
NUKE_AZURE_USERNAME: ${{ vars.AZURE_USERNAME }}
NUKE_AZURE_PASSWORD: ${{ secrets.AZURE_PASSWORD }}
NUKE_AZURE_TENANT: ${{ vars.AZURE_TENANT }}
NUKE_AZURE_RESOURCE_GROUP: ${{ vars.AZURE_RESOURCE_GROUP }}
NUKE_CONTAINER_APP_ENVIRONMENT: ${{ vars.CONTAINER_APP_ENVIRONMENT }}
NUKE_CONTAINER_APP_NAME: ${{ vars.CONTAINER_APP_NAME }}
NUKE_CONTAINER_REGISTRY_NAME: ${{ vars.CONTAINER_REGISTRY_NAME }}
NUKE_CONTAINER_REGISTRY_SERVER: ${{ vars.CONTAINER_REGISTRY_SERVER }}
NUKE_CONTAINER_REGISTRY_USERNAME: ${{ vars.CONTAINER_REGISTRY_USERNAME }}
NUKE_CONTAINER_REGISTRY_PASSWORD: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }}
- name: "Migrate database"
run: ./build.cmd migrate-database
env:
NUKE_SQL_SERVER_CONNECTION_STRING: ${{ secrets.SQL_SERVER_CONNECTION_STRING }}
deploy_web:
name: "🚀🕸 Deploy web app"
runs-on: ubuntu-latest
needs: setup
environment:
name: ${{ needs.setup.outputs.deployment-environment }}
url: ${{ needs.setup.outputs.deployment-url-app }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache .nuke/temp, ~/.nuget/packages
uses: actions/cache@v4
with:
path: |
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }}
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: Install WASM tools workload
run: dotnet workload install wasm-tools
- name: "Deploy web app"
run: ./build.cmd deploy-web-app
env:
NUKE_AZURE_STATIC_WEB_APPS_DEPLOYMENT_TOKEN: ${{ secrets.AZURE_STATIC_WEB_APPS_DEPLOYMENT_TOKEN }}