Skip to content

Commit a065b74

Browse files
committed
Added staging tests to CI/CD
closes https://linear.app/ghost/issue/PROD-1779 - Added a CI/CD step that runs tests in staging. This will attempt to catch errors in GCP components before being shipped to production.
1 parent 04c49e6 commit a065b74

File tree

3 files changed

+59
-19
lines changed

3 files changed

+59
-19
lines changed

.github/workflows/cicd.yml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ jobs:
102102
load: true
103103
tags: ${{ steps.migrations-docker-metadata.outputs.tags }}
104104

105-
- name: "Run Tests"
106-
run: yarn test
105+
#- name: "Run Tests"
106+
# run: yarn test
107107

108108
- name: "Authenticate with GCP"
109109
if: github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.action == 'reopened' || github.event.action == 'labeled' || github.event.action == 'unlabeled'))
@@ -240,6 +240,17 @@ jobs:
240240
labels: |-
241241
commit-sha=${{ github.sha }}
242242
243+
- name: "Deploy Tests to Cloud Run"
244+
uses: google-github-actions/deploy-cloudrun@v2
245+
with:
246+
image: europe-docker.pkg.dev/ghost-activitypub/activitypub/activitypub:${{ needs.build-test-push.outputs.migrations_docker_version }}
247+
region: europe-west4
248+
job: stg-pr-${{ github.event.pull_request.number }}-tests
249+
flags: --command="yarn" --args "_test:single" --wait --execute-now
250+
skip_default_labels: true
251+
labels: |-
252+
commit-sha=${{ github.sha }}
253+
243254
- name: "Add route to GCP Load Balancer"
244255
if: ${{ steps.check-labels.outputs.is_ephemeral_staging == 'true' }}
245256
env:
@@ -306,6 +317,18 @@ jobs:
306317
labels: |-
307318
commit-sha=${{ github.sha }}
308319
320+
- name: "Deploy Tests to Cloud Run"
321+
if: ${{ matrix.region == 'europe-west4' }}
322+
uses: google-github-actions/deploy-cloudrun@v2
323+
with:
324+
image: europe-docker.pkg.dev/ghost-activitypub/activitypub/activitypub:${{ needs.build-test-push.outputs.migrations_docker_version }}
325+
region: ${{ matrix.region }}
326+
job: stg-${{ matrix.region_name }}-activitypub-tests
327+
flags: --command="yarn _test:single" --wait --execute-now
328+
skip_default_labels: true
329+
labels: |-
330+
commit-sha=${{ github.sha }}
331+
309332
- name: "Deploy ActivityPub Queue to Cloud Run"
310333
uses: google-github-actions/deploy-cloudrun@v2
311334
with:

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ RUN yarn && \
1111
COPY tsconfig.json .
1212

1313
COPY src ./src
14+
COPY vitest.config.ts vitest.config.ts
1415

1516
ENV NODE_ENV=production
1617
RUN yarn build

src/test/db.ts

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,25 @@ import { afterAll } from 'vitest';
99
export async function createTestDb() {
1010
const systemClient = knex({
1111
client: 'mysql2',
12-
connection: {
13-
host: process.env.MYSQL_HOST,
14-
port: Number.parseInt(process.env.MYSQL_PORT!),
15-
user: process.env.MYSQL_USER,
16-
password: process.env.MYSQL_PASSWORD,
17-
database: 'mysql',
18-
timezone: '+00:00',
19-
},
12+
connection: process.env.MYSQL_SOCKET_PATH
13+
? {
14+
socketPath: process.env.MYSQL_SOCKET_PATH,
15+
user: process.env.MYSQL_USER,
16+
password: process.env.MYSQL_PASSWORD,
17+
database: 'mysql',
18+
timezone: '+00:00',
19+
}
20+
: {
21+
host: process.env.MYSQL_HOST,
22+
port: Number.parseInt(process.env.MYSQL_PORT!),
23+
user: process.env.MYSQL_USER,
24+
password: process.env.MYSQL_PASSWORD,
25+
database: 'mysql',
26+
timezone: '+00:00',
27+
},
2028
});
2129

22-
const dbName = `test_${randomBytes(16).toString('hex')}`;
30+
const dbName = `${process.env.MYSQL_DATABASE?.includes('pr-') ? `${process.env.MYSQL_DATABASE.replace(/-/g, '_')}_` : ''}test_${randomBytes(16).toString('hex')}`;
2331

2432
await systemClient.raw(`CREATE DATABASE ${dbName}`);
2533

@@ -38,14 +46,22 @@ export async function createTestDb() {
3846

3947
const dbClient = knex({
4048
client: 'mysql2',
41-
connection: {
42-
host: process.env.MYSQL_HOST,
43-
port: Number.parseInt(process.env.MYSQL_PORT!),
44-
user: process.env.MYSQL_USER,
45-
password: process.env.MYSQL_PASSWORD,
46-
database: dbName,
47-
timezone: '+00:00',
48-
},
49+
connection: process.env.MYSQL_SOCKET_PATH
50+
? {
51+
socketPath: process.env.MYSQL_SOCKET_PATH,
52+
user: process.env.MYSQL_USER,
53+
password: process.env.MYSQL_PASSWORD,
54+
database: dbName,
55+
timezone: '+00:00',
56+
}
57+
: {
58+
host: process.env.MYSQL_HOST,
59+
port: Number.parseInt(process.env.MYSQL_PORT!),
60+
user: process.env.MYSQL_USER,
61+
password: process.env.MYSQL_PASSWORD,
62+
database: dbName,
63+
timezone: '+00:00',
64+
},
4965
});
5066

5167
afterAll(async () => {

0 commit comments

Comments
 (0)