From 05926df780bda3bfeb618d98897692c3b84bd079 Mon Sep 17 00:00:00 2001 From: Hongxin <5400599+zhx828@users.noreply.github.com> Date: Thu, 8 Aug 2024 15:15:39 -0400 Subject: [PATCH] Split web driver e2e and screenshots actions into two jobs --- .../webdriver-test-using-docker-artifact.yml | 46 ++++++++++++++ .github/workflows/webdriver-test.yml | 60 +++++++++++++++---- docker-compose.yaml | 9 +-- package.json | 2 + 4 files changed, 103 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/webdriver-test-using-docker-artifact.yml diff --git a/.github/workflows/webdriver-test-using-docker-artifact.yml b/.github/workflows/webdriver-test-using-docker-artifact.yml new file mode 100644 index 000000000..5156bea14 --- /dev/null +++ b/.github/workflows/webdriver-test-using-docker-artifact.yml @@ -0,0 +1,46 @@ +name: 'Import docker artifact' +on: + workflow_call: + inputs: + artifacts-name: + required: true + type: string + artifacts-path: + required: true + type: string + wdio-spec: + required: true + type: string + +jobs: + main: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Download artifacts + uses: actions/download-artifact@v3 + with: + name: ${{ inputs.artifacts-name }} + path: ${{ inputs.artifacts-path }} + + - name: List downloaded files + run: ls ${{ inputs.artifacts-path }} + + - name: Load Docker images + run: | + for file in ${{ inputs.artifacts-path }}/*.tar.gz; do + docker load < "$file" + done + + - name: Run Docker containers + run: | + docker compose up -d + WDIO_SPEC=${{ inputs.wdio_spec }} docker compose run --rm wdio + + - name: Archive screenshots + if: failure() + uses: actions/upload-artifact@v2 + with: + name: visual-regression-screenshots + path: ./src/test/javascript/screenshots diff --git a/.github/workflows/webdriver-test.yml b/.github/workflows/webdriver-test.yml index 73010b148..2c29cda7f 100644 --- a/.github/workflows/webdriver-test.yml +++ b/.github/workflows/webdriver-test.yml @@ -1,25 +1,65 @@ -name: Webdriver Test +name: Webdriver Tests on: [push, pull_request] jobs: build: runs-on: ubuntu-latest + outputs: + DOCKER_IMAGES_FOLDER: ${{ steps.set_env.outputs.DOCKER_IMAGES_FOLDER }} + DOCKER_ARTIFACT_NAME: ${{ steps.set_env.outputs.DOCKER_ARTIFACT_NAME }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + + - name: Set env + id: set_env + run: | + echo "DOCKER_ARTIFACT_NAME=docker-images" >> "$GITHUB_OUTPUT" + echo "DOCKER_IMAGES_FOLDER=docker_images" >> "$GITHUB_OUTPUT" - name: Build Docker images run: docker compose build - - name: Run Docker containers + - name: Save Docker images run: | - docker compose up -d - docker compose run --rm wdio + mkdir -p ${{ steps.set_env.outputs.DOCKER_IMAGES_FOLDER }} + + images=$(docker images --format "{{.Repository}}") + # Loop through each image ID + echo "$images" | while IFS= read -r image; do + if [[ $image == oncokb* ]]; then + echo "$image" + + # Save the image as a tar file + docker save -o "${{ steps.set_env.outputs.DOCKER_IMAGES_FOLDER }}/${image}.tar" $image - - name: Archive screenshots - if: failure() - uses: actions/upload-artifact@v2 + # Gzip the tar file + gzip "${{ steps.set_env.outputs.DOCKER_IMAGES_FOLDER }}/${image}.tar" + + echo "Gzipped ${image} to ${{ steps.set_env.outputs.DOCKER_IMAGES_FOLDER }}/${image}.tar.gz" + fi + done + shell: bash + + - name: Upload Docker image artifact + uses: actions/upload-artifact@v3 with: - name: visual-regression-screenshots - path: ./src/test/javascript/screenshots + name: ${{ steps.set_env.outputs.DOCKER_ARTIFACT_NAME }} + path: ${{ steps.set_env.outputs.DOCKER_IMAGES_FOLDER }}/*.tar.gz + + e2e-test: + uses: ./.github/workflows/webdriver-test-using-docker-artifact.yml + needs: build + with: + artifacts-name: ${{ needs.build.outputs.DOCKER_ARTIFACT_NAME }} + artifacts-path: ${{ needs.build.outputs.DOCKER_IMAGES_FOLDER }} + wdio-spec: e2e + + screenshot-test: + uses: ./.github/workflows/webdriver-test-using-docker-artifact.yml + needs: build + with: + artifacts-name: ${{ needs.build.outputs.DOCKER_ARTIFACT_NAME }} + artifacts-path: ${{ needs.build.outputs.DOCKER_IMAGES_FOLDER }} + wdio-spec: screenshot diff --git a/docker-compose.yaml b/docker-compose.yaml index fcdeda000..4ea5b0b5f 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -10,7 +10,7 @@ services: command: yarn start-tls DOCKER=true wdio: - build: + build: context: . dockerfile: ./docker/app/Dockerfile depends_on: @@ -25,7 +25,8 @@ services: environment: - DOCKER=true - FIREBASE_DATABASE_EMULATOR_HOST=firebase:9095 - command: yarn run wdio + - WDIO_SPEC=${WDIO_SPEC} + command: yarn run wdio${WDIO_SPEC:+:$WDIO_SPEC} firebase: build: @@ -38,7 +39,7 @@ services: - "4400:4400" healthcheck: test: ["CMD", "curl", "http://localhost:4400"] - command: firebase emulators:start --import firebase --project oncokb-curation-test-54b6c # change config here + command: firebase emulators:start --import firebase --project oncokb-curation-test-54b6c # change config here chrome: image: seleniarm/standalone-chromium # for those with m1 processors @@ -46,4 +47,4 @@ services: healthcheck: test: ["CMD", "/opt/bin/check-grid.sh", "--host", "0.0.0.0", "--port", "4444"] ports: - - 4444:4444 \ No newline at end of file + - 4444:4444 diff --git a/package.json b/package.json index dc945f25b..5c65217cc 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,8 @@ "updateAPI": "openapi-generator-cli generate -i http://localhost:9090/v3/api-docs -g typescript-axios -o src/main/webapp/app/shared/api/generated/curation --type-mappings set=Array", "updateCoreAPI": "curl http://localhost:8000/oncokb/api/v1/v2/api-docs?group=Private%20APIs | jq '.definitions.ResponseEntity.properties.statusCode.enum |= unique' > /tmp/updateCoreAPI.json && openapi-generator-cli generate -i /tmp/updateCoreAPI.json -g typescript-axios -o src/main/webapp/app/shared/api/generated/core --type-mappings List=any", "wdio": "cross-env TS_NODE_PROJECT=src/test/javascript/tsconfig.json wdio run ./wdio.conf.ts", + "wdio:e2e": "cross-env TS_NODE_PROJECT=src/test/javascript/tsconfig.json wdio run ./wdio.conf.ts --spec ./src/test/javascript/spec/**/*.e2e.ts", + "wdio:screenshot": "cross-env TS_NODE_PROJECT=src/test/javascript/tsconfig.json wdio run ./wdio.conf.ts --spec ./src/test/javascript/spec/**/*.screenshot.ts", "webapp:build": "yarn run clean-www && yarn run webapp:build:dev --", "webapp:build:dev": "webpack --config webpack/webpack.dev.js --env stats=minimal", "webapp:build:prod": "webpack --config webpack/webpack.prod.js --progress=profile",