Andrew Geissler | 3c88e2d | 2021-01-28 15:18:11 -0600 | [diff] [blame] | 1 | #!/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 Eda | a6ebc6e | 2024-06-17 11:51:45 +0530 | [diff] [blame] | 10 | # provided by that plugin are available (i.e. GERRIT_PROJECT, ...) |
Andrew Geissler | 3c88e2d | 2021-01-28 15:18:11 -0600 | [diff] [blame] | 11 | # |
| 12 | # Required Inputs: |
| 13 | # SSH_KEY: Path to private ssh key used to post messages to gerrit |
| 14 | |
Andrew Geissler | 3705241 | 2022-05-20 15:28:26 -0400 | [diff] [blame] | 15 | GERRIT_COMMAND="curl -s --anyauth -n https://gerrit.openbmc.org" |
Patrick Williams | a4d19dc | 2021-03-15 14:51:06 -0500 | [diff] [blame] | 16 | GERRIT_SSH_CMD=( \ |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 17 | ssh -o 'StrictHostKeyChecking no' -i "$SSH_KEY" \ |
| 18 | -p 29418 jenkins-openbmc-ci@gerrit.openbmc.org gerrit \ |
| 19 | ) |
Andrew Geissler | 3c88e2d | 2021-01-28 15:18:11 -0600 | [diff] [blame] | 20 | |
| 21 | echo "Checking ${GERRIT_PROJECT}:${GERRIT_BRANCH}:${GERRIT_CHANGE_ID}:${GERRIT_PATCHSET_REVISION}" |
| 22 | |
Patrick Williams | ac912df | 2024-04-01 10:28:05 -0500 | [diff] [blame] | 23 | COMMITTER_USERNAME=$("${GERRIT_SSH_CMD[@]}" query "${GERRIT_CHANGE_NUMBER}" --current-patch-set --format json | jq -r '.currentPatchSet.uploader.username | select (. != null )') |
Andrew Geissler | 3c88e2d | 2021-01-28 15:18:11 -0600 | [diff] [blame] | 24 | echo "USERNAME: $COMMITTER_USERNAME" |
Ed Tanous | 5d3031d | 2022-02-16 15:57:15 -0800 | [diff] [blame] | 25 | if [ "${COMMITTER_USERNAME}" = "" ]; then |
Andrew Geissler | 3c88e2d | 2021-01-28 15:18:11 -0600 | [diff] [blame] | 26 | echo "Unable to determine github user for ${COMMITTER_EMAIL}." |
Patrick Williams | a4d19dc | 2021-03-15 14:51:06 -0500 | [diff] [blame] | 27 | "${GERRIT_SSH_CMD[@]}" review \ |
| 28 | "${GERRIT_CHANGE_NUMBER},${GERRIT_PATCHSET_NUMBER}" \ |
Patrick Williams | f8ee6f0 | 2022-01-04 12:03:19 -0600 | [diff] [blame] | 29 | --ok-to-test=0 "--message='Unable to determine github user'" |
Patrick Williams | a4d19dc | 2021-03-15 14:51:06 -0500 | [diff] [blame] | 30 | exit 1 |
Andrew Geissler | 3c88e2d | 2021-01-28 15:18:11 -0600 | [diff] [blame] | 31 | fi |
| 32 | |
| 33 | # Reset the vote to 0 so jenkins will detect a new +1 on retriggers |
Patrick Williams | a4d19dc | 2021-03-15 14:51:06 -0500 | [diff] [blame] | 34 | "${GERRIT_SSH_CMD[@]}" review \ |
| 35 | "${GERRIT_CHANGE_NUMBER},${GERRIT_PATCHSET_NUMBER}" \ |
Patrick Williams | 8ac8e09 | 2022-01-04 12:05:50 -0600 | [diff] [blame] | 36 | --ok-to-test=0 -t autogenerated:jenkins --notify=NONE |
Andrew Geissler | 3c88e2d | 2021-01-28 15:18:11 -0600 | [diff] [blame] | 37 | |
Patrick Williams | 47b59dc | 2022-07-18 16:58:42 -0500 | [diff] [blame] | 38 | # 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 Geissler | 3c88e2d | 2021-01-28 15:18:11 -0600 | [diff] [blame] | 51 | # Write full list of users to a file |
Patrick Williams | a4d19dc | 2021-03-15 14:51:06 -0500 | [diff] [blame] | 52 | GERRIT_CI_GROUPS=( \ |
Andrew Geissler | 7e15307 | 2024-06-26 14:43:06 -0400 | [diff] [blame] | 53 | aimvalley/ci-authorized \ |
Patrick Williams | b836d24 | 2023-10-13 21:10:41 -0500 | [diff] [blame] | 54 | akamai/ci-authorized \ |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 55 | alibaba/ci-authorized \ |
| 56 | amd/ci-authorized \ |
| 57 | ami/ci-authorized \ |
| 58 | ampere/ci-authorized \ |
| 59 | arm/ci-authorized \ |
| 60 | aspeed/ci-authorized \ |
Andrew Geissler | 971d68b | 2023-11-10 08:54:49 -0600 | [diff] [blame] | 61 | asus/ci-authorized \ |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 62 | bytedance/ci-authorized \ |
Andrew Geissler | ad42f70 | 2023-11-17 09:45:25 -0600 | [diff] [blame] | 63 | celestica/ci-authorized \ |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 64 | code-construct/ci-authorized \ |
Andrew Geissler | f38b5c9 | 2024-07-11 11:26:00 -0400 | [diff] [blame] | 65 | dell/ci-authorized \ |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 66 | depo/ci-authorized \ |
| 67 | erg/ci-authorized \ |
Patrick Williams | 93d22a4 | 2023-04-21 14:55:26 -0500 | [diff] [blame] | 68 | equinix/ci-authorized \ |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 69 | facebook/ci-authorized \ |
| 70 | fii/ci-authorized \ |
Paul Fertser | 83d69a2 | 2024-01-24 10:46:32 +0000 | [diff] [blame] | 71 | gagar-in/ci-authorized \ |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 72 | google/ci-authorized \ |
| 73 | hcl/ci-authorized \ |
| 74 | hpe/ci-authorized \ |
| 75 | ibm/ci-authorized \ |
Andrew Geissler | 6481ea4 | 2023-11-10 14:39:25 -0600 | [diff] [blame] | 76 | iei/ci-authorized \ |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 77 | individual/ci-authorized \ |
| 78 | inspur/ci-authorized \ |
| 79 | intel/ci-authorized \ |
| 80 | inventec/ci-authorized \ |
| 81 | lenovo/ci-authorized \ |
| 82 | microsoft/ci-authorized \ |
| 83 | nineelements/ci-authorized \ |
| 84 | nuvoton/ci-authorized \ |
| 85 | nvidia/ci-authorized \ |
| 86 | openbmc/ci-authorized \ |
| 87 | pcpartner/ci-authorized \ |
| 88 | phytium/ci-authorized \ |
Andrew Geissler | 7d88622 | 2024-01-12 00:52:37 -0600 | [diff] [blame] | 89 | plexus/ci-authorized \ |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 90 | quanta/ci-authorized \ |
| 91 | quic/ci-authorized \ |
| 92 | rcs/ci-authorized \ |
| 93 | supermicro/ci-authorized \ |
Andrew Geissler | b873036 | 2023-12-01 13:46:26 -0600 | [diff] [blame] | 94 | tencent/ci-authorized \ |
Andrew Geissler | 2b2f4f1 | 2024-03-11 18:21:56 +0530 | [diff] [blame] | 95 | triple-crown/ci-authorized \ |
Jordan Chang | fd0e80d | 2023-03-06 09:49:30 +0800 | [diff] [blame] | 96 | ufispace/ci-authorized \ |
Patrick Williams | eb4961b | 2023-05-04 11:28:26 -0500 | [diff] [blame] | 97 | vaisala/ci-authorized \ |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 98 | wistron/ci-authorized \ |
| 99 | wiwynn/ci-authorized \ |
| 100 | yadro/ci-authorized \ |
| 101 | ) |
Andrew Geissler | 3c88e2d | 2021-01-28 15:18:11 -0600 | [diff] [blame] | 102 | |
Patrick Williams | a4d19dc | 2021-03-15 14:51:06 -0500 | [diff] [blame] | 103 | rm -f "$WORKSPACE/users.txt" |
| 104 | for g in "${GERRIT_CI_GROUPS[@]}"; do |
| 105 | "${GERRIT_SSH_CMD[@]}" ls-members "$g" --recursive \ |
| 106 | >> "$WORKSPACE/users.txt" |
| 107 | done |
Andrew Geissler | 3c88e2d | 2021-01-28 15:18:11 -0600 | [diff] [blame] | 108 | |
| 109 | # grep for the specific username word in the file |
Patrick Williams | a4d19dc | 2021-03-15 14:51:06 -0500 | [diff] [blame] | 110 | if grep -q -w "${COMMITTER_USERNAME}" "$WORKSPACE/users.txt"; then |
| 111 | "${GERRIT_SSH_CMD[@]}" review \ |
| 112 | "${GERRIT_CHANGE_NUMBER},${GERRIT_PATCHSET_NUMBER}" \ |
Patrick Williams | 8ac8e09 | 2022-01-04 12:05:50 -0600 | [diff] [blame] | 113 | --ok-to-test=1 -t autogenerated:jenkins --notify=NONE \ |
Patrick Williams | a4d19dc | 2021-03-15 14:51:06 -0500 | [diff] [blame] | 114 | "--message='User approved, CI ok to start'" |
Patrick Williams | 2e93e4e | 2021-12-30 10:29:38 -0600 | [diff] [blame] | 115 | |
| 116 | # Immediately erase the score to prevent infinite triggers. |
| 117 | "${GERRIT_SSH_CMD[@]}" review \ |
| 118 | "${GERRIT_CHANGE_NUMBER},${GERRIT_PATCHSET_NUMBER}" \ |
Patrick Williams | 8ac8e09 | 2022-01-04 12:05:50 -0600 | [diff] [blame] | 119 | --ok-to-test=0 -t autogenerated:jenkins --notify=NONE |
Patrick Williams | 2e93e4e | 2021-12-30 10:29:38 -0600 | [diff] [blame] | 120 | |
Andrew Geissler | 3c88e2d | 2021-01-28 15:18:11 -0600 | [diff] [blame] | 121 | exit 0 |
| 122 | fi |
| 123 | |
| 124 | echo "${COMMITTER_USERNAME} is not on the approved list." |
Patrick Williams | a4d19dc | 2021-03-15 14:51:06 -0500 | [diff] [blame] | 125 | "${GERRIT_SSH_CMD[@]}" review \ |
| 126 | "${GERRIT_CHANGE_NUMBER},${GERRIT_PATCHSET_NUMBER}" \ |
Patrick Williams | f8ee6f0 | 2022-01-04 12:03:19 -0600 | [diff] [blame] | 127 | --ok-to-test=0 -t autogenerated:jenkins \ |
Patrick Williams | a4d19dc | 2021-03-15 14:51:06 -0500 | [diff] [blame] | 128 | "--message='User not approved, see admin, no CI'" |
Andrew Geissler | 3c88e2d | 2021-01-28 15:18:11 -0600 | [diff] [blame] | 129 | |
| 130 | exit 0 |