1- name : Registry push
1+ name : CI
22
33on :
44 push :
@@ -15,10 +15,10 @@ concurrency:
1515 cancel-in-progress : true
1616
1717jobs :
18- runtime :
18+ check-dependencies :
1919 runs-on : ubuntu-latest
2020 outputs :
21- runtime_built : ${{ steps.set_output .outputs.runtime_built }}
21+ changed : ${{ steps.dep-check .outputs.changed }}
2222 steps :
2323 - name : Checkout
2424 uses : actions/checkout@v4
@@ -27,16 +27,25 @@ jobs:
2727 run : git fetch origin main
2828
2929 - name : Check if dependencies changed
30- id : depcheck
30+ id : dep-check
3131 run : |
3232 if git diff --name-only origin/main | grep -E 'package.json|pnpm-lock.yaml|pnpm-workspace.yaml|runtime.Dockerfile'; then
3333 echo "changed=true" >> $GITHUB_OUTPUT
3434 else
3535 echo "changed=false" >> $GITHUB_OUTPUT
3636 fi
3737
38+ runtime :
39+ runs-on : ubuntu-latest
40+ needs : [check-dependencies]
41+ if : needs.check-dependencies.outputs.changed == 'true'
42+ outputs :
43+ runtime_built : ' true'
44+ steps :
45+ - name : Checkout
46+ uses : actions/checkout@v4
47+
3848 - name : Docker meta (runtime)
39- if : steps.depcheck.outputs.changed == 'true'
4049 id : meta_runtime
4150 uses : docker/metadata-action@v5
4251 with :
@@ -47,23 +56,19 @@ jobs:
4756 type=raw,value=latest
4857
4958 - name : Set up QEMU
50- if : steps.depcheck.outputs.changed == 'true'
5159 uses : docker/setup-qemu-action@v3
5260
5361 - name : Set up Docker Buildx
54- if : steps.depcheck.outputs.changed == 'true'
5562 uses : docker/setup-buildx-action@v3
5663
5764 - name : Login to ghcr.io Registry
58- if : steps.depcheck.outputs.changed == 'true'
5965 uses : docker/login-action@v3
6066 with :
6167 registry : ghcr.io
6268 username : ${{ github.actor }}
6369 password : ${{ secrets.GITHUB_TOKEN }}
6470
6571 - name : Build and push runtime image
66- if : steps.depcheck.outputs.changed == 'true'
6772 uses : docker/build-push-action@v6
6873 with :
6974 context : .
@@ -74,14 +79,70 @@ jobs:
7479 platforms : |
7580 linux/amd64
7681 linux/arm64
82+ cache-from : type=gha
83+ cache-to : type=gha,mode=max
7784
78- - name : Set output
79- id : set_output
80- run : echo "runtime_built=${{ steps.depcheck.outputs.changed }}" >> $GITHUB_OUTPUT
85+ test :
86+ runs-on : ubuntu-latest
87+ needs : [check-dependencies, runtime]
88+ if : always() && !cancelled() && !failure()
89+ services :
90+ postgres :
91+ image : postgres:17.5
92+ env :
93+ POSTGRES_PASSWORD : omnibox
94+ POSTGRES_USER : omnibox
95+ POSTGRES_DB : omnibox
96+ ports :
97+ - 5432:5432
98+ options : >-
99+ --health-cmd pg_isready
100+ --health-interval 10s
101+ --health-timeout 5s
102+ --health-retries 5
103+
104+ minio :
105+ image : ghcr.io/import-ai/minio-server:RELEASE.2025-04-22T22-12-26Z
106+ env :
107+ MINIO_ROOT_USER : username
108+ MINIO_ROOT_PASSWORD : password
109+ ports :
110+ - 9000:9000
111+ - 9100:9001
112+ options : >-
113+ --health-cmd "curl -f http://localhost:9000/minio/health/live"
114+ --health-interval 30s
115+ --health-timeout 20s
116+ --health-retries 3
117+
118+ container :
119+ image : ghcr.io/import-ai/omnibox-backend-runtime:latest
120+ credentials :
121+ username : ${{ github.actor }}
122+ password : ${{ secrets.GITHUB_TOKEN }}
123+
124+ steps :
125+ - name : Checkout
126+ uses : actions/checkout@v4
127+
128+ - name : Install dependencies
129+ run : pnpm install --frozen-lockfile
130+
131+ - name : Prepare .env
132+ run : cp example.env .env
133+
134+ - name : Run unit tests
135+ run : pnpm run test
136+
137+ - name : Run e2e tests
138+ env :
139+ OBB_POSTGRES_URL : postgres://omnibox:omnibox@postgres:5432/omnibox
140+ OBB_MINIO_URL : http://username:password@minio:9000/omnibox
141+ run : pnpm run test:e2e
81142
82143 app :
83144 runs-on : ubuntu-latest
84- needs : [ runtime ]
145+ needs : [test ]
85146 steps :
86147 - name : Checkout
87148 uses : actions/checkout@v4
@@ -123,17 +184,24 @@ jobs:
123184 platforms : |
124185 linux/amd64
125186 linux/arm64
187+ cache-from : type=gha
188+ cache-to : type=gha,mode=max
126189
127190 webhook :
128191 runs-on : ubuntu-latest
129- needs : [ app ]
192+ needs : [app]
130193 steps :
131194 - name : DEV Webhook
132- if : github.event_name == 'push'
195+ if : github.event_name == 'push' && github.ref == 'refs/heads/main'
133196 run : |
134197 curl "${{ secrets.DEV_WEBHOOK_URL }}/dev" -H "Authorization: Bearer ${{ secrets.DEV_WEBHOOK_API_KEY }}"
135198
136199 - name : PR Webhook
137200 if : github.event_name == 'pull_request'
138201 run : |
139202 curl "${{ secrets.DEV_WEBHOOK_URL }}/pr?module=backend&pr=pr-${{ github.event.number }}" -H "Authorization: Bearer ${{ secrets.DEV_WEBHOOK_API_KEY }}"
203+
204+ - name : PROD Webhook
205+ if : false && github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
206+ run : |
207+ curl "${{ secrets.PROD_WEBHOOK_URL }}/prod?tag=${{ github.ref }}" -H "Authorization: Bearer ${{ secrets.PROD_WEBHOOK_API_KEY }}"
0 commit comments