-
Notifications
You must be signed in to change notification settings - Fork 0
170 lines (140 loc) Β· 5.02 KB
/
ci.yaml
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
name: π CI Pipeline for Monorepo
on:
push:
branches:
- main
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
services: ${{ steps.filter.outputs.services }}
steps:
- name: π₯ Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: π Detect Changed Microservices
id: filter
run: |
changed_services=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep '^backend/' | cut -d'/' -f2 | sort -u | jq -R . | jq -s -c .)
echo "Detected changes in: $changed_services"
# Ensure valid JSON
if [[ -z "$changed_services" || "$changed_services" == "[]" ]]; then
services_json="[]"
else
services_json="$changed_services"
fi
echo "services=$services_json" >> "$GITHUB_OUTPUT"
build:
needs: detect-changes
runs-on: ubuntu-latest
environment: opinex
if: needs.detect-changes.outputs.services != '[]'
steps:
- name: π₯ Checkout Code
uses: actions/checkout@v3
- name: βοΈ Set up Node.js Environment
uses: actions/setup-node@v3
with:
node-version: "22"
- name: βοΈ Set up Python Environment
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: π¦ Install Node.js Dependencies
run: |
npm install -g turbo
npm install
- name: π§ Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 - --version 2.1.1
echo "$HOME/.local/bin" >> $GITHUB_PATH
export PATH="$HOME/.local/bin:$PATH"
- name: Install Event Service Dependencies
run: |
cd backend/event
poetry install --no-root
- name: β
Docker Network creations
run: |
docker network ls | grep main_network || docker network create main_network
- name: π Run docker Resources (DB, cache, pubsub)
run: |
cd docker
cd cache
docker compose up -d
cd ..
cd DBS
docker compose up -d
cd ..
cd pubsub
docker compose up -d
echo " π Docker common resources running"
sleep 10
- name: β
Verify Running Containers
run: |
docker compose -f 'docker/cache/docker-compose.yaml' ps
docker compose -f 'docker/DBS/docker-compose.yaml' ps
docker compose -f 'docker/pubsub/docker-compose.yaml' ps
- name: π Debug Logs on Failure
if: failure()
run: |
docker compose -f 'docker/cache/docker-compose.yaml' logs --tail=100
docker compose -f 'docker/DBS/docker-compose.yaml' logs --tail=100
docker compose -f 'docker/pubsub/docker-compose.yaml' logs --tail=100
- name: β‘ Start Turbo Dev Mode
run: |
turbo build
nohup turbo dev > turbo.log 2>&1 &
echo "Turbo Dev started with PID: $!"
- name: β³ Wait Until All Servers are Up
run: |
cd scripts/
chmod +x checkservice.sh
./checkservice.sh
- name: π¬ Run Tests in /packages/test
run: |
cd packages/test
npm run test
- name: π Stop Turbo Dev
run: |
pkill -f "turbo dev" || echo "Turbo Dev process not running"
# - name: π§Ή Cleanup Resources
# run: |
# docker compose -f 'docker/docker-compose.resources.yaml' down -v
# - name: ποΈ Build Images
# run: |
# cd scripts/
# chmod +x build_images.sh
# ./build_images.sh
# - name: π³ Configure Docker Images + Resources
# run: |
# docker compose -f 'docker/docker-compose.yaml' up -d --build --wait
# - name: β
Verify Running Containers
# run: docker compose -f 'docker/docker-compose.yaml' ps
# - name: π Debug Logs on Failure
# if: failure()
# run: docker compose -f 'docker/docker-compose.yaml' logs --tail=100
# - name: β³ Wait Until All Servers are Up (Docker)
# run: |
# cd scripts/
# chmod +x checkservice.sh
# ./checkservice.sh
# - name: π¬ Run Tests in /packages/test
# run: |
# cd packages/test
# npm run test
# - name: π Convert JSON to Space-Separated List
# id: format_services
# run: |
# services_list=$(echo '${{ needs.detect-changes.outputs.services }}' | jq -r '.[]' | tr '\n' ' ')
# echo "services_list=$services_list" >> "$GITHUB_ENV"
# - name: π Login to Docker Hub
# uses: docker/login-action@v2
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}
# - name: π·οΈ Tag Images
# run: |
# cd scripts/
# chmod +x tag_images.sh
# ./tag_images.sh ${{ secrets.DOCKER_USERNAME }} ${{ github.sha }} $services_list