22set -Eeu
33
44SCRIPT_NAME=" create_never_alone_trail.sh"
5- RELEASE_FLOW =" "
5+ FLOW_NAME =" "
66TRAIL_NAME=" "
77BASE_COMMIT=" "
8- PROPOSED_COMMIT =" "
8+ CURRENT_COMMIT =" "
99SOURCE_FLOW=" "
1010SOURCE_ATTESTATION_NAME=" "
11+ PARENT_FLOW=" "
12+ PARENT_TRAIL=" "
1113KOSLI_HOST=${KOSLI_HOST:- https:// app.kosli.com}
1214
1315
@@ -21,12 +23,14 @@ Collects all commits between base-commit and proposed-commit and use it as a tem
2123
2224Options are:
2325 -h Print this help menu
24- -f <release- flow> Name of kosli flow to report combined never-alone info to. Required
26+ -f <flow-name> Name of kosli flow to report combined never-alone info to. Required
2527 -t <trail-name> Name of the trail that the reviews shall be reported to. Required
26- -b <base-commit> Commit of previous release
27- -p <proposed- commit> Commit sha for release we are building now . Required
28+ -b <base-commit-sha > Old commit sha, used as base for creating list of commits. Required
29+ -c < commit-sha > Current commit sha, used as the end point for creating list of commits . Required
2830 -s <source-flow> Name of kosli flow where the never-alone-data data are stored. Required
2931 -n <attestation-name> Attestation name used for never-alone-data. Required
32+ -p <parent-flow> Send an attestation about the never-alone-trail to the parent-flow. Optional
33+ -q <parent-trail> Trail name of parent flow where the report shall be sent. Optional
3034EOF
3135}
3236
@@ -46,60 +50,69 @@ function repo_root
4650
4751function check_arguments
4852{
49- while getopts " hf:t:b:p :s:n:" opt; do
53+ while getopts " hf:t:b:c :s:n:p:q :" opt; do
5054 case $opt in
5155 h)
5256 print_help
5357 exit 1
5458 ;;
5559 f)
56- RELEASE_FLOW =${OPTARG}
60+ FLOW_NAME =${OPTARG}
5761 ;;
5862 t)
5963 TRAIL_NAME=${OPTARG}
6064 ;;
6165 b)
6266 BASE_COMMIT=${OPTARG}
6367 ;;
64- p )
65- PROPOSED_COMMIT =${OPTARG}
68+ c )
69+ CURRENT_COMMIT =${OPTARG}
6670 ;;
6771 s)
6872 SOURCE_FLOW=${OPTARG}
6973 ;;
7074 n)
7175 SOURCE_ATTESTATION_NAME=${OPTARG}
7276 ;;
77+ p)
78+ PARENT_FLOW=${OPTARG}
79+ ;;
80+ q)
81+ PARENT_TRAIL=${OPTARG}
82+ ;;
7383 \? )
7484 echo " Invalid option: -$OPTARG " >&2
7585 exit 1
7686 ;;
7787 esac
7888 done
7989
80- if [ -z " ${RELEASE_FLOW } " ]; then
81- die " option -f <release- flow> is required"
90+ if [ -z " ${FLOW_NAME } " ]; then
91+ die " option -f <flow-name > is required"
8292 fi
8393 if [ -z " ${TRAIL_NAME} " ]; then
8494 die " option -t <trail-name> is required"
8595 fi
8696 if [ -z " ${BASE_COMMIT} " ]; then
87- die " option -b <base-commit> is required"
97+ die " option -b <base-commit-sha > is required"
8898 fi
89- if [ -z " ${PROPOSED_COMMIT } " ]; then
90- die " option -p <proposed- commit> is required"
99+ if [ -z " ${CURRENT_COMMIT } " ]; then
100+ die " option -c < commit-sha > is required"
91101 fi
92102 if [ -z " ${SOURCE_FLOW} " ]; then
93103 die " option -s <source-flow> is required"
94104 fi
95105 if [ -z " ${SOURCE_ATTESTATION_NAME} " ]; then
96106 die " option -n <attestation-name> is required"
97107 fi
108+ if { [[ -n " $PARENT_FLOW " && -z " $PARENT_TRAIL " ]] || [[ -z " $PARENT_FLOW " && -n " $PARENT_TRAIL " ]]; }; then
109+ die " You must provide either both options -p <parent-flow> and -q <parent-trail>, or neither"
110+ fi
98111}
99112
100113function begin_trail_with_template
101114{
102- local release_flow =$1 ; shift
115+ local flow_name =$1 ; shift
103116 local trail_name=$1 ; shift
104117 local commits=(" $@ " )
105118 local trail_template_file_name=" review_trail.yaml"
119132 } > ${trail_template_file_name}
120133
121134 kosli begin trail ${trail_name} \
122- --flow=${release_flow } \
135+ --flow=${flow_name } \
123136 --description=" $( git log -1 --pretty=' %aN - %s' ) " \
124137 --template-file=${trail_template_file_name}
125138}
@@ -175,7 +188,7 @@ function get_never_alone_compliance
175188
176189function attest_commit_trail_never_alone
177190{
178- local -r release_flow =$1 ; shift
191+ local -r flow_name =$1 ; shift
179192 local -r trail_name=$1 ; shift
180193 local -r commit=$1 ; shift
181194 local -r source_flow=$1 ; shift
@@ -190,7 +203,7 @@ function attest_commit_trail_never_alone
190203 latest_never_alone_data=$( echo " ${never_alone_data} " | jq ' .[-1]' )
191204 compliant=$( get_never_alone_compliance " ${latest_never_alone_data} " )
192205 kosli attest generic \
193- --flow ${release_flow } \
206+ --flow ${flow_name } \
194207 --trail ${trail_name} \
195208 --commit ${commit} \
196209 --name=" ${commit} " \
@@ -199,18 +212,37 @@ function attest_commit_trail_never_alone
199212 fi
200213}
201214
215+ function attest_never_alone_trail_to_parent
216+ {
217+ local -r flow_name=$1 ; shift
218+ local -r trail_name=$1 ; shift
219+ local -r parent_flow=$1 ; shift
220+ local -r parent_trail=$1 ; shift
221+
222+ never_alone_trail_link=" ${KOSLI_HOST} /${KOSLI_ORG} /flows/${flow_name} /trails/${trail_name} "
223+ kosli attest generic \
224+ --flow ${parent_flow} \
225+ --trail ${parent_trail} \
226+ --name never-alone-trail \
227+ --annotate never_alone_trail=" ${never_alone_trail_link} "
228+ }
229+
202230function main
203231{
204232 check_arguments " $@ "
205233 # Use gh instead of git so we can keep the commit depth of 1. The order are from oldest
206234 # commit to newest
207- commits=($( gh api repos/:owner/:repo/compare/${BASE_COMMIT} ...${PROPOSED_COMMIT } -q ' .commits[].sha' ) )
235+ commits=($( gh api repos/:owner/:repo/compare/${BASE_COMMIT} ...${CURRENT_COMMIT } -q ' .commits[].sha' ) )
208236
209- begin_trail_with_template ${RELEASE_FLOW } ${TRAIL_NAME} " ${commits[@]} "
237+ begin_trail_with_template ${FLOW_NAME } ${TRAIL_NAME} " ${commits[@]} "
210238
211239 for commit in " ${commits[@]} " ; do
212- attest_commit_trail_never_alone ${RELEASE_FLOW } ${TRAIL_NAME} ${commit} ${SOURCE_FLOW} ${SOURCE_ATTESTATION_NAME}
240+ attest_commit_trail_never_alone ${FLOW_NAME } ${TRAIL_NAME} ${commit} ${SOURCE_FLOW} ${SOURCE_ATTESTATION_NAME}
213241 done
242+
243+ if [ -n " ${PARENT_FLOW} " ]; then
244+ attest_never_alone_trail_to_parent ${FLOW_NAME} ${TRAIL_NAME} ${PARENT_FLOW} ${PARENT_TRAIL}
245+ fi
214246}
215247
216248main " $@ "
0 commit comments