Skip to content

Commit 617c76f

Browse files
authored
chore: add script for showing playwright report (#1879)
This PR adds a neat little scrip `gh:show-report`, which uses the [GitHub CLI](https://cli.github.com/) and playwright to download and show the latest failed test report of the current branch. GitHub CLI needs to be installed manually.
1 parent 706e8a2 commit 617c76f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"lint:ci:all": "pnpm run lint:all --format @microsoft/eslint-formatter-sarif --output-file eslint-results.sarif",
1616
"publint:all": "pnpm -r --parallel --aggregate-output exec publint",
1717
"prepare": "simple-git-hooks",
18+
"gh:show-report": "./scripts/show-last-test-report.sh",
1819
"preinstall": "npx only-allow pnpm"
1920
},
2021
"devDependencies": {

scripts/show-last-test-report.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env sh
2+
3+
# check if gh cli is installed
4+
if ! command -v gh &>/dev/null; then
5+
echo "gh CLI is not installed. Please install it first: https://github.com/cli/cli#installation"
6+
exit 1
7+
fi
8+
9+
# Create temporary directory
10+
TMP_DIR=$(mktemp -d)
11+
12+
# Create shell trap to clean up temporary directory
13+
function cleanup {
14+
rm -r ${TMP_DIR}
15+
}
16+
trap cleanup EXIT
17+
18+
# query the id of the last failed run for the current branch
19+
GH_LAST_RUN_ID=$(gh run list -s failure -b $(git branch --show-current) --json "createdAt,databaseId" --jq "sort_by(.createdAt) | last.databaseId")
20+
21+
# download report
22+
gh run download $GH_LAST_RUN_ID -D $TMP_DIR -p "html-report--attempt-1"
23+
24+
# show report
25+
(cd $TMP_DIR/html-report--attempt-1/packages/sit-onyx && pnpm dlx playwright show-report)

0 commit comments

Comments
 (0)