Random Selection of Members for Activities Planning

Tanankem Ramses
4 min readJan 19, 2024

--

I am a member of a group of AI enthusiasts. We sometimes need to select some members to carry out some activities (presentations or article writing). Doing the selection manually was tedious, with many communication difficulties. To overcome those limits and allow everyone to participate equitably in the group dynamic, we decided to automate the task attribution process. The automation process we have set up is based on GitHub actions. In this article, we will present in detail how the developed workflow works and the advantages of such a system.

Table of Contents

How does the selection process work?
GitHub actions: A simplified overview
Random selection of a member
Automation of the execution of the script and notification of selected users: GitHub actions workflow
Conclusion

How does the selection process work?

Given the list of the members of the group, we have to randomly draw a member to carry out a given activity. Here are the steps of the selection process:

  1. First, we have to select the sublist of members to consider in the draw. The members to consider in the draw are members for which the last date of activity is greater than a given delay. For instance, if the delay is 3 months, a member is included in the list of possible members who can be selected if the last date of participation of this member for the given activity was more than 3 months ago.
  2. From the sublist of members that can be drawn, we then randomly select one member, each member having the same probability of being drawn.
  3. Once a member is selected, we create an issue on the GitHub repository tagging the member to notify him and ask for his availability.
  4. Now the communication can take place in the comments section of the issue to fix the date and the details of the activity. Once all is agreed, the issue is closed. Now, the selected member will not be included in the future draws for the next 3 months (the fixed delay).

In the next sections, we are going to give you a brief overview of the code of the workflow.

GitHub actions: A simplified overview

GitHub Actions is a powerful automation feature within GitHub, offering the flexibility to create and execute custom workflows directly in a repository. These workflows are defined in YAML files and can handle a variety of tasks, from simple code checks to complex build and deployment processes. An essential aspect of GitHub Actions is the ability to set triggers for launching these workflows, which can be specific events like a push, a pull request, or scheduled times using cron syntax. Each workflow comprises jobs that execute in isolated virtual environments, such as containers or virtual machines, ensuring consistency and replicability across runs. You can check this GitHub page for more details on GitHub actions.

Random selection of a member

For the random selection of a member, we use the choice function of the numpy library.

salt = 300
seed = int(datetime.now().timestamp())
random.seed(seed + salt)
np.random.seed(seed + salt)

#members_list: list of github usernames from which the draw is made
#k: the number of members to draw
selected_members = (
np.random.choice(a=members_list, size=k, replace=False)
).tolist()

This call randomly selects k members from members_list, and all the members have the same weight in the drawing.

Once the members are selected, they are kept as environment variables in the GITHUB_ENV environment, so we will be able to use them when setting up the GitHub actions.

# Write the selected usernames in the GITHUB_ENV environment
env_file = os.getenv("GITHUB_ENV")
if env_file is None:
# If GITHUB_ENV is not set, we are likely in dev env, use a temporary file
with tempfile.NamedTemporaryFile(mode="a", delete=False) as file:
for i, username in enumerate(choosen_candidates, start=1):
file.write(f"user{i}={username}\n")
else:
with open(env_file, "a") as file_env:
for i, username in enumerate(choosen_candidates, start=1):
file_env.write(f"user{i}={username}\n")

Automation of the execution of the script and notification of selected users: GitHub actions workflow

To avoid having to launch the previous script manually, we decided to set up a GitHub actions workflow that will periodically run the script and notify the selected members. To achieve that, we used the cron syntax to schedule the execution of the script. Each time the script is executed, an issue is created on the GitHub repository, in which we mention the selected members to ask them for their availability.

Here is an overview of the workflow.

name: Pick_some_member
on:
schedule:
- cron: '42 10 * * mon' # Every monday at 10:42
workflow_dispatch:

jobs:
job1:
name: Debug
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.8'
- run: pip install numpy pandas python-dotenv argparse
- run: python main.py --column_to_check availability_article
env:
MEMBERS_SHEET_URL: ${{ secrets.MEMBERS_SHEET_URL }}
- name: Create team sync issue
run: gh issue create --title "$TITLE" --assignee "$ASSIGNEES" --body "$BODY" --label "$LABELS"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
TITLE: "ENSPY AI [Article] : ${{ env.user1 }}, let's share your insights!"
LABELS: article
BODY: |
Hello ${{ env.user1 }}

Message...

Best Regards
PINNED: false
CLOSE_PREVIOUS: false

Once the issue is created, the selected members will receive an email. They will then be able to go and add comments on the issue to give their availability and fix the details concerning the task to achieve. When everything is okay, the issue is closed.

Conclusion

In this article, we presented a way to automate the process of members selection and task assignment in a group using a GitHub actions workflow. This approach has the advantage of being human independent, avoiding situations such as delays in execution. The process is automated, and thanks to discussions using issues, we can keep a log that can be useful later.

--

--

Tanankem Ramses

Msc in Data Science and Artificial Intelligence student