-
Notifications
You must be signed in to change notification settings - Fork 0
203 lines (182 loc) · 7.76 KB
/
spendmanagement-identity-api.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
name: build_and_run_tests
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
name: Build application
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore src/Identity.Api/Identity.Api.csproj
- name: Build
run: dotnet build --no-restore --configuration Release src/Identity.Api/Identity.Api.csproj
unit-tests:
runs-on: ubuntu-latest
name: Running UnitTests
needs: [build]
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies for unit tests
run: dotnet restore tests/Identity.UnitTests/Identity.UnitTests.csproj
- name: Build project
run: dotnet build --no-restore --configuration Release tests/Identity.UnitTests/Identity.UnitTests.csproj
- name: Run unit tests
run: dotnet test --verbosity normal tests/Identity.UnitTests/Identity.UnitTests.csproj
integration-tests:
name: Running IntegrationTests
runs-on: ubuntu-latest
needs: [unit-tests]
steps:
- name: Setup PostgreSQL
run: |
docker run -d --name postgres -p 5432:5432 \
-e POSTGRES_PASSWORD=postgres \
--health-cmd pg_isready \
--health-interval 10s \
--health-timeout 5s \
--health-retries 5 \
postgres
- name: Wait for PostgreSQL to start
run: |
until docker exec postgres pg_isready; do
sleep 1;
done
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Run integration tests
run: |
dotnet restore tests/Identity.IntegrationTests/Identity.IntegrationTests.csproj
dotnet build --no-restore --configuration Release tests/Identity.IntegrationTests/Identity.IntegrationTests.csproj
dotnet test --verbosity normal tests/Identity.IntegrationTests/Identity.IntegrationTests.csproj
bump:
name: Update project version
runs-on: ubuntu-latest
needs: [build,unit-tests, integration-tests]
outputs:
version: ${{ steps.set-version.outputs.VERSION }}
version_update_type: ${{ steps.determine_update_type.outputs.VERSION_UPDATE_TYPE }}
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Determinar Tipo de Mudança
id: determine_update_type
run: |
LAST_COMMIT_MESSAGE=$(git log -1 --pretty=%B)
if echo "$LAST_COMMIT_MESSAGE" | grep -qiE "feat"; then
echo "VERSION_UPDATE_TYPE=MINOR" >> $GITHUB_OUTPUT
echo "VERSION_UPDATE_TYPE=MINOR" >> $GITHUB_ENV
fi
if echo "$LAST_COMMIT_MESSAGE" | grep -qiE "fix"; then
echo "VERSION_UPDATE_TYPE=REVISION" >> $GITHUB_OUTPUT
echo "VERSION_UPDATE_TYPE=REVISION" >> $GITHUB_ENV
fi
- name: Print Update type
run: |
echo "Tipo de Mudança: ${{ steps.determine_update_type.outputs.VERSION_UPDATE_TYPE }}"
- name: Bump build version - Minor
if: env.VERSION_UPDATE_TYPE == 'MINOR'
id: bump-minor
uses: vers-one/dotnet-project-version-updater@v1.5
with:
file: src/Identity.Api/Identity.Api.csproj
version: "*.^.0"
- name: Bump build version - Revision
if: env.VERSION_UPDATE_TYPE == 'REVISION'
id: bump-revision
uses: vers-one/dotnet-project-version-updater@v1.5
with:
file: src/Identity.Api/Identity.Api.csproj
version: "*.*.^"
- name: Commit and push changes - MINOR
if: env.VERSION_UPDATE_TYPE == 'MINOR'
run: |
git config user.name "Build - Incrementing version | Github action"
git config user.email "deploy@spendmanagement.com"
git add .
git commit -m "CI: Updating application version ${{ steps.bump-minor.outputs.newVersion }}"
git push
- name: Commit and push changes - Revision
if: env.VERSION_UPDATE_TYPE == 'REVISION'
run: |
git config user.name "Build - Incrementing version | Github action"
git config user.email "deploy@spendmanagement.com"
git add .
git commit -m "CI: Updating application version ${{ steps.bump-revision.outputs.newVersion }}"
git push
- name: Set version - Revision
id: set-version
if: env.VERSION_UPDATE_TYPE == 'MINOR' || env.VERSION_UPDATE_TYPE == 'REVISION'
run: |
if [[ ${{ steps.determine_update_type.outputs.VERSION_UPDATE_TYPE }} == 'REVISION' ]]; then
echo "VERSION=${{ steps.bump-revision.outputs.newVersion }}" >> $GITHUB_OUTPUT
else
echo "VERSION=${{ steps.bump-minor.outputs.newVersion }}" >> $GITHUB_OUTPUT
fi
publish-docker-image:
name: Publish new docker image
needs: [bump]
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.bump.outputs.version }}
VERSION_UPDATE_TYPE: ${{ needs.bump.outputs.version_update_type }}
steps:
- name: Print version + type
if: env.VERSION_UPDATE_TYPE == 'MINOR' || env.VERSION_UPDATE_TYPE == 'REVISION'
run: |
echo "The csproj version is $VERSION-$VERSION_UPDATE_TYPE"
- name: Checkout repository
if: env.VERSION_UPDATE_TYPE == 'MINOR' || env.VERSION_UPDATE_TYPE == 'REVISION'
uses: actions/checkout@v4
- name: Display appsettings before
if: env.VERSION_UPDATE_TYPE == 'MINOR' || env.VERSION_UPDATE_TYPE == 'REVISION'
run: cat src/Identity.Api/appsettings.Development.json
- name: Change connection string
if: env.VERSION_UPDATE_TYPE == 'MINOR' || env.VERSION_UPDATE_TYPE == 'REVISION'
run: |
sed -i 's/localhost/postgresql/g' src/Identity.Api/appsettings.Development.json
working-directory: ${{ github.workspace }}
- name: Display appsettings after changes
if: env.VERSION_UPDATE_TYPE == 'MINOR' || env.VERSION_UPDATE_TYPE == 'REVISION'
run: cat src/Identity.Api/appsettings.Development.json
- name: Build Docker image
if: env.VERSION_UPDATE_TYPE == 'MINOR' || env.VERSION_UPDATE_TYPE == 'REVISION'
run: docker build -t "fmattioli/spendmanagement-identity-api:$VERSION" .
- name: Login to Docker Hub
if: env.VERSION_UPDATE_TYPE == 'MINOR' || env.VERSION_UPDATE_TYPE == 'REVISION'
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- name: Push Docker image to Docker Hub
id: publish-image
if: env.VERSION_UPDATE_TYPE == 'MINOR' || env.VERSION_UPDATE_TYPE == 'REVISION'
run: |
docker push "fmattioli/spendmanagement-identity-api:$VERSION"
docker tag "fmattioli/spendmanagement-identity-api:$VERSION" "fmattioli/spendmanagement-identity-api:latest"
docker push "fmattioli/spendmanagement-identity-api:latest"
Deploy:
needs: [bump, publish-docker-image]
name: Start deploy on Render
runs-on: ubuntu-latest
env:
IMAGE_URL: 'docker.io/fmattioli/spendmanagement-receipts-commandhandler-api:latest'
VERSION_UPDATE_TYPE: ${{ needs.bump.outputs.version_update_type }}
steps:
- name: Deploy hostinger
if: github.ref == 'refs/heads/main' && env.VERSION_UPDATE_TYPE == 'MINOR' || env.VERSION_UPDATE_TYPE == 'REVISION'
run: |
echo $VERSION_UPDATE_TYPE
curl "${{ secrets.API_URL_HOSTINGER }}"