-
Notifications
You must be signed in to change notification settings - Fork 5
149 lines (123 loc) · 6.69 KB
/
dotnet-test.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
name: dotnet test
on:
push:
branches: [production, test, dev]
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_NOLOGO: true
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04]
dotnet-version: ['8.0.x']
steps:
- uses: actions/checkout@v3
- name: Setup .NET SDK
uses: actions/setup-dotnet@v2
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Extract short SHA
shell: bash
run: echo "##[set-output name=short_sha;]$(echo ${GITHUB_SHA} | cut -c1-8)"
id: extract_short_sha
- name: Test
run: dotnet test --configuration Release --filter 'FullyQualifiedName!~Fakemail.IntegrationTests' --no-restore --verbosity normal --logger trx --results-directory "TestResults-${{ matrix.dotnet-version }}"
#- name: Upload test results
# uses: actions/upload-artifact@v3
# with:
# name: test-results-${{ matrix.dotnet-version }}
# path: TestResults-${{ matrix.dotnet-version }}
# if: ${{ always() }}
- name: Dotnet publish
run: |
rm -rf Fakemail.Web/bin/Release/8.0/publish
rm -rf Fakemail.Api/bin/Release/net8.0/publish
rm -rf Fakemail.Services/bin/Release/net8.0/publish
dotnet publish -p:PublishProfile=FolderProfile --configuration Release -p:DebugType=None -p:DebugSymbols=false Fakemail.Web
dotnet publish -p:PublishProfile=FolderProfile --configuration Release -p:DebugType=None -p:DebugSymbols=false Fakemail.Api
dotnet publish -p:PublishProfile=FolderProfile --configuration Release -p:DebugType=None -p:DebugSymbols=false Fakemail.Services
- name: Create deployment artifact
run: |
rm -rf fakemail-deployment
mkdir -p fakemail-deployment/common/runtimes
mkdir fakemail-deployment/api
mkdir fakemail-deployment/web
mkdir fakemail-deployment/services
# delete the runtimes that are not used
mv Fakemail.Web/bin/Release/net8.0/publish/runtimes/linux-x64 fakemail-deployment/common/runtimes
mv Fakemail.Web/bin/Release/net8.0/publish/runtimes/linux-arm64 fakemail-deployment/common/runtimes
rm -rf Fakemail.Web/bin/Release/net8.0/publish/runtimes
rm -rf Fakemail.Api/bin/Release/net8.0/publish/runtimes
rm -rf Fakemail.Services/bin/Release/net8.0/publish/runtimes
# web specific files
mv Fakemail.Web/bin/Release/net8.0/publish/*.json fakemail-deployment/web
mv Fakemail.Web/bin/Release/net8.0/publish/*.config fakemail-deployment/web
mv Fakemail.Web/bin/Release/net8.0/publish/Fakemail.Web.* fakemail-deployment/web
mv Fakemail.Web/bin/Release/net8.0/publish/wwwroot fakemail-deployment/web
# api specific files
mv Fakemail.Api/bin/Release/net8.0/publish/*.json fakemail-deployment/api
mv Fakemail.Api/bin/Release/net8.0/publish/*.config fakemail-deployment/api
mv Fakemail.Api/bin/Release/net8.0/publish/Fakemail.Api.* fakemail-deployment/api
# services specific files
mv Fakemail.Services/bin/Release/net8.0/publish/*.json fakemail-deployment/services
mv Fakemail.Services/bin/Release/net8.0/publish/Fakemail.Services.* fakemail-deployment/services
# everything else is common
mv Fakemail.Web/bin/Release/net8.0/publish/* fakemail-deployment/common
mv Fakemail.Api/bin/Release/net8.0/publish/* fakemail-deployment/common
mv Fakemail.Services/bin/Release/net8.0/publish/* fakemail-deployment/common
mv fakemail-deployment fakemail-deployment.${{ steps.extract_branch.outputs.branch }}.${{ steps.extract_short_sha.outputs.short_sha }}
tar -zcvf fakemail-deployment.${{ steps.extract_branch.outputs.branch }}.${{ steps.extract_short_sha.outputs.short_sha }}.tgz fakemail-deployment.${{ steps.extract_branch.outputs.branch }}.${{ steps.extract_short_sha.outputs.short_sha }}
# Upload deployment artifact, but without secrets
# TODO: only upload production deployments
#- name: Upload deployment artifact
# uses: actions/upload-artifact@v3
# with:
# name: fakemail-deployment.${{ steps.extract_branch.outputs.branch }}.${{ steps.extract_short_sha.outputs.short_sha }}
# path: fakemail-deployment.${{ steps.extract_branch.outputs.branch }}.${{ steps.extract_short_sha.outputs.short_sha }}.tgz
# Now recreate artifact with secrets
- uses: microsoft/variable-substitution@v1
with:
files: '**/appsettings.json'
env:
Jwt.Secret: ${{ secrets.FAKEMAIL_API_JWT_SECRET }}
- name: Create deployment artifact with secrets
run: |
rm -rf fakemail-deployment.${{ steps.extract_branch.outputs.branch }}.${{ steps.extract_short_sha.outputs.short_sha }}.tgz
tar -zcvf fakemail-deployment.${{ steps.extract_branch.outputs.branch }}.${{ steps.extract_short_sha.outputs.short_sha }}.tgz fakemail-deployment.${{ steps.extract_branch.outputs.branch }}.${{ steps.extract_short_sha.outputs.short_sha }}
- name: Set deploy host
run: |
if [[ $GITHUB_REF == 'refs/heads/dev' ]]; then
echo "DEPLOY_HOST=fakemail.stream" >> "$GITHUB_ENV"
elif [[ $GITHUB_REF == 'refs/heads/test' ]]; then
echo "DEPLOY_HOST=test.fakemail.stream" >> "$GITHUB_ENV"
elif [[ $GITHUB_REF == 'refs/heads/production' ]]; then
echo "DEPLOY_HOST=fakemail.stream" >> "$GITHUB_ENV"
else
echo DEPLOY_HOST='' >> "$GITHUB_ENV"
fi
- name: copy file via ssh
uses: appleboy/scp-action@master
with:
host: ${{ env.DEPLOY_HOST }}
username: ${{ secrets.FAKEMAIL_DEPLOY_USER }}
key: ${{ secrets.FAKEMAIL_DEPLOY_SSH_KEY }}
source: "fakemail-deployment.${{ steps.extract_branch.outputs.branch }}.${{ steps.extract_short_sha.outputs.short_sha }}.tgz"
target: "${{ secrets.FAKEMAIL_DEPLOY_PATH }}"
- name: run deploy command
uses: appleboy/ssh-action@master
with:
host: ${{ env.DEPLOY_HOST }}
username: ${{ secrets.FAKEMAIL_DEPLOY_USER }}
key: ${{ secrets.FAKEMAIL_DEPLOY_SSH_KEY }}
script: /home/fakemail/deploy.sh fakemail-deployment.${{ steps.extract_branch.outputs.branch }}.${{ steps.extract_short_sha.outputs.short_sha }}