forked from kubernetes/minikube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_contributions.sh
executable file
·88 lines (76 loc) · 3.52 KB
/
update_contributions.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
# Copyright 2018 The Kubernetes Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -eu -o pipefail
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
install_pullsheet() {
pullsheet_workdir="$(mktemp -d)"
trap 'rm -rf -- ${pullsheet_workdir}' RETURN
# See https://stackoverflow.com/questions/56842385/using-go-get-to-download-binaries-without-adding-them-to-go-mod for this workaround
cd "${pullsheet_workdir}"
go mod init ps
GOBIN="$DIR" go get github.com/google/pullsheet
cd -
}
if ! [[ -x "${DIR}/pullsheet" ]]; then
echo >&2 'Installing pullsheet'
install_pullsheet
fi
git pull https://github.com/kubernetes/minikube.git master --tags
tags_to_generate=${1:-1}
# 1) Fetch latest tags (https://github.com/kubernetes/minikube/issues/12561).
# 2) Get tags.
# 3) Filter out beta tags.
# 4) Parse tag name into its version numbers.
# 5) Sort by ascending version numbers.
# 6) Reform tag name from version numbers.
# 7) Pair up current and previous tags. Format: (previous tag, current tag)
# 8) Format command to get tag dates.
# 9) Execute command to get dates of previous and current tag. Format: (current tag, prev date, current date)
# 10) Add negative line numbers to each tag. Format: (negative index, current tag, prev date, current date)
# - Negative line numbers are used since entries are sorted in descending order.
# 11) Take most recent $tags_to_generate tags.
tags_with_range=$(
git fetch --tags -f \
git --no-pager tag \
| grep -v -e "beta" \
| sed -r "s/v([0-9]*)\.([0-9]*)\.([0-9]*)/\1 \2 \3/" \
| sort -k1n -k2n -k3n \
| sed -r "s/([0-9]*) ([0-9]*) ([0-9]*)/v\1.\2.\3/" \
| sed -n -r "x; G; s/\n/ /; p"\
| sed -n -r "s/([v.0-9]+) ([v.0-9]+)/-c '{ echo -n \2; git log -1 --pretty=format:\" %as \" \1; git log -1 --pretty=format:\"%as\" \2; echo;}'/p" \
| xargs -L 1 bash \
| sed "=" | sed -r "N;s/\n/ /;s/^/-/" \
| tail -n "$tags_to_generate")
destination="$DIR/../site/content/en/docs/contrib/leaderboard"
mkdir -p "$destination"
TMP_TOKEN=$(mktemp)
gh auth status -t 2>&1 | sed -n -r 's/^.*Token: ([a-zA-Z0-9_]*)/\1/p' > "$TMP_TOKEN"
if [ ! -s "$TMP_TOKEN" ]; then
echo "Failed to acquire token from 'gh auth'. Ensure 'gh' is authenticated." 1>&2
exit 1
fi
# Ensure the token is deleted when the script exits, so the token is not leaked.
function cleanup_token() {
rm -f "$TMP_TOKEN"
}
trap cleanup_token EXIT
while read -r tag_index tag_name tag_start tag_end; do
echo "Generating leaderboard for" "$tag_name" "(from $tag_start to $tag_end)"
# Print header for page.
printf -- "---\ntitle: \"$tag_name - $tag_end\"\nlinkTitle: \"$tag_name - $tag_end\"\nweight: $tag_index\n---\n" > "$destination/$tag_name.html"
# Add pullsheet content (deleting the lines consisting of the command used to generate it).
$DIR/pullsheet leaderboard --token-path "$TMP_TOKEN" --repos kubernetes/minikube --since "$tag_start" --until "$tag_end" --logtostderr=false --stderrthreshold=2 \
| sed -r -e "/Command\-line/,/pullsheet/d" >> "$destination/$tag_name.html"
done <<< "$tags_with_range"