Publish playwright test reports #137
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: Publish playwright test reports | |
on: | |
workflow_run: | |
workflows: [PR checks] | |
types: [completed] | |
jobs: | |
publish_report: | |
name: publish-e2e-report | |
runs-on: ubuntu-latest | |
continue-on-error: true | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: gh-pages | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Download test report artifact | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: context.payload.workflow_run.id, | |
}); | |
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { | |
return artifact.name == "playwright-report" | |
})[0]; | |
let download = await github.rest.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: matchArtifact.id, | |
archive_format: 'zip', | |
}); | |
let fs = require('fs'); | |
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/playwright-report.zip`, Buffer.from(download.data)); | |
- name: Unzip artifact and cleanup | |
run: | | |
mkdir tmp | |
unzip playwright-report.zip -d tmp | |
# Extract parent workflow info from info.txt in artifact | |
HTML_REPORT_URL_PATH=$(grep "HTML_REPORT_URL_PATH:" tmp/info.txt | sed 's/HTML_REPORT_URL_PATH://g') | |
echo "HTML_REPORT_URL_PATH=$HTML_REPORT_URL_PATH" >> "$GITHUB_ENV" | |
mkdir -p $HTML_REPORT_URL_PATH | |
mv -f tmp/* $HTML_REPORT_URL_PATH | |
rm -rf playwright-report.zip | |
rm -rf tmp | |
# user git configs are needed for git commands to work | |
# actual authentication is done using secrets.GITHUB_TOKEN with write permission | |
- name: Set Git User | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub Action" | |
- name: Push HTML Report | |
timeout-minutes: 3 | |
run: | | |
git add . | |
git commit -m "workflow: add HTML report published at $HTML_REPORT_URL_PATH" | |
# In case if another action job pushed to gh-pages while we are rebasing for the current job | |
while true; do | |
git pull --rebase | |
if [ $? -ne 0 ]; then | |
echo "Failed to rebase. Please review manually." | |
exit 1 | |
fi | |
git push | |
if [ $? -eq 0 ]; then | |
echo "Successfully pushed HTML report to repo." | |
exit 0 | |
fi | |
done | |
- name: Output Report URL as Worfklow Annotation | |
run: | | |
FULL_HTML_REPORT_URL=https://canonical.github.io/lxd-ui/$HTML_REPORT_URL_PATH | |
echo "::notice title=Published Playwright Test Report::$FULL_HTML_REPORT_URL" |