summaryrefslogtreecommitdiff
path: root/tcwg-report-orphan-rr-branches.sh
blob: 2130344d1aed5f9e7a17834fa8dcf5287c3efd2c (plain)
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
#!/bin/bash

set -euf -o pipefail

# Round-robin CI loops store their baseline state in:
# 1. toolchain/ci/base-artifacts.git repo stores artifacts of
#    baseline/reference build in branches named $ci_project/$ci_config.
# 2. toolchain/ci/$project.git repos store sources of $project that match
#    baseline/reference build in branches named $ci_project/$ci_config.
#
# Therefore, for a given $ci_project/$ci_config there should be a branch
# in toolchain/ci/base-artifacts.git repo and every relevant $project repo
# toolchain/ci/$project.git .
#
# If there are branches in toolchain/ci/$project.git repos that have
# no match in toolchain/ci/base-artifacts.git repo, then such branches
# are orphans and can be removed.
#
# This script lists such orphan branches.

scripts=$(dirname "$0")
# shellcheck source=jenkins-helpers.sh
. "$scripts/jenkins-helpers.sh"

convert_args_to_variables "$@"

repos=("${repos[@]-default}")
refs_prefix="${refs_prefix-refs/heads/linaro-local/ci/}"
refs_url="${refs_url-https://git.linaro.org/toolchain/ci/base-artifacts}"
verbose="${verbose-false}"

if $verbose; then
    set -x
fi

if [ x"${repos[*]}" = x"default" ]; then
    repos=(binutils-gdb gcc glibc linux llvm-project newlib qemu)
fi

branch_list=$(mktemp)
git ls-remote "$refs_url" "${refs_prefix}*" | awk '{ print $2 }' > $branch_list

for repo in "${repos[@]}"; do
    repo_url="$(dirname "$refs_url")/$repo"
    while IFS= read -r ref; do
	if grep -q "^$ref\$" $branch_list; then
	    continue
	fi

	echo "$repo $ref"
    done < <(git ls-remote "$repo_url" "${refs_prefix}*" | awk '{ print $2 }')
done

rm $branch_list