Skip to content

Ops - Actions Updates #120

Ops - Actions Updates

Ops - Actions Updates #120

name: Playwright Test
on:
workflow_dispatch:
push:
branches: [main]
pull_request:
branches: [main]
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
checks: write # for dorny/test-reporter
pull-requests: write # for leaving a comment on PR
env:
NODEJS_VERSION: 20
TESULTS_API_TOKEN: ${{ secrets.TESULTS_API_TOKEN }}
LH_TESULTS_API_TOKEN: ${{ secrets.LH_TESULTS_API_TOKEN }}
jobs:
set_job_params:
name: Set Job Params
runs-on: ubuntu-latest
outputs:
pw-version: ${{ steps.set_version.outputs.PW_VERSION }}
pw-tesults-target-token: ${{ steps.generate-secret.outputs.secret-token }}
steps:
- uses: actions/checkout@v4
- name: Setup NodeJS SDK ${{ env.NODEJS_VERSION }}
uses: actions/setup-node@v4
with:
cache: yarn
cache-dependency-path: yarn.lock
node-version: ${{ env.NODEJS_VERSION }}
# used to create/delete branch target
- name: Set Branch Name Environment Variable
run: |
# Short name for current branch. For PRs, use target branch (base ref)
BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
- name: Yarn Install
run: yarn install --mode=skip-build
- name: Create Tesults Target Token
run: node ./.scripts/create-delete-branch-target.js create
# - name: Upload Tesults Token
# uses: actions/upload-artifact@v4
# with:
# name: tesultsToken
# path: tesultsToken.txt
# echo "PW_TESULTS_TOKEN=$(cat tesultsToken.txt)" >> $GITHUB_ENV
- name: Set Tesults Target Token Masked Output
id: generate-secret
shell: bash
run: |
PW_TESULTS_TARGET_TOKEN=$(cat tesultsToken.txt)
echo "::add-mask::$PW_TESULTS_TARGET_TOKEN"
echo "secret-token=$PW_TESULTS_TARGET_TOKEN" >> "$GITHUB_OUTPUT"
# - name: Set Tesults Target Token Environment Variable
# run: echo "PW_TESULTS_TARGET_TOKEN=$(cat tesultsToken.txt)" >> $GITHUB_ENV
# - name: Set Tesults Token Github Output
# id: set_tesults_token
# run: echo "PW_TESULTS_TARGET_TOKEN=${{ env.PW_TESULTS_TARGET_TOKEN }}" >> $GITHUB_OUTPUT
- name: Get Playwright Package Version
id: get-version
uses: beaconbrigade/package-json-version@v0.3.1
with:
path: node_modules/playwright
- name: Set Package Version
id: set_version
run: echo "PW_VERSION=${{ steps.get-version.outputs.version }}" >> $GITHUB_OUTPUT
playwright_test:
name: Playwright Test
needs: set_job_params
strategy:
fail-fast: false
matrix:
shardIndex: [1, 2, 3, 4]
shardTotal: [4]
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/playwright:v${{ needs.set_job_params.outputs.pw-version }}-jammy
steps:
- uses: actions/checkout@v4
- name: Yarn Install
run: yarn install
# - name: Download Tesults Token Artifact
# uses: actions/download-artifact@v4
# with:
# name: tesultsToken
# - name: Set Tesults Target
# run: echo "PW_TESULTS_TOKEN=$(cat tesultsToken.txt)" >> $GITHUB_ENV
- name: Set Tesults Target Environment Variable
run: echo "PW_TESULTS_TARGET_TOKEN=${{ needs.set_job_params.outputs.pw-tesults-target-token }}" >> $GITHUB_ENV
- run: echo "${{ env.PW_TESULTS_TARGET_TOKEN }}"
- name: Get Tesults Target Token Secret
shell: bash
run: |
PW_TESULTS_SECRET_TOKEN="${{ needs.set_job_params.outputs.pw-tesults-target-token }}"
echo "::add-mask::$PW_TESULTS_SECRET_TOKEN"
echo "We retrieved our masked secret: $PW_TESULTS_SECRET_TOKEN"
echo "PW_TESULTS_TARGET_TOKEN=$PW_TESULTS_SECRET_TOKEN" >> $GITHUB_ENV
- run: echo "${{ env.PW_TESULTS_TARGET_TOKEN }}"
- name: Run Tests
run: yarn test:ci --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
env:
HOME: /root # required for playwright to run in container
- name: Upload blob report to GitHub Actions Artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: all-blob-reports-${{ matrix.shardIndex }}
path: blob-report/
retention-days: 10
# uploading to have a backup of the test-results in case reporting fails
- name: Upload test-results to GitHub Actions Artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.shardIndex }}
path: test-results/
retention-days: 10
if-no-files-found: warn
reporting:
if: ${{ always() }}
needs: playwright_test
name: Reporting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup NodeJS SDK ${{ env.NODEJS_VERSION }}
uses: actions/setup-node@v4
with:
cache: yarn
cache-dependency-path: yarn.lock
node-version: ${{ env.NODEJS_VERSION }}
- name: Yarn Install
run: yarn install
- name: Download blob reports from GitHub Actions Artifacts
uses: actions/download-artifact@v4
with:
pattern: all-blob-reports-*
merge-multiple: true
path: all-blob-reports
# xml report use by dorny-test-reporter
- name: Merge into XML Report
run: PLAYWRIGHT_JUNIT_OUTPUT_NAME=junit.xml npx playwright merge-reports --reporter=junit ./all-blob-reports
- name: Test Report
uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: Playwright Test Report
path: "**/junit.xml"
reporter: java-junit
fail-on-error: 'false'
- name: Merge into HTML Report
run: npx playwright merge-reports --reporter html ./all-blob-reports
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload HTML report for Pages
uses: actions/upload-pages-artifact@v3
with:
name: github-pages
path: playwright-report
retention-days: 14
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
- name: Message PR of Artifact Published
if: ${{ always() && github.event_name == 'pull_request' }}
uses: thollander/actions-comment-pull-request@main
with:
message: |
[Click here for Github Pages Playwright Report](${{ steps.deployment.outputs.page_url }})
[Click here to see Tesults Dashboard](https://www.tesults.com/results/rsp/view/status/project/48242328-a7eb-4ab4-8065-3a3686634e5c/group/playwright-boilerplate)
comment_tag: playwright_message
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
lighthouse_test:
if: ${{ always() }}
name: Lighthouse
needs: set_job_params
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/playwright:v${{ needs.set_job_params.outputs.pw-version }}-jammy
steps:
- uses: actions/checkout@v4
- name: Yarn Install
run: yarn install
- name: Run Lighthouse
run: yarn test:lighthouse
env:
HOME: /root # required for playwright to run in container
- name: Upload Lighthouse Report
uses: actions/upload-artifact@v4
with:
name: lighthouse-report
path: tests/lighthouse/reports
retention-days: 10
- name: Message PR of Artifact Published
if: ${{ always() && github.event_name == 'pull_request' }}
uses: thollander/actions-comment-pull-request@main
with:
message: |
[Click here to see Tesults Lighthouse Report](https://www.tesults.com/results/rsp/view/results/target/48242328-a7eb-4ab4-8065-3a3686634e5c-1701748288944)
comment_tag: lighthouse_message
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}