Skip to content

Commit 6af6d5c

Browse files
authored
chore: migrate to GH action for Postgres build and tests (#2012)
1 parent b16ef50 commit 6af6d5c

1 file changed

Lines changed: 220 additions & 0 deletions

File tree

.github/workflows/postgres.yml

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
name: Postgres Build and Test
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
push:
7+
branches:
8+
- master
9+
tags:
10+
- '**'
11+
workflow_dispatch: {}
12+
13+
env:
14+
RUST_VERSION: "1.89"
15+
PYTHON_VERSION: "3.12"
16+
17+
jobs:
18+
build-and-test-postgres:
19+
runs-on: ubuntu-latest
20+
21+
services:
22+
postgres:
23+
image: postgres:18.0
24+
env:
25+
POSTGRES_USER: test
26+
POSTGRES_PASSWORD: test
27+
POSTGRES_DB: syncstorage
28+
ports:
29+
- 5432:5432
30+
options: >-
31+
--health-cmd="pg_isready -U test"
32+
--health-interval=10s
33+
--health-timeout=5s
34+
--health-retries=5
35+
36+
env:
37+
SYNC_SYNCSTORAGE__DATABASE_URL: postgres://test:test@127.0.0.1/syncstorage
38+
SYNC_TOKENSERVER__DATABASE_URL: postgres://test:test@127.0.0.1/tokenserver
39+
RUST_BACKTRACE: 1
40+
RUST_TEST_THREADS: 1
41+
42+
steps:
43+
- uses: actions/checkout@v6
44+
45+
- uses: ./.github/actions/setup-rust
46+
with:
47+
workspace-path: workflow/test-results
48+
49+
- uses: ./.github/actions/setup-python
50+
with:
51+
workspace-path: workflow/test-results
52+
53+
- name: Install PostgreSQL client
54+
run: sudo apt-get update && sudo apt-get install -y postgresql-client
55+
56+
- name: Create Tokenserver database
57+
run: |
58+
PGPASSWORD=test psql -U test -h 127.0.0.1 -d syncstorage -c 'CREATE DATABASE tokenserver;'
59+
60+
- name: Create version.json
61+
run: |
62+
printf '{"commit":"%s","version":"%s","source":"https://github.com/%s/%s","build":"%s"}\n' \
63+
"${{ github.sha }}" \
64+
"${{ github.ref_name }}" \
65+
"${{ github.repository_owner }}" \
66+
"${{ github.event.repository.name }}" \
67+
"${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
68+
> syncserver/version.json
69+
70+
- name: Install test dependencies
71+
run: cargo install --locked cargo-nextest cargo-llvm-cov
72+
73+
- name: Run unit tests with coverage
74+
run: make postgres_test_with_coverage
75+
76+
- name: Run unit tests with coverage (quota enforced)
77+
run: make postgres_test_with_coverage
78+
env:
79+
SYNC_SYNCSTORAGE__ENFORCE_QUOTA: 1
80+
81+
- name: Run Postgres utils tests
82+
working-directory: tools/postgres
83+
run: |
84+
poetry install --no-interaction --no-ansi
85+
poetry run pytest test_purge_ttl.py -v --junit-xml="../../workflow/test-results/${{ github.run_number }}-${{ github.job }}-utils_tests.xml"
86+
env:
87+
SYNC_SYNCSTORAGE__DATABASE_URL: postgresql://test:test@127.0.0.1/syncstorage
88+
89+
- name: Upload test results
90+
if: always()
91+
uses: actions/upload-artifact@v6
92+
with:
93+
name: postgres-test-results
94+
path: workflow/test-results/
95+
96+
# Upload to GCS on master
97+
- name: Authenticate to Google Cloud
98+
if: github.ref == 'refs/heads/master' && env.GCP_AUTH_KEY != ''
99+
env:
100+
GCP_AUTH_KEY: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }}
101+
uses: google-github-actions/auth@v3
102+
with:
103+
credentials_json: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }}
104+
105+
- name: Upload JUnit results to GCS
106+
if: github.ref == 'refs/heads/master' && env.GCP_AUTH_KEY != ''
107+
env:
108+
GCP_AUTH_KEY: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }}
109+
uses: google-github-actions/upload-cloud-storage@v2
110+
with:
111+
path: workflow/test-results
112+
destination: ecosystem-test-eng-metrics/syncstorage-rs/junit
113+
glob: "*.xml"
114+
parent: false
115+
process_gcloudignore: false
116+
117+
- name: Upload coverage results to GCS
118+
if: github.ref == 'refs/heads/master' && env.GCP_AUTH_KEY != ''
119+
env:
120+
GCP_AUTH_KEY: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }}
121+
uses: google-github-actions/upload-cloud-storage@v2
122+
with:
123+
path: workflow/test-results
124+
destination: ecosystem-test-eng-metrics/syncstorage-rs/coverage
125+
glob: "*.json"
126+
parent: false
127+
process_gcloudignore: false
128+
129+
build-postgres-image:
130+
runs-on: ubuntu-latest
131+
needs: build-and-test-postgres
132+
133+
steps:
134+
- uses: actions/checkout@v6
135+
136+
- name: Create version.json
137+
run: |
138+
printf '{"commit":"%s","version":"%s","source":"https://github.com/%s/%s","build":"%s"}\n' \
139+
"${{ github.sha }}" \
140+
"${{ github.ref_name }}" \
141+
"${{ github.repository_owner }}" \
142+
"${{ github.event.repository.name }}" \
143+
"${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
144+
> syncserver/version.json
145+
146+
- name: Set up Docker Buildx
147+
uses: docker/setup-buildx-action@v3
148+
149+
- name: Build Postgres Docker image
150+
uses: docker/build-push-action@v6
151+
with:
152+
context: .
153+
push: false
154+
tags: app:build
155+
build-args: |
156+
SYNCSTORAGE_DATABASE_BACKEND=postgres
157+
TOKENSERVER_DATABASE_BACKEND=postgres
158+
outputs: type=docker,dest=/tmp/postgres-image.tar
159+
cache-from: type=gha
160+
cache-to: type=gha,mode=max
161+
162+
- name: Upload Docker image artifact
163+
uses: actions/upload-artifact@v6
164+
with:
165+
name: postgres-docker-image
166+
path: /tmp/postgres-image.tar
167+
retention-days: 1
168+
169+
postgres-e2e-tests:
170+
runs-on: ubuntu-latest
171+
needs: build-postgres-image
172+
173+
steps:
174+
- uses: actions/checkout@v6
175+
176+
- name: Download Docker image
177+
uses: actions/download-artifact@v6
178+
with:
179+
name: postgres-docker-image
180+
path: /tmp
181+
182+
- name: Load Docker image
183+
run: docker load --input /tmp/postgres-image.tar
184+
185+
- name: Create test results directory
186+
run: mkdir -p workflow/test-results
187+
188+
- name: Run Postgres e2e tests
189+
run: make docker_run_postgres_e2e_tests
190+
env:
191+
SYNCSTORAGE_RS_IMAGE: app:build
192+
193+
- name: Upload e2e test results
194+
if: always()
195+
uses: actions/upload-artifact@v6
196+
with:
197+
name: postgres-e2e-test-results
198+
path: workflow/test-results/
199+
200+
# Upload to GCS on master
201+
- name: Authenticate to Google Cloud
202+
if: github.ref == 'refs/heads/master' && env.GCP_AUTH_KEY != ''
203+
env:
204+
GCP_AUTH_KEY: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }}
205+
uses: google-github-actions/auth@v3
206+
with:
207+
credentials_json: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }}
208+
209+
- name: Upload e2e test results to GCS
210+
if: github.ref == 'refs/heads/master' && env.GCP_AUTH_KEY != ''
211+
env:
212+
GCP_AUTH_KEY: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }}
213+
uses: google-github-actions/upload-cloud-storage@v2
214+
with:
215+
path: workflow/test-results
216+
destination: ecosystem-test-eng-metrics/syncstorage-rs/junit
217+
glob: "*.xml"
218+
parent: false
219+
process_gcloudignore: false
220+

0 commit comments

Comments
 (0)