Skip to content
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
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/team-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Team Linter
on:

# manual trigger
workflow_dispatch:

# on pull request involving the ladder/teams directory
pull_request:
paths: 'ladder/teams/**'
joestringer marked this conversation as resolved.
Show resolved Hide resolved

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
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

env:
GITHUB_TOKEN: ${{ secrets.TM_ORG_READ_TOKEN }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note (for me): Set up this token.

78 changes: 78 additions & 0 deletions tools/lint_members.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/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"

logins=( `curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/$2/members | jq -r '.[].login'` )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be worth checking whether this list is truncated.. I suspect that there's pagination going on, given the number of org members.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated in new commit

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be worth checking whether this list is truncated.. I suspect that there's pagination going on, given the number of org members.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated in commit

>&2 echo "Org Members:"
for login in "${logins[@]}"; do
>&2 echo "$login"
done
>&2 echo ""

status=0
for file in *.yaml; do
>&2 echo -e "\n>> Linting members/mentors from $file"
f="${file%.*}"
cd "$CDIR"; cd "$1"
members=`yq -o t '.members' $file`
for member in $members; do
#>&2 echo "checking team member: $member"
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
done

mentors=`yq -o t '.mentors' $file`
for mentor in $mentors; do
#>&2 echo "checking team mentor: $mentor"
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
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