-
Notifications
You must be signed in to change notification settings - Fork 0
125 lines (103 loc) · 3.15 KB
/
ci-cd.yml
File metadata and controls
125 lines (103 loc) · 3.15 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
name: TechMart Backend CI/CD
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
env:
DOTNET_VERSION: "9.0.x"
jobs:
test:
runs-on: ubuntu-latest
name: 🧪 Test
services:
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: Password123!
POSTGRES_DB: TechMartTest
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis:7
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore dependencies
run: dotnet restore src/TechMart.Backend.sln
- name: Build
run: dotnet build src/TechMart.Backend.sln --no-restore
- name: Unit Tests
run: dotnet test tests/UnitTests/ --no-build --verbosity normal --collect:"XPlat Code Coverage"
- name: Integration Tests
run: dotnet test tests/IntegrationTests/ --no-build --verbosity normal
env:
ConnectionStrings__DefaultConnection: "Host=localhost;Database=TechMartTest;Username=postgres;Password=Password123!"
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.cobertura.xml
fail_ci_if_error: true
build-and-push:
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/main'
name: 🐳 Build & Push Docker Images
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Auth Service
uses: docker/build-push-action@v5
with:
context: ./src
file: ./src/Services/Auth/Dockerfile
push: true
tags: techmart/auth-service:latest
- name: Build and push Product Service
uses: docker/build-push-action@v5
with:
context: ./src
file: ./src/Services/Product/Dockerfile
push: true
tags: techmart/product-service:latest
deploy-staging:
runs-on: ubuntu-latest
needs: build-and-push
if: github.ref == 'refs/heads/develop'
name: 🚀 Deploy to Staging
steps:
- name: Deploy to staging
run: |
echo "Deploying to staging environment"
# Add deployment scripts here
deploy-production:
runs-on: ubuntu-latest
needs: build-and-push
if: github.ref == 'refs/heads/main'
name: 🌟 Deploy to Production
steps:
- name: Deploy to production
run: |
echo "Deploying to production environment"
# Add deployment scripts here