-
Notifications
You must be signed in to change notification settings - Fork 12
208 lines (179 loc) · 6.24 KB
/
ci.yml
File metadata and controls
208 lines (179 loc) · 6.24 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
name: Deploy to Cloudflare Pages & API to G
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
inputs:
deploy_all:
description: "Deploy all projects regardless of changes"
required: false
default: false
type: boolean
jobs:
check-affected:
runs-on: ubuntu-latest
name: Check Affected Projects
outputs:
admin: ${{ steps.affected.outputs.admin }}
platform: ${{ steps.affected.outputs.platform }}
api: ${{ steps.affected.outputs.api }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup moon
uses: moonrepo/setup-toolchain@v0
- name: Check affected projects
id: affected
run: |
# Check if this is a manual deploy all trigger
if [ "${{ github.event_name }}" == "workflow_dispatch" ] && [ "${{ github.event.inputs.deploy_all }}" == "true" ]; then
echo "admin=true" >> $GITHUB_OUTPUT
echo "platform=true" >> $GITHUB_OUTPUT
echo "api=true" >> $GITHUB_OUTPUT
echo "Manual deploy all triggered - deploying all projects"
else
# Get affected projects as JSON
AFFECTED=$(moon query projects --affected --json)
# Check if each project is affected
echo "admin=$(echo $AFFECTED | jq -r '.projects | map(select(.id == "admin")) | if length > 0 then "true" else "false" end')" >> $GITHUB_OUTPUT
echo "platform=$(echo $AFFECTED | jq -r '.projects | map(select(.id == "platform")) | if length > 0 then "true" else "false" end')" >> $GITHUB_OUTPUT
echo "api=$(echo $AFFECTED | jq -r '.projects | map(select(.id == "api")) | if length > 0 then "true" else "false" end')" >> $GITHUB_OUTPUT
fi
test-api:
runs-on: ubuntu-latest
needs: check-affected
if: |
needs.check-affected.outputs.api == 'true' ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_all == 'true')
name: Test API
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Install dependencies
run: |
cd apps/api
uv sync
- name: Run tests
run: |
cd apps/api
uv run pytest tests/ -v
env:
DB_URL: sqlite:///test.db
deploy-admin:
runs-on: ubuntu-latest
needs: check-affected
if: |
(github.ref == 'refs/heads/main' && needs.check-affected.outputs.admin == 'true') ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_all == 'true')
name: Deploy Admin to Cloudflare Pages
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.18.3
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build UI Package
run: pnpm --filter @opencircle/ui build
- name: Build Admin
run: pnpm --filter admin build
env:
VITE_API_URL: ${{ secrets.VITE_API_URL }}
- name: Deploy to Cloudflare Pages
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: circle-admin
directory: apps/admin/dist
deploy-platform:
runs-on: ubuntu-latest
needs: check-affected
if: |
(github.ref == 'refs/heads/main' && needs.check-affected.outputs.platform == 'true') ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_all == 'true')
name: Deploy Platform to Cloudflare Pages
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.18.3
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build UI Package
run: pnpm --filter @opencircle/ui build
- name: Build Platform
run: pnpm --filter platform build
env:
VITE_API_URL: ${{ secrets.VITE_API_URL }}
- name: Deploy to Cloudflare Pages
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: devscale-circle
directory: apps/platform/dist
deploy-api:
runs-on: ubuntu-latest
needs: [test-api, check-affected]
if: |
(github.ref == 'refs/heads/main' &&
needs.check-affected.outputs.api == 'true' &&
needs.test-api.result == 'success') ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_all == 'true')
name: Deploy API to Docker Registry
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.PAT_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/opencircle-api
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./apps/api/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max