-
Notifications
You must be signed in to change notification settings - Fork 0
209 lines (170 loc) · 6.14 KB
/
Copy pathdotnet.yml
File metadata and controls
209 lines (170 loc) · 6.14 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
name: .NET API Tests, Docker Build & Deploy
on:
push:
branches: [ Prod ]
pull_request:
branches: [ Prod ]
permissions:
contents: write
checks: write
pull-requests: write
packages: write
env:
IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/tablemaster-api
jobs:
build-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: ['10.0.x']
steps:
- uses: actions/checkout@v4
- name: Setup .NET ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ matrix.dotnet-version }}
include-prerelease: true
- name: Restore dependencies
run: |
dotnet restore TableMasterApi/TableMasterApi.csproj
dotnet restore TableMasterApi.Tests/TableMasterApi.Tests.csproj
- name: Audit vulnerable dependencies
run: >
dotnet package list
--project TableMasterApi/TableMasterApi.csproj
--vulnerable
--include-transitive
- name: Report outdated dependencies
run: >
dotnet package list
--project TableMasterApi/TableMasterApi.csproj
--outdated
--include-transitive
| tee dotnet-outdated.txt
- name: Build
run: |
dotnet build TableMasterApi/TableMasterApi.csproj --no-restore --configuration Release
dotnet build TableMasterApi.Tests/TableMasterApi.Tests.csproj --no-restore --configuration Release
- name: Run Unit Tests
run: >
dotnet test TableMasterApi.Tests/TableMasterApi.Tests.csproj
--no-build
--configuration Release
--verbosity normal
--logger "trx;LogFileName=test-results.trx"
- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: |
**/test-results.trx
dotnet-outdated.txt
- name: Test Report
if: always()
uses: dorny/test-reporter@v1
with:
name: .NET Test Results
path: '**/test-results.trx'
reporter: 'dotnet-trx'
docker-build-and-push:
name: Build and push Docker image
runs-on: ubuntu-latest
needs: build-and-test
if: github.event_name == 'push' && github.ref == 'refs/heads/Prod'
steps:
- uses: actions/checkout@v4
- name: Normalize image name
run: |
IMAGE_NAME_LOWER=$(echo "${IMAGE_NAME}" | tr '[:upper:]' '[:lower:]')
echo "IMAGE_NAME_LOWER=$IMAGE_NAME_LOWER" >> $GITHUB_ENV
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push API image
uses: docker/build-push-action@v6
with:
context: .
file: ./TableMasterApi/Dockerfile
push: true
tags: |
${{ env.IMAGE_NAME_LOWER }}:prod
${{ env.IMAGE_NAME_LOWER }}:${{ github.sha }}
deploy:
name: Deploy to Oracle VPS
runs-on: ubuntu-latest
needs: docker-build-and-push
if: github.event_name == 'push' && github.ref == 'refs/heads/Prod'
steps:
- name: Prepare SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.ORACLE_SSH_KEY_B64 }}" | base64 -d > ~/.ssh/oracle_key
chmod 600 ~/.ssh/oracle_key
ssh-keyscan -H ${{ secrets.ORACLE_HOST }} >> ~/.ssh/known_hosts
- name: Deploy with Docker Compose
run: |
ssh -i ~/.ssh/oracle_key ${{ secrets.ORACLE_USER }}@${{ secrets.ORACLE_HOST }} << 'EOF'
set -e
cd /opt/tablemaster/prod/TableMasterApi
git fetch origin Prod
git reset --hard origin/Prod
test -f .env
test -f tablemaster-firebase.json
echo "${{ secrets.GHCR_READ_TOKEN }}" | docker login ghcr.io -u "${{ secrets.GHCR_USERNAME }}" --password-stdin
chmod +x ../ops/*.sh
API_IMAGE_TAG="${{ github.sha }}" \
APP_VERSION="1.0.2+${{ github.run_number }}" \
SENTRY_RELEASE="tablemaster-api@1.0.2+${{ github.run_number }}" \
../ops/deploy-api.sh
EOF
release:
name: Publish API release journal
runs-on: ubuntu-latest
needs: deploy
if: github.event_name == 'push' && github.ref == 'refs/heads/Prod'
steps:
- uses: actions/checkout@v4
- name: Download test evidence
uses: actions/download-artifact@v4
with:
name: test-results
path: test-results
- name: Prepare release evidence
run: |
mkdir -p release-evidence
TRX_FILE=$(find test-results -type f -name '*.trx' -print -quit)
OUTDATED_FILE=$(find test-results -type f -name 'dotnet-outdated.txt' -print -quit)
test -n "$TRX_FILE"
test -n "$OUTDATED_FILE"
cp "$TRX_FILE" release-evidence/test-results.trx
cp "$OUTDATED_FILE" release-evidence/dotnet-outdated.txt
sha256sum release-evidence/* CHANGELOG.md > SHA256SUMS
cat > release-notes.md << EOF
Release TableMaster API 1.0.2+${{ github.run_number }}
Commit: ${{ github.sha }}
Image immuable: ghcr.io/${{ github.repository_owner }}/tablemaster-api:${{ github.sha }}
Release Sentry: tablemaster-api@1.0.2+${{ github.run_number }}
Validation:
- build Release
- tests xUnit
- audit des dépendances vulnérables
- readiness PostgreSQL
- smoke test post-déploiement
Consulter CHANGELOG.md pour le détail des évolutions et correctifs.
EOF
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "api-v1.0.2+${{ github.run_number }}" \
CHANGELOG.md \
SHA256SUMS \
release-evidence/test-results.trx \
release-evidence/dotnet-outdated.txt \
--title "TableMaster API 1.0.2+${{ github.run_number }}" \
--notes-file release-notes.md \
--latest