Run test against new Core Pkg #992
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node | |
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | |
name: Run test against new Core Pkg | |
on: | |
workflow_dispatch: | |
inputs: | |
core_pkg_version: | |
description: 'Core pkg version' | |
required: true | |
jobs: | |
build-test-env: | |
name: Build test env | |
runs-on: ubuntu-latest | |
steps: | |
- env: | |
EVENT_CONTEXT: ${{ toJSON(github.event) }} | |
run: | | |
echo $EVENT_CONTEXT | |
- uses: actions/checkout@v4 | |
- name: Install dependencies | |
uses: ./.github/actions/install | |
with: | |
core_pkg_version: ${{ inputs.core_pkg_version }} | |
- name: Build app | |
uses: ./.github/actions/build | |
with: | |
REACT_APP_APP_ENV: 'test' | |
test-compile: | |
name: Typecheck apps | |
runs-on: ubuntu-latest | |
needs: build-test-env | |
strategy: | |
max-parallel: 6 | |
fail-fast: false | |
matrix: | |
include: | |
- test_name: 'Typecheck webapp' | |
test_command: 'npm run typecheck' | |
- test_name: 'Typecheck cron' | |
test_command: 'npm run typecheck -w apps/cron' | |
- test_name: 'Typecheck websockets' | |
test_command: 'npm run typecheck -w apps/websockets' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Restore dependencies from cache | |
uses: ./.github/actions/install | |
with: | |
core_pkg_version: ${{ inputs.core_pkg_version }} | |
- name: Restore app from cache | |
uses: ./.github/actions/build | |
with: | |
REACT_APP_APP_ENV: 'test' | |
- name: Run ${{matrix.test_name}} | |
run: ${{matrix.test_command}} | |
integration-test: | |
name: Tests | |
runs-on: ubuntu-latest | |
needs: build-test-env | |
# Postgres setup copied from https://gist.github.com/2color/537f8ef13ecec80059abb007839a6878 | |
services: | |
postgres: | |
image: postgres | |
env: | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
--hostname postgres | |
ports: | |
# Maps tcp port 5432 on service container to the host | |
- 5432:5432 | |
strategy: | |
max-parallel: 6 | |
fail-fast: false | |
matrix: | |
include: | |
- test_name: 'Basic tests #1' | |
test_command: 'npm run test:ci -- --config="./lib/jest.config.ts" --shard 1/3' | |
- test_name: 'Basic tests #2' | |
test_command: 'npm run test:ci -- --config="./lib/jest.config.ts" --shard 2/3' | |
- test_name: 'Basic tests #3' | |
test_command: 'npm run test:ci -- --config="./lib/jest.config.ts" --shard 3/3' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Restore dependencies from cache | |
uses: ./.github/actions/install | |
with: | |
core_pkg_version: ${{ inputs.core_pkg_version }} | |
- name: Setup test database | |
run: npx dotenv -e .env.test.local -- npm run prisma:reset | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: us-east-1 | |
mask-aws-account-id: 'no' | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Run permissions api docker image | |
id: run_permissions_api | |
run: | | |
docker inspect postgres | |
docker network ls | |
cat /etc/hosts | |
echo "network ${{ job.services.postgres.network }}" | |
docker run -d --name permissions-api \ | |
-h permissions-api \ | |
-p "3001:3001" \ | |
-e HOST=0.0.0.0 \ | |
-e PORT=3001 \ | |
-v $PWD/nodes_modules/@charmverse/core:/apps/node_modules/@charmverse/core \ | |
--network "${{ job.services.postgres.network }}" \ | |
-e DATABASE_URL=postgres://postgres:postgres@postgres:5432/charmversetest \ | |
${{ steps.login-ecr.outputs.registry }}/charmverse-permissions-api:latest \ | |
node --experimental-specifier-resolution=node ./dist/main.js | |
for i in {1..10}; do | |
docker ps | |
docker logs permissions-api | |
docker inspect permissions-api | |
curl localhost:3001/api/health && { | |
echo "permission api container is up..." | |
break | |
} | |
echo "permission api not up...sleeping" | |
sleep 10 | |
done | |
- name: Restore app from cache | |
uses: ./.github/actions/build | |
with: | |
REACT_APP_APP_ENV: 'test' | |
- name: Run ${{matrix.test_name}} | |
run: ${{matrix.test_command}} |