summaryrefslogtreecommitdiff
path: root/tcwg-report-stale-rr-jobs.sh
blob: 6e0a7c0880b473141288929d6a3c01e1b6db523d (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
#!/bin/bash

set -euf -o pipefail

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

convert_args_to_variables "$@"

days="${days-10}"
human="${human-true}"
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

# Initialize base-artifacts repo (by cloning its "empty" branch).
refs_repo=$(basename "$refs_url" .git)
clone_or_update_repo_no_checkout "$refs_repo" "$refs_url" none empty origin \
				 >/dev/null 2>&1
git -C "$refs_repo" reset --hard >/dev/null 2>&1

# Walk through all commits of all tcwg_bmk* branches and mark results
# referenced in those results with "used_by" file.
while IFS= read -r ref; do
    git -C "$refs_repo" fetch -q origin "$ref"
    commit_stamp=$(git -C "$refs_repo" show --no-patch --pretty=%ct FETCH_HEAD)
    days_ago=$((($(date +%s) - $commit_stamp) / (24 * 3600)))
    if [ $days_ago -gt $days ]; then
	if $human; then
	    echo "${ref#$refs_prefix} : last updated $days_ago days ago"
	else
	    echo "$ref"
	fi
    fi
done < <(git ls-remote "$refs_url" "${refs_prefix}*" | awk '{ print $2 }')