-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbypass-another-branch.sh
executable file
·72 lines (54 loc) · 1.54 KB
/
bypass-another-branch.sh
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
#!/bin/bash
info() {
echo "info: $1" >&2
}
error() {
echo "error: $1" >&2
}
help() {
echo "$1" >&2
}
if [ $# -ne 1 ]; then
help "usage: $0 repo"
help " repo path to local git repository"
help
help "outputs list of *unique* workflow files found in all *remote* branches of the repo"
exit 1
fi
LOCAL_REPO="$1"
if [ ! -d "$LOCAL_REPO/.git" ]; then
error "$LOCAL_REPO is not git repository"
exit 2
fi
OUTPUT_DIR="$(mktemp -d)"
HASH_DIR="$(mktemp -d)"
REMOTE="$(git -C "$LOCAL_REPO" remote get-url origin)"
# https://github.com/dead-claudia/github-limits
if ! echo "$REMOTE" | grep -qE '^https://github\.com/[0-9A-Za-z-]+/[0-9A-Za-z_.-]+$'; then
error "remote '$REMOTE' does not match regex"
exit 1
fi
OWNER="$(echo "$REMOTE" | cut -d / -f 4)"
REPO="$(echo "$REMOTE" | cut -d / -f 5)"
git -C "$LOCAL_REPO" branch --remotes | grep -vF 'HEAD ->' | cut -d ' ' -f 3 | while read branch; do
git -C "$LOCAL_REPO" checkout --quiet "$branch"
if ! test -d "$LOCAL_REPO/.github/workflows"; then
continue
fi
out="$OUTPUT_DIR/$OWNER/$REPO/$branch/.github/workflows"
mkdir -p "$out"
find "$LOCAL_REPO/.github/workflows" -type f | grep -E '\.ya?ml$' | while read file; do
cp "$file" "$out"
done
done
find "$OUTPUT_DIR" -type f | grep -E '\.ya?ml$' | while read file; do
hash="$HASH_DIR/$(shasum "$file" | cut -d ' ' -f 1)"
if test -f "$hash"; then
rm "$file"
else
touch "$hash"
fi
done
readonly OUTPUT_FILE="$(mktemp)"
find "$OUTPUT_DIR" -type f > "$OUTPUT_FILE"
echo "output is written to the '$OUTPUT_FILE' file"