Skip to content

Commit 912afdc

Browse files
authored
Added reporting an attestation to the relase pointing back to the never-alone-trail #2298 (#312)
* Took out docker part of build to speed up * Started on adding a never-alone-trail attestation to the cli-release * Added setup of kosli cli before report of never-alone-trail * fixed extra argument to kosli attest * Fixed trailing white space * Added git repo of depth 1 * Updated to a new release number * Moved attestation of never-alone-trail into bash script * Added begin trail for the test parent flow * Added -p and -q options when calling create_never_alone_trail * Some cleanup
1 parent b5bdcca commit 912afdc

4 files changed

Lines changed: 68 additions & 23 deletions

File tree

.github/workflows/never_alone_trail.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ on:
1515
attestation_name:
1616
required: true
1717
type: string
18+
parent_flow_name:
19+
required: false
20+
type: string
21+
parent_trail_name:
22+
required: false
23+
type: string
1824
kosli_org:
1925
required: true
2026
type: string
@@ -64,6 +70,8 @@ jobs:
6470
-f ${{inputs.flow_name}} \
6571
-t ${{inputs.trail_name}} \
6672
-b ${BASE_COMMIT} \
67-
-p ${GITHUB_SHA} \
73+
-c ${GITHUB_SHA} \
6874
-s ${{inputs.source_flow_name}} \
69-
-n ${{inputs.attestation_name}}
75+
-n ${{inputs.attestation_name}} \
76+
-p ${{inputs.parent_flow_name}} \
77+
-q ${{inputs.parent_trail_name}}

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ jobs:
5555
TRAIL_NAME: ${{ needs.pre-build.outputs.trail_name }}
5656
SOURCE_FLOW_NAME: cli
5757
ATTESTATION_NAME: never-alone-data
58+
PARENT_FLOW_NAME: cli-release
59+
PARENT_TRAIL_NAME: ${{ needs.pre-build.outputs.trail_name }}
5860
KOSLI_ORG: kosli-public
5961
secrets:
6062
kosli_api_token: ${{ secrets.KOSLI_API_TOKEN }}

bin/never_alone/create_never_alone_trail.sh

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
set -Eeu
33

44
SCRIPT_NAME="create_never_alone_trail.sh"
5-
RELEASE_FLOW=""
5+
FLOW_NAME=""
66
TRAIL_NAME=""
77
BASE_COMMIT=""
8-
PROPOSED_COMMIT=""
8+
CURRENT_COMMIT=""
99
SOURCE_FLOW=""
1010
SOURCE_ATTESTATION_NAME=""
11+
PARENT_FLOW=""
12+
PARENT_TRAIL=""
1113
KOSLI_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
2224
Options 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
3034
EOF
3135
}
3236

@@ -46,60 +50,69 @@ function repo_root
4650

4751
function 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

100113
function 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"
@@ -119,7 +132,7 @@ EOF
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

176189
function 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+
202230
function 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

216248
main "$@"

bin/never_alone/get_commit_and_pr_info.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ function get_never_alone_data
105105
local -r commit=$1; shift
106106
local -r result_file=$1; shift
107107

108+
# We have seen that the 'gh search commits' sometimes return an empty list
109+
# Have added getting data with graphql also, and some echo messages further down
110+
# Only for debugging at the moment, but we could use graphql to get both commit and pr data
108111
commit_data_graphql=$(get_commit_data_using_graphql $commit)
109112
pr_data=$(gh pr list --search "${commit}" --state merged --json author,reviews,mergeCommit,mergedAt,reviewDecision,url)
110113
commit_data=$(gh search commits --hash "${commit}" --json commit)

0 commit comments

Comments
 (0)