0

GitHub Follower Management

Discover how to streamline GitHub follower management effortlessly using GitHub Actions.

Automating GitHub Follower

Managing your GitHub followers manually can be time-consuming. Thankfully, with the "follower-sync" action, you can automate this task effortlessly. Here's how it works

Setting up Workflow Folder

To begin automating GitHub follower management with the "follower-sync" action, the first step is to create the .github/workflows folder within your repository. The .github folder is a special directory recognized by GitHub.

Configure Secrets

For the 'follower-sync' action, you'll need to configure the PERSONAL_ACCESS_TOKEN. However, if you wish to receive email notifications for follower changes, you'll also need to set up secrets for your email credentials and the recipient's email address.

  • PERSONAL_ACCESS_TOKEN is required for authentication purposes, allowing the actions to access your GitHub account and perform actions like fetching follower data and managing followers. Ensure that this token has the necessary permissions, typically at least the user scope permission, to perform the required actions.
  • MAIL_USERNAME and MAIL_PASSWORD these secrets are used for sending email notifications. They represent the username and password for the email account that will be used to send notifications.
  • TO_EMAIL_ADDRESS: This secret represents the email address where you want to receive follower change notifications. Provide your desired email address here to receive notifications about any changes in your GitHub followers.

By configuring these secrets in your GitHub repository's settings, you ensure that sensitive information such as access tokens and email credentials are kept secure and are only accessible to authorized workflows within your repository. Make sure to follow best practices for managing secrets, such as avoiding hardcoding them directly in the workflow files and regularly rotating them for security purposes.

Trigger Setup

config.yaml
name: follower-management
 
on:
  workflow_dispatch:
  schedule:
    - cron: "15 7 * * *"

This sets up the workflow to run on a schedule using cron syntax, triggering it every day at 1:15 PM. Additionally, it can be manually triggered via the GitHub Actions UI. You can configure the schedule according to your needs by adjusting the cron expression.

Follower Change Notification Job

If you're solely interested in automating GitHub follower management with the "follower-sync" action and don't require email notifications or follower change notifications, you can skip this part.

However, if you'd like to receive email notifications for follower changes, follow along as we set up the Follower Change Notification Job.

config.yaml
jobs:
  follower-notifier:
    runs-on: ubuntu-latest
    steps:
      - name: get-follower-change
        id: followerChange
        uses: Sorosliu1029/follower-change@v2
        with:
          myToken: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
          notifyUnFollowEvent: true
      - name: email-me
        uses: dawidd6/action-send-mail@v3
        if: steps.followerChange.outputs.shouldNotify == 'true'
        with:
          server_address: smtp.gmail.com
          server_port: 465
          username: ${{ secrets.MAIL_USERNAME }}
          password: ${{ secrets.MAIL_PASSWORD }}
          subject: GitHub Follower Change
          from: Follower Change Notifier
          to: ${{ secrets.TO_EMAIL_ADDRESS }}
          html_body: file://${{ steps.followerChange.outputs.htmlFilePath }}

This job is responsible for detecting changes in GitHub followers. It uses the "follower-change" action to monitor follower activity. If any unfollow events are detected, it sends an email notification using the "action-send-mail" action.

Cleanup Follower Job

Remove needs: [follower-notifier] if you're not interested in follower change notifications. If you want to fork the repository and customize it for your own test here is github link Follower Sync

config.yaml
cleanup-follower:
  runs-on: ubuntu-latest
  needs: [follower-notifier]
  steps:
    - name: start-cleaning
      uses: al-imam/follower-sync@v1
      with:
        personal-access-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
        each-operation-delay: 5000
        safe-list: ${{ vars.SAFE_LIST }}

The safe-list input allows you to specify GitHub usernames that should not be unfollowed during the cleanup process. It is a multiline input, meaning each username should be listed on a new line for example -

al-imam
Sorosliu1029
dawidd6

Cleanup follower job automatically cleans up the GitHub followers list. It utilizes the "follower-sync" action to follow and unfollow users, enhancing follower management efficiency.

Conclusion

By leveraging the "follower-sync" action in your GitHub Actions workflow, you can automate the process of managing GitHub followers effectively.