-
Notifications
You must be signed in to change notification settings - Fork 1
244 lines (219 loc) · 7.44 KB
/
Copy pathci.yml
File metadata and controls
244 lines (219 loc) · 7.44 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
name: CI
on:
push:
branches: [main, develop]
pull_request:
permissions:
contents: write
pull-requests: write
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
# 1) Qaysi paketlar o'zgarganini aniqlaydi
changes:
runs-on: ubuntu-latest
outputs:
web-user: ${{ steps.filter.outputs.web-user }}
web-partner: ${{ steps.filter.outputs.web-partner }}
web-admin: ${{ steps.filter.outputs.web-admin }}
backend: ${{ steps.filter.outputs.backend }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
shared: &shared
- 'package.json'
- 'package-lock.json'
- 'packages/types/**'
web-user:
- *shared
- 'apps/web-user/**'
web-partner:
- *shared
- 'apps/web-partner/**'
web-admin:
- *shared
- 'apps/web-admin/**'
backend:
- *shared
- 'apps/backend/**'
# 2) Har bir o'zgargan app'ni build + lint qiladi
web-user:
needs: changes
if: ${{ needs.changes.outputs.web-user == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm run build:types
- run: npm run lint -w @safaar/web-user
- run: npm run build:user
web-partner:
needs: changes
if: ${{ needs.changes.outputs.web-partner == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm run build:types
- run: npm run lint -w @safaar/web-partner
- run: npm run build:partner
web-admin:
needs: changes
if: ${{ needs.changes.outputs.web-admin == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm run build:types
- run: npm run lint -w @safaar/web-admin
- run: npm run build:admin
backend:
needs: changes
if: ${{ needs.changes.outputs.backend == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm run build:types
- run: npm run test -w @safaar/backend
- run: npm run build:backend
# 3) Boundary check — har bir commit faqat o'z papkasiga tegganligini tekshiradi
boundary-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Papka chegaralarini tekshirish
shell: bash
run: |
set -euo pipefail
# Push yoki PR ekanligiga qarab base/head ni aniqlaymiz
if [ "${{ github.event_name }}" = "push" ]; then
BASE="${{ github.event.before }}"
HEAD="${{ github.sha }}"
else
BASE="${{ github.event.pull_request.base.sha }}"
HEAD="${{ github.event.pull_request.head.sha }}"
fi
# Agar BASE "0000..." bo'lsa (birinchi push), farqni topolmaymiz — skip
if [ "$BASE" = "0000000000000000000000000000000000000000" ]; then
echo "::notice::Birinchi push — boundary check o'tkazib yuborildi"
exit 0
fi
VIOLATIONS=0
for COMMIT in $(git rev-list "$BASE..$HEAD"); do
FILES=$(git diff-tree --no-commit-id -r --name-only "$COMMIT")
# Qaysi guruh(lar)ga tegishli ekanligini aniqlaymiz
GROUP_OWNER=""
while IFS= read -r FILE; do
OWNER=""
case "$FILE" in
# @FarrukhDev-io
apps/web-user/*)
OWNER="farrukh"
;;
# @adhambek7717
apps/web-partner/* | apps/web-admin/*)
OWNER="adhambek"
;;
# @Lazizdeveloper
apps/backend/* | packages/types/* | package.json | package-lock.json | CODEOWNERS | tsconfig.json | .prettierrc)
OWNER="laziz"
;;
# Shared — hamma tegishi mumkin
.github/* | *.md | AGENTS.md | CONTRIBUTING.md | .gitignore | .gitattributes)
OWNER="shared"
;;
railway.json | docker-compose* | vercel.json | .env* | next.config* | postcss.config* | eslint* | tsconfig*)
OWNER="shared"
;;
esac
# Agar OWNER aniqlanmasa — shared hisoblanadi
OWNER="${OWNER:-shared}"
if [ "$OWNER" != "shared" ]; then
if [ -z "$GROUP_OWNER" ]; then
GROUP_OWNER="$OWNER"
elif [ "$GROUP_OWNER" != "$OWNER" ]; then
echo "::error::CHEGARA BUZILISHI: $COMMIT — commit bir necha egaga tegishli"
echo " Egalar: $GROUP_OWNER va $OWNER"
echo " Fayl: $FILE"
VIOLATIONS=$((VIOLATIONS + 1))
fi
fi
done <<< "$FILES"
done
if [ "$VIOLATIONS" -gt 0 ]; then
echo "::error::$VIOLATIONS ta commitda chegara buzilishi aniqlandi"
exit 1
fi
echo "::notice::Barcha commitlar chegara qoidalariga mos"
# 4) Umumiy gate — branch protection uchun
ci-success:
name: CI Success
needs: [web-user, web-partner, web-admin, backend, boundary-check]
if: always()
runs-on: ubuntu-latest
steps:
- name: Natijalarni tekshirish
run: |
results="${{ needs.web-user.result }} ${{ needs.web-partner.result }} ${{ needs.web-admin.result }} ${{ needs.backend.result }} ${{ needs.boundary-check.result }}"
echo "Job natijalari: $results"
for r in $results; do
if [ "$r" = "failure" ] || [ "$r" = "cancelled" ]; then
echo "::error::Kamida bitta tekshiruv muvaffaqiyatsiz tugadi."
exit 1
fi
done
echo "Barcha tegishli tekshiruvlar muvaffaqiyatli."
# 5) Auto-merge: develop → main (faqat develop'ga push'da, CI to'liq o'tsa)
auto-merge:
needs: ci-success
if: >
github.ref == 'refs/heads/develop' &&
github.event_name == 'push' &&
success()
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
ref: develop
fetch-depth: 0
- name: develop → main PR yaratish va auto-merge
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr create \
--base main \
--head develop \
--title "🤖 Auto-merge: develop → main" \
--body "## Avtomatik merge
- **CI:** o'tdi ✅
- **Boundary check:** o'tdi ✅
Barcha tekshiruvlardan muvaffaqiyatli o'tgan develop'dagi o'zgarishlar main'ga merge qilinmoqda." \
2>/dev/null || echo "PR allaqachon mavjud"
gh pr merge --auto --squash --base main 2>/dev/null || \
echo "Auto-merge yoqilgan yoki PR yopiq"