|
| 1 | +--- |
| 2 | +name: 'Reusable - Run E2E Tests (Matrix)' |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_call: |
| 6 | + inputs: |
| 7 | + DOCKER_IMAGE_TAG: |
| 8 | + type: string |
| 9 | + description: 'The full Docker image tag being tested' |
| 10 | + required: false |
| 11 | + COMMIT_HASH: |
| 12 | + type: string |
| 13 | + description: 'The commit hash from which to check out the repository' |
| 14 | + required: false |
| 15 | + |
| 16 | +jobs: |
| 17 | + get-e2e-files: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + outputs: |
| 20 | + file_list: ${{ steps.generate-file-list.outputs.file_list }} |
| 21 | + steps: |
| 22 | + - name: Checkout Target Repo Code (to find test files) |
| 23 | + uses: actions/checkout@v5 |
| 24 | + with: |
| 25 | + ref: ${{ inputs.COMMIT_HASH }} |
| 26 | + |
| 27 | + - name: Install jq (JSON processor) |
| 28 | + run: sudo apt-get update && sudo apt-get install -y jq |
| 29 | + |
| 30 | + - name: Generate list of E2E test files |
| 31 | + id: generate-file-list |
| 32 | + env: |
| 33 | + E2E_DIR: frontend/cypress/e2e |
| 34 | + run: | |
| 35 | + if [ -d "$E2E_DIR" ] && [ "$(ls -A $E2E_DIR)" ]; then |
| 36 | + FILES=$(ls $E2E_DIR | jq -R . | jq -s . | jq -c) |
| 37 | + echo "Found test files: $FILES" |
| 38 | + else |
| 39 | + echo "No test files found in $E2E_DIR or directory does not exist." |
| 40 | + FILES="[]" |
| 41 | + fi |
| 42 | + echo "file_list=$FILES" >> $GITHUB_OUTPUT |
| 43 | +
|
| 44 | + e2e: |
| 45 | + needs: get-e2e-files |
| 46 | + runs-on: ubuntu-24.04 |
| 47 | + strategy: |
| 48 | + fail-fast: false |
| 49 | + matrix: |
| 50 | + file: ${{ fromJSON(needs.get-e2e-files.outputs.file_list) }} |
| 51 | + env: |
| 52 | + BRANCH_NAME: ${{ github.ref_name || github.base_ref }} |
| 53 | + COMMIT_REF: ${{ inputs.COMMIT_HASH || github.ref_name }} |
| 54 | + |
| 55 | + steps: |
| 56 | + - name: Checkout repo |
| 57 | + uses: actions/checkout@v5 |
| 58 | + with: |
| 59 | + ref: ${{ env.COMMIT_REF }} |
| 60 | + |
| 61 | + - name: Start application stack with Docker Compose |
| 62 | + run: cd docker && docker compose -f docker-compose.yml -f docker-compose.e2e.yml up -d |
| 63 | + |
| 64 | + - name: Set up node for Cypress |
| 65 | + uses: actions/setup-node@v4 |
| 66 | + with: |
| 67 | + node-version: ${{ vars.NODE_VERSION }} |
| 68 | + |
| 69 | + - name: Cypress run e2e tests |
| 70 | + uses: cypress-io/github-action@v6 |
| 71 | + with: |
| 72 | + working-directory: frontend |
| 73 | + install: true |
| 74 | + wait-on: 'http://localhost:4200/' |
| 75 | + wait-on-timeout: 300 |
| 76 | + browser: chrome |
| 77 | + headed: false |
| 78 | + config: baseUrl=http://localhost:4200/ |
| 79 | + spec: cypress/e2e/${{ matrix.file }} |
| 80 | + |
| 81 | + - uses: actions/upload-artifact@v4 |
| 82 | + if: always() |
| 83 | + with: |
| 84 | + name: cypress-screenshots for ${{ matrix.file }} |
| 85 | + path: frontend/cypress/screenshots |
0 commit comments