blob: 7637a6b5796b3b81dbc62d6f860f6369c006161c [file] [log] [blame]
Arthur She87e7f392024-01-21 20:03:20 -08001- job:
2 name: tf-a-lts-verified-propagater
Arthur Sheeeef44c2025-01-09 20:48:32 -08003 node: docker-amd64-tf-a-jammy
Arthur She87e7f392024-01-21 20:03:20 -08004 project-type: freestyle
5 concurrent: false
Chris Kay675db4f2025-06-24 14:14:34 +01006 description: Triggers whenever a patch in the lts branch get a Verified score. It will vote the same score to the dependent patch
Arthur She87e7f392024-01-21 20:03:20 -08007 disabled: false
8 builders:
Chris Kay675db4f2025-06-24 14:14:34 +01009 - shell: ""
10 - shell: |-
11 #!/bin/bash
12 # This job is triggered by the label Verified +1 or -1 of the patch
13 # it will vote the same score (Verified +1 / Verified -1) to the dependent patch
14 # , if there is any.
15 # For example, P5 -> P4 -> P3 -> P2 -> P1. P5 dependents on P4, and so on
16 # When P5 gets Verified +1, this job will be triggered and set Verified +1 to P4.
17 # P4 gets Verified +1 triggers an other job to set Verified +1 to P3, and so on.
18 # That is how we propagate the Verified score to the entire patch stack
19 set -ex
Arthur She87e7f392024-01-21 20:03:20 -080020
Chris Kay675db4f2025-06-24 14:14:34 +010021 echo "########################################################################"
22 echo " Gerrit Environment"
23 env |grep '^GERRIT'
24 echo "########################################################################"
Arthur She87e7f392024-01-21 20:03:20 -080025
Chris Kay675db4f2025-06-24 14:14:34 +010026 SSH_PARAMS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o PubkeyAcceptedKeyTypes=+ssh-rsa -p 29418 -i ${CI_BOT_KEY}"
27 GERRIT_URL="review.trustedfirmware.org"
28 GERRIT_QUERY_PARAMS="--dependencies --submit-records --format=JSON change:"
29 QUERY_CMD="${SSH_PARAMS} ${CI_BOT_USERNAME}@${GERRIT_URL} gerrit query ${GERRIT_QUERY_PARAMS}"
30 QUERY_CHANGE_DEPENDS_CMD="${QUERY_CMD}${GERRIT_CHANGE_NUMBER}"
31 REVIEW_MESSAGE="Propagated verified from ${GERRIT_CHANGE_URL}. By ${BUILD_URL}"
32 SET_VERIFIED_CMD="${SSH_PARAMS} ${CI_BOT_USERNAME}@${GERRIT_URL} gerrit review --verified"
Arthur She87e7f392024-01-21 20:03:20 -080033
Chris Kay675db4f2025-06-24 14:14:34 +010034 change_url_base=${GERRIT_CHANGE_URL%/*}
35 # Check this example https://ci.trustedfirmware.org/view/TF-A/job/tf-a-lts-verified-propagater/14/console
36 # for what we get from gerrit query command
37 patch_query=$(ssh ${QUERY_CHANGE_DEPENDS_CMD} | jq .)
38 dependsOn=$(echo ${patch_query} | jq -r 'select(.dependsOn)')
39 # Normally, there would be just one dependent patch
40 # (and that patch would in turn has another dependent patch, that's how a dependency chain is structured)
41 # But Gerrit data model has a list of dependent patches, so we process all just in case
42 dependsOn_rev=($(echo ${dependsOn} | jq -r '.dependsOn[].revision'))
43 dependsOn_no=($(echo ${dependsOn} | jq -r '.dependsOn[].number'))
44 verified_status=$(echo ${patch_query} | jq -r 'select(.submitRecords) | .submitRecords[0].labels[] | select(.label == "Verified") | .status')
45 # Verified label status and value mapping
46 # REJECT: -1
47 # OK: 1
48 verified_value=0
49 if [ "${verified_status}" == "REJECT" ]; then
50 verified_value=-1
51 elif [ "${verified_status}" == "OK" ]; then
52 verified_value=1
53 fi
54 # Vote the same Verified score to the dependent patch by loop
55 for ((i=0; i<${#dependsOn_rev[@]}; i++))
56 do
57 # Need to check the .status before set verified score
58 if [ $(ssh ${QUERY_CMD}${dependsOn_no[$i]} | jq -r 'select(.status)|.status') == "MERGED" ]; then
59 echo "The dependent patch ${change_url_base}${dependsOn_no[$i]} has been merged. Don't set Verified score to it!"
60 continue
61 else
62 echo "Set Verified ${verified_value} to: ${change_url_base}/${dependsOn_no[$i]}"
63 ssh ${SET_VERIFIED_CMD} ${verified_value} -m \'\"${REVIEW_MESSAGE}\"\' ${dependsOn_rev[$i]}
64 fi
65 done
Arthur She87e7f392024-01-21 20:03:20 -080066 properties:
Chris Kay675db4f2025-06-24 14:14:34 +010067 - build-discarder:
68 days-to-keep: 60
69 num-to-keep: 10
Arthur She87e7f392024-01-21 20:03:20 -080070 triggers:
Chris Kay675db4f2025-06-24 14:14:34 +010071 - gerrit:
72 silent: true
73 server-name: review.trustedfirmware.org
74 projects:
75 - branches:
76 - branch-compare-type: REG_EXP
77 branch-pattern: lts-v.*
78 project-compare-type: PLAIN
79 project-pattern: TF-A/trusted-firmware-a
80 trigger-on:
81 - comment-added-event:
82 approval-category: Verified
83 approval-value: 1
84 - comment-added-event:
85 approval-category: Verified
86 approval-value: -1
Arthur She87e7f392024-01-21 20:03:20 -080087 wrappers:
Chris Kay675db4f2025-06-24 14:14:34 +010088 - timestamps
89 - credentials-binding:
90 - ssh-user-private-key:
91 credential-id: TFA_CI_BOT_USER_SSH_KEY
92 key-file-variable: CI_BOT_KEY
93 username-variable: CI_BOT_USERNAME
94 passphrase-variable: ""
Arthur She87e7f392024-01-21 20:03:20 -080095 publishers:
Chris Kay675db4f2025-06-24 14:14:34 +010096 - workspace-cleanup