1- #! /bin/bash
1+ #! /usr/bin/env bash
2+
23# This Source Code Form is subject to the terms of the Mozilla Public
34# License, v. 2.0. If a copy of the MPL was not distributed with this
45# file, you can obtain one at https://mozilla.org/MPL/2.0/.
56#
67# Copyright Oxide Computer Company
78
9+ # Run this script on a branch to download the E2E failure traces from the
10+ # latest run on that branch. Pass a commit (full hash, not abbreviated)
11+ # to pull the traces for that commit.
12+
813set -e
914set -o pipefail
1015
11- # Get the ID of the last github actions run if there was one
12- BRANCH= $( git rev-parse --abbrev-ref HEAD )
13- RUN_ID= $( gh run list -b " $BRANCH " -w CI -L 1 --json databaseId --jq ' .[0].databaseId ' )
16+ DIR= " ci-e2e-traces "
17+
18+ COMMIT= $1
1419
15- if [ -z " $RUN_ID " ]; then
16- echo " No action runs found for this branch"
17- exit 0
20+ # Get the ID of the last github actions run if there was one. If a commit
21+ # is specified, use that, otherwise
22+ if [ -n " $COMMIT " ]; then
23+ echo -e " Looking at latest run on commit $COMMIT "
24+ RUN_ID=$( gh run list --commit " $COMMIT " -w CI -L 1 --json databaseId --jq ' .[0].databaseId' )
25+ if [ -z " $RUN_ID " ]; then
26+ echo " No action runs found. Make sure to use full commit SHA."
27+ exit 0
28+ fi
29+ else
30+ BRANCH=$( git rev-parse --abbrev-ref HEAD)
31+ echo -e " Looking at latest run on branch $BRANCH "
32+ RUN_ID=$( gh run list -b " $BRANCH " -w CI -L 1 --json databaseId --jq ' .[0].databaseId' )
33+ if [ -z " $RUN_ID " ]; then
34+ echo " No action runs found"
35+ exit 0
36+ fi
1837fi
1938
20- if [ -d " test-results" ] && [ -f " test-results/.run" ] && [ " $RUN_ID " == " $( cat test-results/.run) " ]; then
39+
40+ if [ -e " $DIR /.run" ] && [ " $RUN_ID " == " $( cat $DIR /.run) " ]; then
2141 : # Do nothing, the test results are already up to date
2242else
23- rm -rf test-results
24- echo " Attempting to download test failure traces for current branch ..."
25- gh run download $RUN_ID
26- echo $RUN_ID > test-results /.run
43+ rm -rf $DIR
44+ echo " Downloading traces..."
45+ gh run download $RUN_ID --dir $DIR
46+ echo $RUN_ID > $DIR /.run
2747fi
2848
29-
30- echo " Choose a test trace to view"
31- select test in $( ls test-results) ; do
32- npx playwright show-trace test-results/$test /trace.zip
49+ # gnarly select and re-find is to take filepath noise out of the select list
50+ echo " Choose a trace to view"
51+ select trace in $( find $DIR -name " trace.zip" | sed ' s/.*\/\(.*\)\/trace.zip/\1/' ) ; do
52+ selected_trace=$( find $DIR -path " */$trace " /trace.zip)
53+ npx playwright show-trace " $selected_trace "
3354 exit 0
34- done
55+ done
0 commit comments