Repository navigation
Expand file tree
/
Copy pathrun-acceptance
More file actions
executable file
·101 lines (83 loc) · 2.26 KB
/
Copy pathrun-acceptance
File metadata and controls
executable file
·101 lines (83 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env bash
set -euo pipefail
readonly repository="cli/cli"
readonly workflow="acceptance.yml"
readonly operating_systems="all ubuntu-latest windows-latest macos-latest"
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
readonly repo_root
readonly testdata_dir="$repo_root/acceptance/testdata"
usage() {
cat <<EOF
Usage: script/run-acceptance [REF] [COMMAND] [OS]
Dispatch acceptance tests using the workflow from a branch or tag. REF defaults
to the current branch. COMMAND and OS default to "all".
List available command groups:
script/run-acceptance groups
EOF
}
contains() {
local expected="$1"
shift
local candidate
for candidate in "$@"; do
if [[ "$candidate" == "$expected" ]]; then
return 0
fi
done
return 1
}
test_groups() {
echo "all"
local directory
for directory in "$testdata_dir"/*; do
if [[ -d "$directory" ]]; then
basename "$directory"
fi
done
}
if [[ "${1:-}" == "groups" ]]; then
test_groups
exit
fi
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
usage
exit
fi
ref="${1:-}"
command="${2:-all}"
operating_system="${3:-all}"
read -r -a operating_system_values <<<"$operating_systems"
if ! contains "$operating_system" "${operating_system_values[@]}"; then
echo "invalid operating system: $operating_system" >&2
exit 1
fi
if [[ -z "$ref" ]]; then
ref="$(git branch --show-current)"
if [[ -z "$ref" ]]; then
echo "ref is required when HEAD is detached" >&2
exit 1
fi
fi
active_runs="$(gh run list \
--repo "$repository" \
--workflow "$workflow" \
--limit 100 \
--json databaseId,headBranch,status,url \
--jq '.[] | select(.status != "completed") | "\(.databaseId)\t\(.status)\t\(.headBranch)\t\(.url)"')"
if [[ -n "$active_runs" ]]; then
echo "warning: acceptance test workflows are already in flight; another run might be rate limited" >&2
printf '%s\n' "$active_runs" >&2
if [[ -t 0 ]]; then
read -r -p "Dispatch another acceptance test run? [y/N] " response
case "$response" in
y | Y | yes | YES | Yes) ;;
*) exit 1 ;;
esac
fi
fi
gh workflow run "$workflow" \
--repo "$repository" \
--ref "$ref" \
--raw-field "command=$command" \
--raw-field "os=$operating_system"
printf 'Dispatched acceptance tests for %s\n' "$ref"