github.com/redhat-appstudio/e2e-tests@v0.0.0-20230619105049-9a422b2094d7/pipelines/interrupt_catcher/ic-task.yaml (about) 1 apiVersion: tekton.dev/v1beta1 2 kind: Task 3 metadata: 4 name: rotate-ic 5 namespace: appstudio-qe 6 spec: 7 steps: 8 - env: 9 - name: TOKEN 10 valueFrom: 11 secretKeyRef: 12 key: token 13 name: slack-token 14 image: quay.io/devfile/base-developer-image:latest 15 name: rotate-ic 16 script: | 17 #!/bin/bash 18 19 # Updates IC group in slack and sends message about it. 20 # First arument is index of primary IC in allPeople array 21 # Second argument is index of secondary IC in allPeople array 22 function updateICAndSendMessage { 23 echo "Next Primary is:" 24 echo "${allPeople[$1]}" 25 echo "Next backup is:" 26 echo "${allPeople[$2]}" 27 primaryUsername=$(echo ${allPeople[$1]} |jq -r .username) 28 primaryId=$(echo ${allPeople[$1]} |jq -r .id) 29 backupUsername=$(echo ${allPeople[$2]} |jq -r .username) 30 backupId=$(echo ${allPeople[$2]} |jq -r .id) 31 curl -X POST -H "Authorization: Bearer $TOKEN" \ 32 --data-urlencode "usergroup=${USERGROUP_ID}" \ 33 --data-urlencode "users=${primaryId},${backupId}" \ 34 "https://slack.com/api/usergroups.users.update" 35 36 text=":interrupt-catcher: Primary IC for next week is ${primaryUsername}. Backup is ${backupUsername}" 37 curl -X POST -H "Authorization: Bearer $TOKEN" \ 38 --data-urlencode "channel=C02FANRBZQD" \ 39 --data-urlencode "text=$text" \ 40 "https://slack.com/api/chat.postMessage" 41 42 } 43 44 USERGROUP_ID=S03PD4MV58W 45 46 readarray -t allPeople < <(jq -c ".[]" /var/people-list/people-list) 47 readarray -t currentICs < <(curl -X POST -H "Authorization: Bearer $TOKEN" https://slack.com/api/usergroups.users.list\?usergroup\=S03PD4MV58W | jq -r ".users[]") 48 49 if [ ${#currentICs[@]} -ne 2 ]; then 50 text=":warning: :interrupt-catcher: IC rotation pipeline failed (Expect exaclty 2 people in IC group). Please check latest run." 51 curl -X POST -H "Authorization: Bearer $TOKEN" \ 52 --data-urlencode "channel=C02FANRBZQD" \ 53 --data-urlencode "text=$text" \ 54 "https://slack.com/api/chat.postMessage" 55 exit 1 56 fi 57 58 for i in "${!allPeople[@]}"; do 59 for currentIC in "${currentICs[@]}"; do 60 61 if [[ $currentIC == $(echo ${allPeople[$i]} | jq -r .id) ]]; then 62 63 # Exception for when the primary IC is first in list and the backup was last on the list (list wraps around) 64 if [[ $i -eq 0 ]]; then 65 if [[ " ${currentICs[*]} " =~ " $(echo ${allPeople[$((${#allPeople[@]}-1))]} | jq -r .id) " ]]; then 66 updateICAndSendMessage $(($i+1)) $i 67 exit 0 68 fi 69 fi 70 71 # Normal flow - check whether next one was in IC group as well and shift by one. 72 # Fail othewise 73 if [[ " ${currentICs[*]} " =~ " $(echo ${allPeople[$(($i+1))]} | jq -r .id) " ]]; then 74 updateICAndSendMessage $(($i+2)) $(($i+1)) 75 exit 0 76 else 77 text=":warning: :interrupt-catcher: IC rotation pipeline failed (People in IC group are not next to each other according to roration list). Please check latest run." 78 curl -X POST -H "Authorization: Bearer $TOKEN" \ 79 --data-urlencode "channel=C02FANRBZQD" \ 80 --data-urlencode "text=$text" \ 81 "https://slack.com/api/chat.postMessage" 82 exit 1 83 fi 84 fi 85 done 86 done 87 88 volumeMounts: 89 - name: people-list 90 mountPath: /var/people-list 91 volumes: 92 - name: people-list 93 configMap: 94 name: ic-people-list