Ops - Actions Updates #105
Workflow file for this run
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: 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 }} | |
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: Set Tesults Token Output | |
run: node ./.scripts/create-delete-branch-target.js create | |
- name: Upload Tesults Token | |
uses: actions/upload-artifact@v4 | |
with: | |
name: tesultsToken | |
path: tesultsToken.txt | |
- name: Get Playwright Package Version | |
id: get-version | |
uses: beaconbrigade/[email protected] | |
with: | |
path: node_modules/playwright | |
- name: Write Version to File | |
run: echo "${{ steps.get-version.outputs.version }}" > playwrightPackageVersion.txt | |
# - name: Upload Playwright Package Version | |
# uses: actions/upload-artifact@v4 | |
# with: | |
# name: playwrightPackageVersion | |
# path: playwrightPackageVersion.txt | |
# retention-days: 10 | |
# - name: Download Playwright Package Version | |
# uses: actions/download-artifact@v4 | |
# with: | |
# name: playwrightPackageVersion | |
# path: ${{ env.WORKING_DIRECTORY }} | |
- name: Set Package Version | |
id: set_version | |
run: | | |
echo "PW_VERSION=$(cat playwrightPackageVersion.txt)" >> $GITHUB_OUTPUT | |
playwright_test: | |
name: Playwright Test | |
needs: set_job_params | |
strategy: | |
fail-fast: false | |
matrix: | |
shard: [1/4, 2/4, 3/4, 4/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: 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 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: Run Tests | |
run: yarn test:ci --shard ${{ matrix.shard }} | |
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.shard }} | |
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.shard }} | |
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 | |
# test-results directory is only created when a test fails, if all pass there is no dir to download | |
# - name: Check for test-results Artifact | |
# uses: xSAVIKx/artifact-exists-action@v0 | |
# id: check-artifact | |
# with: | |
# name: test-results | |
# # TODO - watch for upcoming ignore feature on this so that the above step can be removed | |
# - name: Download test-results from GitHub Actions Artifacts | |
# uses: actions/download-artifact@v3 | |
# if: ${{ steps.check-artifact.outputs.exists == 'true' }} | |
# with: | |
# name: test-results | |
# path: test-results | |
# 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: 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: 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 }} | |