Merge pull request #1311 from hallieswan/AG-1471_AG-1473_AG-1474 #2
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
name: Build Data Image and Run End-to-end Tests | |
on: push | |
jobs: | |
e2e: | |
# Run in Sage repo on develop or main branches | |
# and on all branches in user-owned forks | |
if: ${{ github.ref_name == 'develop' || github.ref_name == 'main' || github.actor == github.repository_owner }} | |
timeout-minutes: 60 | |
runs-on: ubuntu-20.04 | |
environment: e2e | |
env: | |
CI: true | |
LOCAL_DATA_PATH: './local/data' | |
LOCAL_TEAM_IMAGES_DIR: './local/data/team_images' | |
LOCAL_COLLECTIONS_PATH: './scripts/collections.csv' | |
LOCAL_IMPORT_SCRIPT_PATH: './docker/import-data.sh' | |
LOCAL_CREATE_INDEXES_PATH: './scripts/mongo-create-Indexes.js' | |
DOCKER_COMPOSE_PATH: './docker/docker-compose.yml' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: get data image tag, data manifest id, and data version | |
env: | |
PACKAGE_JSON_PATH: 'package.json' | |
DATA_IMAGE_NAME: '${{ vars.DB_NAME }}/data' | |
run: | | |
DATA_MANIFEST_ID=$(jq -r '."data-file"' "${{ env.PACKAGE_JSON_PATH }}") | |
echo "DATA_MANIFEST_ID=${DATA_MANIFEST_ID}" >> "$GITHUB_ENV" | |
DATA_VERSION=$(jq -r '."data-version"' "${{ env.PACKAGE_JSON_PATH }}") | |
echo "DATA_VERSION=${DATA_VERSION}" >> "$GITHUB_ENV" | |
DATA_IMAGE_TAG="${{ env.DATA_IMAGE_NAME }}:${DATA_MANIFEST_ID}-v${DATA_VERSION}" | |
echo "DATA_IMAGE_TAG=${DATA_IMAGE_TAG}" >> "$GITHUB_ENV" | |
# TODO - check remote repository | |
- name: check whether image exists | |
id: image-exists | |
run: | | |
echo "==> data image tag: ${{ env.DATA_IMAGE_TAG }}" | |
echo "IMAGE_EXISTS=false" >> "$GITHUB_ENV" | |
# TODO - move into job which conditionally runs based on IMAGE_EXISTS | |
# https://github.com/actions/setup-python/issues/807 | |
- name: create placeholder requirements.txt file | |
run: touch ./requirements.txt | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.9' | |
cache: 'pip' | |
- name: install synapseclient | |
run: | | |
pip install --upgrade synapseclient | |
- name: download data from synapse | |
timeout-minutes: 10 | |
env: | |
SYNAPSE_AUTH_TOKEN: ${{ secrets.SYNAPSE_AUTH_TOKEN }} | |
run: | | |
echo "==> make directory for team images" | |
mkdir -p "${{ env.LOCAL_TEAM_IMAGES_DIR }}" | |
echo "==> download manifest file from Synapse" | |
synapse get --downloadLocation "${{ env.LOCAL_DATA_PATH }}" -v "${{ env.DATA_VERSION }}" "${{ env.DATA_MANIFEST_ID }}" | |
echo "==> download all files referenced in manifest from Synapse" | |
cat "${{ env.LOCAL_DATA_PATH }}"/data_manifest.csv | tail -n +2 | while IFS=, read -r id version; do | |
echo "===> Downloading ${id}.${version}" | |
synapse get --downloadLocation "${{ env.LOCAL_DATA_PATH }}" -v "${version}" "${id}" | |
done | |
echo "==> download team images" | |
synapse get -r --downloadLocation "${{ env.LOCAL_TEAM_IMAGES_DIR }}/" "${{ vars.TEAM_IMAGES_ID }}" | |
- name: build image | |
env: | |
DOCKERFILE_PATH: './docker/Dockerfile' | |
run: | | |
docker build \ | |
-t "${{ env.DATA_IMAGE_TAG }}" \ | |
-f "${{ env.DOCKERFILE_PATH }}" \ | |
--build-arg LOCAL_DATA_PATH="${{ env.LOCAL_DATA_PATH }}" \ | |
--build-arg LOCAL_COLLECTIONS_PATH="${{ env.LOCAL_COLLECTIONS_PATH }}" \ | |
--build-arg LOCAL_IMPORT_SCRIPT_PATH="${{ env.LOCAL_IMPORT_SCRIPT_PATH }}" \ | |
--build-arg LOCAL_CREATE_INDEXES_PATH="${{ env.LOCAL_CREATE_INDEXES_PATH }}" \ | |
. | |
# TODO - push image to remote repository | |
# TODO - move into job that pulls image from remote repository | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 16 | |
- name: install dependencies | |
run: npm install | |
- name: install Playwright Browsers | |
run: npx playwright install --with-deps | |
- name: start database, server, and app | |
env: | |
DB_USER: ${{ secrets.DB_USER }} | |
DB_PASS: ${{ secrets.DB_PASS }} | |
DB_PORT: ${{ vars.DB_PORT }} | |
DB_NAME: ${{ vars.DB_NAME }} | |
run: | | |
echo "==> start database and data containers" | |
docker-compose -f "${{ env.DOCKER_COMPOSE_PATH }}" up -d | |
echo "==> wait for data container to finish seeding database container" | |
DATA_CONTAINER=$(docker compose -f "${{ env.DOCKER_COMPOSE_PATH }}" ps -a --format '{{.Name}}' mongo-seed) | |
docker wait "${DATA_CONTAINER}" | |
echo "==> start server and app in background and wait for server to grab port" | |
MONGODB_HOST="localhost" MONGODB_PORT="${{ env.DB_PORT }}" APP_ENV="e2e" npm run dev >/dev/null 2>&1 & | |
sleep 5 | |
- name: run e2e tests | |
run: npx playwright test | |
- name: clean up database, server, and app | |
env: | |
DB_USER: ${{ secrets.DB_USER }} | |
DB_PASS: ${{ secrets.DB_PASS }} | |
DB_PORT: ${{ vars.DB_PORT }} | |
DB_NAME: ${{ vars.DB_NAME }} | |
run: | | |
echo "==> stop app" | |
pid=$(lsof -i :3000 -t) && kill ${pid} | |
echo "==> stop server" | |
pid=$(lsof -i :8080 -t) && kill ${pid} | |
echo "==> stop database" | |
docker-compose -f "${{ env.DOCKER_COMPOSE_PATH }}" down | |
- uses: actions/upload-artifact@v4 | |
if: ${{ !cancelled() }} | |
with: | |
name: playwright-report | |
path: playwright-report/ | |
retention-days: 5 |