-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Team Management Automation Enhancement: Add team linter workflow and linter script #208
Open
jspaleta
wants to merge
5
commits into
cilium:main
Choose a base branch
from
jspaleta:jspaleta/team-management-linter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+189
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
14f855f
Add team linter workflow and linter script to be run pull requests th…
jspaleta 1764783
include the workflow file in the pull request paths
jspaleta 7d6414b
Account for GitHub API paging
jspaleta 993af27
report unexpected API status code as error, as a check on auth token
jspaleta 1522ac3
Refactor linter to use githubwide login rest api to check for login c…
jspaleta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Team Linter | ||
on: | ||
|
||
# manual trigger | ||
workflow_dispatch: | ||
|
||
# on pull request involving the ladder/teams directory | ||
pull_request: | ||
paths: | ||
- 'ladder/teams/**' | ||
- '.github/workflows/team-lint.yaml' | ||
|
||
jobs: | ||
team-management-linter: | ||
if: github.repository == 'cilium/community' | ||
name: Team Management Linter Workflow | ||
runs-on: ubuntu-latest | ||
environment: team-management | ||
steps: | ||
# Checkout repo with full config | ||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | ||
# Lint team membership files for org members | ||
- name: check team membership for org membership | ||
run: tools/lint_members.sh ladder/teams cilium | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.TM_ORG_READ_TOKEN }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note (for me): Set up this token. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
#!/usr/bin/env bash | ||
# Copyright Authors of Cilium | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
## | ||
# This script is used to lint team membership | ||
# file based on a directory of yaml files of the | ||
# form team-name.yaml | ||
# This tool is used as part of team-management automation | ||
## | ||
|
||
set -eu | ||
set -o pipefail | ||
|
||
# $1 - teams directory | ||
# $2 - org name | ||
if [ $# -ne 2 ]; then | ||
echo "Usage: $0 <TEAMS_DIRECTORY> <GITHUB_ORG>" | ||
echo "Organization read token in envvar GITHUB_TOKEN" | ||
exit 1 | ||
fi | ||
|
||
>&2 echo "> Linting $2 teams from $1/*.yaml" | ||
CDIR=`pwd` | ||
cd "$1" | ||
|
||
# Use GitHub API with paging to recover Org member login list | ||
url="https://api.github.com/orgs/$2/members" | ||
page=1 | ||
flag=true | ||
logins=() | ||
check_org_members=true | ||
while $flag; do | ||
status=$(curl --head --location --connect-timeout 5 --write-out %{http_code} --silent --output /dev/null -H "Authorization: Bearer $GITHUB_TOKEN" ${url}?page=${page}) | ||
if [[ "$status" -gt 399 ]] ; then | ||
echo "GitHub API Org Membership Retrieval Failure with Status Code: $status" | ||
flag=false | ||
check_org_members=false | ||
fi | ||
if $flag; then | ||
response=$( curl -s -I -H "Authorization: Bearer $GITHUB_TOKEN" "${url}?page=${page}" ) | ||
# Append to logins array | ||
logins+=( `curl --no-progress-meter -L \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer $GITHUB_TOKEN" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
${url}?page=${page} | jq -r '.[].login'` ) | ||
|
||
# Check to see if there is a next page to grab | ||
set +o pipefail | ||
next_page=$(echo "$response" | grep -s 'rel="next"' | sed 's/.*<//' | sed 's/>.*//') | ||
set -o pipefail | ||
|
||
if [[ -z "$next_page" ]]; then | ||
flag=false | ||
fi | ||
|
||
page=$((page + 1)) | ||
fi | ||
done | ||
if $check_org_members; then | ||
>&2 echo "Org Members:" | ||
for login in "${logins[@]}"; do | ||
>&2 echo "$login" | ||
done | ||
fi | ||
>&2 echo "" | ||
|
||
status=0 | ||
for file in *.yaml; do | ||
>&2 echo -e "\n>> Linting members from $file" | ||
f="${file%.*}" | ||
cd "$CDIR"; cd "$1" | ||
set +e | ||
members=$(yq -e -o t '.members' $file 2>/dev/null) | ||
ret=$? | ||
set -e | ||
if [ $ret -ne 0 ]; then | ||
continue | ||
fi | ||
for member in ${members[@]}; do | ||
if [ -n "$member" ]; then | ||
|
||
#>&2 echo "checking team member: $member" | ||
# Checking to see if team member login is cased correctly | ||
http_status=`curl --header "Authorization: Bearer $GITHUB_TOKEN" --head --location --connect-timeout 5 --write-out %{http_code} --silent --output /dev/null --no-progress-meter "https://api.github.com/users/${member}"` | ||
if [[ "$http_status" -gt 399 ]] ; then | ||
>&2 echo "Error: Member: ${member} :: GitHub API Status Code: $http_status" | ||
status=1 | ||
else | ||
login=`curl --header "Authorization: Bearer $GITHUB_TOKEN" --no-progress-meter "https://api.github.com/users/${member}" | jq -r .login` | ||
if [ "$login" == "$member" ] ; then | ||
found=1 | ||
else | ||
>&2 echo "Team $f Member: $member case mistatch should be : $login" | ||
status=1 | ||
fi | ||
fi | ||
|
||
# Checking to see if team member login is in org membership | ||
if $check_org_members; then | ||
found=0 | ||
for login in "${logins[@]}"; do | ||
if [ "$login" == "$member" ] ; then | ||
found=1 | ||
fi | ||
done | ||
if [ $found -eq 0 ] ; then | ||
>&2 echo "Team $f Member: $member not found in Org: $2" | ||
status=1 | ||
fi | ||
fi | ||
fi | ||
done | ||
>&2 echo -e "\n>> Linting mentors from $file" | ||
|
||
set +e | ||
mentors=$(yq -e -o t '.mentors' $file 2>/dev/null) | ||
ret=$? | ||
set -e | ||
if [ $ret -ne 0 ]; then | ||
continue | ||
fi | ||
for mentor in ${mentors[@]}; do | ||
if [ -n "$mentor" ]; then | ||
>&2 echo "checking team mentor: $mentor" | ||
# Checking to see if team mentor login is cased correctly | ||
http_status=`curl --header "Authorization: Bearer $GITHUB_TOKEN" --head --location --connect-timeout 5 --write-out %{http_code} --silent --output /dev/null --no-progress-meter "https://api.github.com/users/${mentor}"` | ||
if [[ "$http_status" -gt 399 ]] ; then | ||
>&2 echo "Error: Mentor: ${mentor} :: GitHub API Status Code: $http_status" | ||
status=1 | ||
else | ||
login=`curl --header "Authorization: Bearer $GITHUB_TOKEN" --no-progress-meter "https://api.github.com/users/${mentor}" | jq -r .login` | ||
if [ "$login" == "$mentor" ] ; then | ||
found=1 | ||
else | ||
>&2 echo "Team $f Mentor: $mentor case mistatch should be : $login" | ||
status=1 | ||
fi | ||
fi | ||
|
||
# Checking to see if team mentor login is in org membership | ||
if $check_org_members; then | ||
found=0 | ||
for login in "${logins[@]}"; do | ||
if [ "$login" == "$mentor" ] ; then | ||
found=1 | ||
fi | ||
done | ||
if [ $found -eq 0 ] ; then | ||
>&2 echo "Team $f Mentor: $mentor not found in Org: $2" | ||
status=1 | ||
fi | ||
fi | ||
fi | ||
done | ||
done | ||
if [ $status -eq 1 ] ; then | ||
>&2 echo -e "\n> At least one team member or mentor missing from org $2: exiting" | ||
exit 1 | ||
fi | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the recent additions to the org, I have merged these files first and then run a sync script that detects such member cases and adds them into GitHub. This linter reverses this, meaning that the member would have to be in the GitHub org first before we sync. Will need new scripting to work this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That said I think there's multiple ways to solve this, but having a linter like this in this repo seems like the right approach. Maybe I'll just rethink the sync script or rip it out and go back to the old process for adding new members.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I look at it this way this linter is a reminder to run the sync. Worst case is you rekick the failed workflow after the sync and that should clear the PR for merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but the sync could run against the PR checkout right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I could rebuild the linter logic just to check for casing errors but wrong/missing org login seems like a good thing to catch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep sync could be run against the PR checkout.