forked from kubernetes/release
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prin
executable file
·156 lines (139 loc) · 4.88 KB
/
prin
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env bash
#
# Copyright 2016 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 PROGram name
PROG=${0##*/}
########################################################################
#+
#+ NAME
#+ $PROG - What tag(s) is my PR IN?
#+
#+ SYNOPSIS
#+ $PROG <commit|pr>
#+ $PROG [--security_layer=/path/to/pointer/to/script]
#+ $PROG [--helpshort|--usage|-?]
#+ $PROG [--help|-man]
#+
#+ DESCRIPTION
#+ Report the tags in which a PR or commit appears and the latency in
#+ days (commit to release).
#+
#+ OPTIONS
#+ [--security_layer=] - A file containing a path to a script to
#+ source/include:
#+ FLAGS_security_layer=/path/to/script
#+ Default: $HOME/.kubernetes-releaserc
#+ [--help | -man] - display man page for this script
#+ [--usage | -?] - display in-line usage
#+
#+ EXAMPLES
#+
#+ FILES
#+
#+ SEE ALSO
#+ common.sh - base function definitions
#+
#+ BUGS/TODO/IDEAS
#+ Limit results to first tag/release per branch
#+
########################################################################
# If NO ARGUMENTS should return *usage*, uncomment the following line:
usage=${1:-yes}
source $(dirname $(readlink -ne $BASH_SOURCE))/lib/common.sh
source $TOOL_LIB_PATH/gitlib.sh
###############################################################################
# FUNCTIONS
###############################################################################
#############################################################################
# Display/Report tags and latency (to release) for the incoming commits
# K8S latency is the difference between the commit timestamp and tag timestamp
# @param pr - a PR or "" (placeholder)
# @param commits - a list of commits
# HOSTED_EPOCH is set by an external script
show_tags () {
local pr=$1
local initial_commit=$2
shift 2
local cp_commits=($*)
local commit
local commit_seconds
local tag_seconds
local tag
local days
local hosted_days
logecho
logecho "COMMITS: $initial_commit (initial) ${cp_commits[*]} (cherrypicks)"
[[ -n $pr ]] && echo "(https://github.com/kubernetes/kubernetes/pull/$pr)"
logecho
logecho " LATENCY TO APPEAR (DAYS)"
logecho -n "TAG K8S"
if ((SECURITY_LAYER)); then
logecho " HOSTED"
else
logecho
fi
logecho -n "--- ---"
if ((SECURITY_LAYER)); then
logecho " ------"
else
logecho
fi
# We only care about the initial commit for latency calculation
commit_seconds=$(git show -s --format="%ct" $initial_commit)
for commit in $initial_commit ${cp_commits[*]}; do
for tag in $(git tag --contains $commit); do
tag_seconds=$(git show -s --pretty=format:%ct $tag |tail -1)
# Convert to days with some precision
days=$(echo "scale=2; ($tag_seconds-$commit_seconds)/86400"|bc)
if ((SECURITY_LAYER)); then
hosted_days="NA"
[[ -n "${HOSTED_EPOCH[$tag]}" ]] && \
hosted_days=$(echo "scale=2; (${HOSTED_EPOCH[$tag]}-$commit_seconds)/86400"|bc)
fi
printf "%-15s %-7s %s\n" "$tag" "$days" "$hosted_days"
done
done
echo
}
###############################################################################
# Stubbed out
security_layer::hosted_map () {
logecho "Skipping $FUNCNAME extensions..."
return 0
}
###############################################################################
# MAIN
###############################################################################
# Are we in a repo?
gitlib::current_branch >/dev/null || common::exit 1
# Additional functionality
common::security_layer
if [[ ${POSITIONAL_ARGV[0]} =~ [0-9]{5,} ]]; then
PR=${POSITIONAL_ARGV[0]}
#echo "Converting incoming PR to a commit..."
# Need to include --all for the primary commit too for
# non-cherrypick commit searches on branches
INITIAL_COMMIT=$(git log --grep "Merge pull request #$PR" \
--all --pretty=format:"%h")
CP_COMMITS=($(git log --grep "cherry-pick-of-.*#$PR-" \
--all --pretty=format:"%h"))
else
# TODO: Need to validate this is a git hash
INITIAL_COMMIT=("${POSITIONAL_ARGV[0]}")
fi
[[ -z "$INITIAL_COMMIT" ]] && common::exit 1 "No commit/pr found in this repo."
security_layer::hosted_map
show_tags "$PR" $INITIAL_COMMIT ${CP_COMMITS[*]}