|
| 1 | +name: "Run Snapshot Tests" |
| 2 | +description: "Run snapshot tests against Preprod environment" |
| 3 | + |
| 4 | +inputs: |
| 5 | + checkout_ref: |
| 6 | + description: "Ref to checkout" |
| 7 | + required: true |
| 8 | + release_name: |
| 9 | + description: "S3 folder to use for references and storing results (e.g. 'release1', 'latest-main')" |
| 10 | + required: true |
| 11 | + |
| 12 | +runs: |
| 13 | + using: "composite" |
| 14 | + steps: |
| 15 | + - name: "Checkout code" |
| 16 | + uses: actions/checkout@v5 |
| 17 | + with: |
| 18 | + ref: ${{ inputs.checkout_ref }} |
| 19 | + path: "code-for-snapshot-tests" |
| 20 | + |
| 21 | + - name: "Configure AWS credentials for environment" |
| 22 | + uses: aws-actions/configure-aws-credentials@v5 |
| 23 | + with: |
| 24 | + role-session-name: GitHubActionsSession |
| 25 | + role-to-assume: ${{ secrets.IAM_ROLE }} |
| 26 | + aws-region: ${{ env.AWS_REGION }} |
| 27 | + |
| 28 | + - name: Cache node modules |
| 29 | + id: cache-npm |
| 30 | + uses: actions/cache@v4 |
| 31 | + env: |
| 32 | + cache-name: cache-node-modules |
| 33 | + with: |
| 34 | + path: ~/.npm |
| 35 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('./code-for-snapshot-tests**/package-lock.json') }} |
| 36 | + |
| 37 | + - name: "Install dependencies" |
| 38 | + shell: bash |
| 39 | + working-directory: "./code-for-snapshot-tests" |
| 40 | + run: | |
| 41 | + npm ci --ignore-scripts |
| 42 | +
|
| 43 | + - name: "Get current week number and playwright version" |
| 44 | + id: cache_key_values |
| 45 | + shell: bash |
| 46 | + working-directory: "./code-for-snapshot-tests" |
| 47 | + run: | |
| 48 | + echo "week_num=$(date -u +'%Y-%V')" | tee -a $GITHUB_OUTPUT |
| 49 | + echo "playwright_version=$(npm view @playwright/test version)" | tee -a $GITHUB_OUTPUT |
| 50 | +
|
| 51 | + - name: "Get current date" |
| 52 | + id: folder_name_value |
| 53 | + shell: bash |
| 54 | + working-directory: "./code-for-snapshot-tests" |
| 55 | + run: | |
| 56 | + echo "current_datetime=$(date -u +'%Y-%m-%dT%H%M%SZ')" | tee -a $GITHUB_OUTPUT |
| 57 | +
|
| 58 | + - name: "Cache Playwright browsers" |
| 59 | + uses: actions/cache@v4 |
| 60 | + id: playwright-cache |
| 61 | + with: |
| 62 | + path: ~/.cache/ms-playwright |
| 63 | + key: ${{ runner.os }}-playwright-${{ steps.cache_key_values.outputs.week_num }}-${{ steps.cache_key_values.outputs.playwright_version }}-${{ hashFiles('**/playwright.config*') }} |
| 64 | + |
| 65 | + - name: "Install Playwright browsers (Chromium, Firefox)" |
| 66 | + if: steps.playwright-cache.outputs.cache-hit != 'true' |
| 67 | + shell: bash |
| 68 | + working-directory: "./code-for-snapshot-tests" |
| 69 | + run: | |
| 70 | + npx playwright install chromium firefox --with-deps |
| 71 | +
|
| 72 | + - name: "Install Playwright browsers (Webkit)" |
| 73 | + shell: bash |
| 74 | + working-directory: "./code-for-snapshot-tests" |
| 75 | + run: | |
| 76 | + npx playwright install webkit --with-deps |
| 77 | +
|
| 78 | + - name: "Download snapshots from ${{ inputs.release_name }} S3 bucket" |
| 79 | + shell: bash |
| 80 | + working-directory: "./code-for-snapshot-tests" |
| 81 | + run: | |
| 82 | + aws s3 sync s3://${{ env.AWS_S3_ARTEFACTS_BUCKET }}/playwright/reference/${{ inputs.release_name }}/ ./e2e/snapshot/ |
| 83 | +
|
| 84 | + - name: "Run Playwright snapshot tests (no update)" |
| 85 | + shell: bash |
| 86 | + working-directory: "./code-for-snapshot-tests" |
| 87 | + run: | |
| 88 | + npm run e2e:snapshot -- --config=playwright.config.cross-browser.ts |
| 89 | + env: |
| 90 | + CURRENT_DATETIME: ${{ steps.folder_name_value.outputs.current_datetime }} |
| 91 | + CHECKOUT_REF: ${{ inputs.checkout_ref }} |
| 92 | + |
| 93 | + - name: "Upload snapshots to ${{ inputs.release_name }} S3 bucket with tag ${{ steps.folder_name_value.outputs.current_datetime }}-${{ inputs.checkout_ref }}" |
| 94 | + if: failure() |
| 95 | + shell: bash |
| 96 | + working-directory: "./code-for-snapshot-tests" |
| 97 | + run: | |
| 98 | + aws s3 sync --delete ./e2e/snapshot/snapshot_review/ s3://${{ env.AWS_S3_ARTEFACTS_BUCKET }}/playwright/snapshots-for-review/${{ inputs.release_name }}/${{ steps.folder_name_value.outputs.current_datetime }}-${{ inputs.checkout_ref }}/ |
| 99 | +
|
| 100 | + - name: "Upload report" |
| 101 | + uses: actions/upload-artifact@v5 |
| 102 | + if: always() |
| 103 | + with: |
| 104 | + name: playwright-report-snapshot-${{ inputs.release_name }}-${{ steps.folder_name_value.outputs.current_datetime }}-${{ inputs.checkout_ref }} |
| 105 | + path: playwright-report/ |
| 106 | + retention-days: 30 |
0 commit comments