blob: cdfadd8a396ea4aae2959cc05057e33a9b40c75f [file] [log] [blame]
Andrew Geissler3c88e2d2021-01-28 15:18:11 -06001#!/bin/bash -e
2#
3# Purpose:
4# This script is responsible for determining the owner of a gerrit
5# commit, verifying they are within an approved gerrit group, and
6# then updating gerrit with that verification info.
7#
8# Note: It is assumed this script is run as a part of a jenkins job triggered
9# by the gerrit plugin. Therefore it assumes certain env variables
Manojkiran Edaa6ebc6e2024-06-17 11:51:45 +053010# provided by that plugin are available (i.e. GERRIT_PROJECT, ...)
Andrew Geissler3c88e2d2021-01-28 15:18:11 -060011#
12# Required Inputs:
13# SSH_KEY: Path to private ssh key used to post messages to gerrit
14
Andrew Geissler37052412022-05-20 15:28:26 -040015GERRIT_COMMAND="curl -s --anyauth -n https://gerrit.openbmc.org"
Patrick Williamsa4d19dc2021-03-15 14:51:06 -050016GERRIT_SSH_CMD=( \
Patrick Williams476a7e92022-12-06 09:52:53 -060017 ssh -o 'StrictHostKeyChecking no' -i "$SSH_KEY" \
18 -p 29418 jenkins-openbmc-ci@gerrit.openbmc.org gerrit \
19 )
Andrew Geissler3c88e2d2021-01-28 15:18:11 -060020
21echo "Checking ${GERRIT_PROJECT}:${GERRIT_BRANCH}:${GERRIT_CHANGE_ID}:${GERRIT_PATCHSET_REVISION}"
22
Patrick Williamsac912df2024-04-01 10:28:05 -050023COMMITTER_USERNAME=$("${GERRIT_SSH_CMD[@]}" query "${GERRIT_CHANGE_NUMBER}" --current-patch-set --format json | jq -r '.currentPatchSet.uploader.username | select (. != null )')
Andrew Geissler3c88e2d2021-01-28 15:18:11 -060024echo "USERNAME: $COMMITTER_USERNAME"
Ed Tanous5d3031d2022-02-16 15:57:15 -080025if [ "${COMMITTER_USERNAME}" = "" ]; then
Andrew Geissler3c88e2d2021-01-28 15:18:11 -060026 echo "Unable to determine github user for ${COMMITTER_EMAIL}."
Patrick Williamsa4d19dc2021-03-15 14:51:06 -050027 "${GERRIT_SSH_CMD[@]}" review \
28 "${GERRIT_CHANGE_NUMBER},${GERRIT_PATCHSET_NUMBER}" \
Patrick Williamsf8ee6f02022-01-04 12:03:19 -060029 --ok-to-test=0 "--message='Unable to determine github user'"
Patrick Williamsa4d19dc2021-03-15 14:51:06 -050030 exit 1
Andrew Geissler3c88e2d2021-01-28 15:18:11 -060031fi
32
33# Reset the vote to 0 so jenkins will detect a new +1 on retriggers
Patrick Williamsa4d19dc2021-03-15 14:51:06 -050034"${GERRIT_SSH_CMD[@]}" review \
35 "${GERRIT_CHANGE_NUMBER},${GERRIT_PATCHSET_NUMBER}" \
Patrick Williams8ac8e092022-01-04 12:05:50 -060036 --ok-to-test=0 -t autogenerated:jenkins --notify=NONE
Andrew Geissler3c88e2d2021-01-28 15:18:11 -060037
Patrick Williams47b59dc2022-07-18 16:58:42 -050038# Add reviewers based on OWNERS files.
39"${WORKSPACE}/openbmc-build-scripts/tools/owners" -p "${WORKSPACE}" reviewers |
40{
41 while read -r reviewer ;
42 do
43 # shellcheck disable=2086 # GERRIT_COMMAND is purposefully wordsplit.
44 ${GERRIT_COMMAND}/a/changes/${GERRIT_PROJECT/\//%2F}~${GERRIT_BRANCH}~${GERRIT_CHANGE_ID}/reviewers \
45 -X POST \
46 -H "Content-Type: application/json" \
47 -d "$reviewer" || true
48 done
49} || true
50
Andrew Geissler3c88e2d2021-01-28 15:18:11 -060051# Write full list of users to a file
Patrick Williamsa4d19dc2021-03-15 14:51:06 -050052GERRIT_CI_GROUPS=( \
Andrew Geissler7e153072024-06-26 14:43:06 -040053 aimvalley/ci-authorized \
Patrick Williamsb836d242023-10-13 21:10:41 -050054 akamai/ci-authorized \
Patrick Williams476a7e92022-12-06 09:52:53 -060055 alibaba/ci-authorized \
56 amd/ci-authorized \
57 ami/ci-authorized \
58 ampere/ci-authorized \
59 arm/ci-authorized \
60 aspeed/ci-authorized \
Andrew Geissler971d68b2023-11-10 08:54:49 -060061 asus/ci-authorized \
Patrick Williams476a7e92022-12-06 09:52:53 -060062 bytedance/ci-authorized \
Andrew Geisslerad42f702023-11-17 09:45:25 -060063 celestica/ci-authorized \
Patrick Williams476a7e92022-12-06 09:52:53 -060064 code-construct/ci-authorized \
Andrew Geisslerd0667782025-07-08 08:24:15 -050065 coreweave/ci-authorized \
Andrew Geissler8c012372024-10-17 08:57:21 -040066 cornelis/ci-authorized \
Andrew Geisslerf38b5c92024-07-11 11:26:00 -040067 dell/ci-authorized \
Patrick Williams476a7e92022-12-06 09:52:53 -060068 depo/ci-authorized \
69 erg/ci-authorized \
Patrick Williams93d22a42023-04-21 14:55:26 -050070 equinix/ci-authorized \
Patrick Williams476a7e92022-12-06 09:52:53 -060071 facebook/ci-authorized \
72 fii/ci-authorized \
Paul Fertser83d69a22024-01-24 10:46:32 +000073 gagar-in/ci-authorized \
Patrick Williams476a7e92022-12-06 09:52:53 -060074 google/ci-authorized \
75 hcl/ci-authorized \
Andrew Geisslerf6b3db12025-01-29 15:24:07 -060076 hetzner/ci-authorized \
Andrew Geisslerf3e82892024-11-19 13:58:20 -060077 hp/ci-authorized \
Patrick Williams476a7e92022-12-06 09:52:53 -060078 hpe/ci-authorized \
79 ibm/ci-authorized \
Andrew Geissler6481ea42023-11-10 14:39:25 -060080 iei/ci-authorized \
Patrick Williams476a7e92022-12-06 09:52:53 -060081 individual/ci-authorized \
Andrew Geisslercf184a42025-04-01 14:36:22 -050082 ingrasys/ci-authorized \
Patrick Williams476a7e92022-12-06 09:52:53 -060083 inspur/ci-authorized \
84 intel/ci-authorized \
85 inventec/ci-authorized \
86 lenovo/ci-authorized \
87 microsoft/ci-authorized \
Andrew Geissler478503b2024-09-26 15:15:33 -040088 mitac/ci-authorized \
Andrew Geissler5f4d98c2025-02-11 10:17:36 -060089 multicoreware/ci-authorized \
Patrick Williams1a029ec2025-05-16 12:43:42 -040090 napatech/ci-authorized \
Patrick Williams476a7e92022-12-06 09:52:53 -060091 nineelements/ci-authorized \
92 nuvoton/ci-authorized \
93 nvidia/ci-authorized \
94 openbmc/ci-authorized \
95 pcpartner/ci-authorized \
96 phytium/ci-authorized \
Andrew Geissler7d886222024-01-12 00:52:37 -060097 plexus/ci-authorized \
Patrick Williams476a7e92022-12-06 09:52:53 -060098 quanta/ci-authorized \
99 quic/ci-authorized \
Patrick Williamsb79444a2025-04-09 11:58:11 -0400100 raptorcs/ci-authorized \
Andrew Geissler23b47b22025-02-12 10:47:58 -0600101 sipearl/ci-authorized \
Patrick Williams476a7e92022-12-06 09:52:53 -0600102 supermicro/ci-authorized \
Andrew Geisslerb8730362023-12-01 13:46:26 -0600103 tencent/ci-authorized \
Andrew Geissler25602982025-05-20 07:20:32 -0500104 tenstorrent/ci-authorized \
Andrew Geissler2b2f4f12024-03-11 18:21:56 +0530105 triple-crown/ci-authorized \
Jordan Changfd0e80d2023-03-06 09:49:30 +0800106 ufispace/ci-authorized \
Patrick Williamseb4961b2023-05-04 11:28:26 -0500107 vaisala/ci-authorized \
Patrick Williams476a7e92022-12-06 09:52:53 -0600108 wistron/ci-authorized \
109 wiwynn/ci-authorized \
Patrick Williams476a7e92022-12-06 09:52:53 -0600110 )
Andrew Geissler3c88e2d2021-01-28 15:18:11 -0600111
Patrick Williamsa4d19dc2021-03-15 14:51:06 -0500112rm -f "$WORKSPACE/users.txt"
113for g in "${GERRIT_CI_GROUPS[@]}"; do
114 "${GERRIT_SSH_CMD[@]}" ls-members "$g" --recursive \
115 >> "$WORKSPACE/users.txt"
116done
Andrew Geissler3c88e2d2021-01-28 15:18:11 -0600117
118# grep for the specific username word in the file
Patrick Williamsa4d19dc2021-03-15 14:51:06 -0500119if grep -q -w "${COMMITTER_USERNAME}" "$WORKSPACE/users.txt"; then
120 "${GERRIT_SSH_CMD[@]}" review \
121 "${GERRIT_CHANGE_NUMBER},${GERRIT_PATCHSET_NUMBER}" \
Patrick Williams8ac8e092022-01-04 12:05:50 -0600122 --ok-to-test=1 -t autogenerated:jenkins --notify=NONE \
Patrick Williamsa4d19dc2021-03-15 14:51:06 -0500123 "--message='User approved, CI ok to start'"
Patrick Williams2e93e4e2021-12-30 10:29:38 -0600124
125 # Immediately erase the score to prevent infinite triggers.
126 "${GERRIT_SSH_CMD[@]}" review \
127 "${GERRIT_CHANGE_NUMBER},${GERRIT_PATCHSET_NUMBER}" \
Patrick Williams8ac8e092022-01-04 12:05:50 -0600128 --ok-to-test=0 -t autogenerated:jenkins --notify=NONE
Patrick Williams2e93e4e2021-12-30 10:29:38 -0600129
Andrew Geissler3c88e2d2021-01-28 15:18:11 -0600130 exit 0
131fi
132
133echo "${COMMITTER_USERNAME} is not on the approved list."
Patrick Williamsa4d19dc2021-03-15 14:51:06 -0500134"${GERRIT_SSH_CMD[@]}" review \
135 "${GERRIT_CHANGE_NUMBER},${GERRIT_PATCHSET_NUMBER}" \
Patrick Williamsf8ee6f02022-01-04 12:03:19 -0600136 --ok-to-test=0 -t autogenerated:jenkins \
Patrick Williamsa4d19dc2021-03-15 14:51:06 -0500137 "--message='User not approved, see admin, no CI'"
Andrew Geissler3c88e2d2021-01-28 15:18:11 -0600138
139exit 0