|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# This scripts generates the 'collaborators' and 'maintainers' GitHub team |
| 4 | +# member list files from the Zephyr MAINTAINERS.yml file. |
| 5 | + |
| 6 | +set -e |
| 7 | + |
| 8 | +usage() |
| 9 | +{ |
| 10 | + echo "Usage: $(basename $0) maintainers_file manifest_path" |
| 11 | +} |
| 12 | + |
| 13 | +# Validate and prase arguments |
| 14 | +if [ "$1" == "" ]; then |
| 15 | + usage |
| 16 | + echo |
| 17 | + echo "maintainers_file must be specified." |
| 18 | + exit 1 |
| 19 | +elif [ "$2" == "" ]; then |
| 20 | + usage |
| 21 | + echo |
| 22 | + echo "manifest_path must be specified." |
| 23 | + exit 1 |
| 24 | +fi |
| 25 | + |
| 26 | +maintainers_file=$1 |
| 27 | +manifest_path=$2 |
| 28 | + |
| 29 | +if [ ! -f "${maintainers_file}" ]; then |
| 30 | + echo "'${maintainers_file}' does not exist." |
| 31 | + exit 2 |
| 32 | +fi |
| 33 | + |
| 34 | +if [ ! -d "${manifest_path}" ]; then |
| 35 | + echo "'${manifest_path}' is not a valid directory." |
| 36 | +fi |
| 37 | + |
| 38 | +# Read and validate maintainers file. |
| 39 | +maintainers_data=$(<${maintainers_file}) |
| 40 | + |
| 41 | +echo "${maintainers_data}" | yq &> /dev/null || ( |
| 42 | + echo "'${maintainers_file}' is not a valid YAML file." |
| 43 | + exit 10 |
| 44 | +) |
| 45 | + |
| 46 | +# Get the list of all collaborators |
| 47 | +all_collaborators=$(echo "${maintainers_data}" | yq -r '.[].collaborators.[]') |
| 48 | +all_collaborators=$(echo "${all_collaborators}" | sort -f -u) |
| 49 | + |
| 50 | +# Get the list of all maintainers |
| 51 | +all_maintainers=$(echo "${maintainers_data}" | yq -r '.[].maintainers.[]') |
| 52 | +all_maintainers=$(echo "${all_maintainers}" | sort -f -u) |
| 53 | + |
| 54 | +# Write team member list files |
| 55 | +global_admins=$(<${manifest_path}/global-admins.csv) |
| 56 | +global_admins=$(echo "${global_admins}" | tail -n +2) |
| 57 | +global_admins=(${global_admins}) |
| 58 | + |
| 59 | +write_team_member_list() |
| 60 | +{ |
| 61 | + output_file="$1" |
| 62 | + member_list="$2" |
| 63 | + |
| 64 | + echo "username,role" > "${output_file}" |
| 65 | + for user in ${member_list}; do |
| 66 | + if [[ " ${global_admins[@]} " =~ " ${user} " ]]; then |
| 67 | + echo "${user},maintainer" >> ${output_file} |
| 68 | + else |
| 69 | + echo "${user},member" >> "${output_file}" |
| 70 | + fi |
| 71 | + done |
| 72 | +} |
| 73 | + |
| 74 | +write_team_member_list "${manifest_path}/team/team-members/collaborators.csv" "${all_collaborators}" |
| 75 | +write_team_member_list "${manifest_path}/team/team-members/maintainers.csv" "${all_maintainers}" |
0 commit comments