Published on

Automate your GitHub Contributions with GitHub Actions

Authors

GitHub

I recently stumbled upon a discussion on LinkedIn about how recruiters are using the GitHub Contribution Graph as a programming productivity indicator. This is a false assumption out of various reasons, just a few listed below:

  1. Only Commits to the default or gh-pages branches are considered. If you are working on a non default branch, this is not considered as a contribution.
  2. The Commits will only appear if the email used in the Git configuration is associated with your GitHub account.
  3. Opening Issues and Discussions is also considered as a contribution.
  4. Commits Do Not Equal Productivity! Money Quote:

    What should be committed is often a matter of personal preference and is subject to debate.

  5. The Graph can easily be faked by adding numerous commits in an automated way.

So to showcase how easy it is to fake contributions without spending money on computing power / setting up a server, I've written a short tutorial. But first a few words about GitHub Actions. GitHub Actions are triggered by events on GitHub and executed as code directly on the platform. Every GitHub Account has 2000 Minutes of execution time per month for free, so basically free Cloud Computing. One way of triggering a GitHub Action is by providing a CRON expression. So in the following steps we're going to set up the repository, create a GitHub Action and trigger it with a CRON expression. The GitHub Action will write random data into a file and push this file to our private GitHub repository.

  1. Initialize a Git Repository.
  2. Create a GitHub Personal Access Token. The authorization scope repo is required.
  3. Add the Secrets GH_TOKEN containing the previously created token and GH_USER containing your username.
  4. Create the file .github/workflows/contribution-bot.yaml and add the following content:
    name: Contribution Bot
    on:
      <!-- Execute the GitHub Action at minute 31 and 51 of every hour. In total the action is executed 48 times per day. -->
      schedule:
        - cron: "31,51 * * * *"
      push:
        <!-- Execute the GitHub Action if the file trigger.txt is changed in the commit. This is handy for debugging. -->
        paths:
          - "trigger.txt"
    jobs:
      push_to_repository:
        runs-on: [ubuntu-latest]
        steps:
          - uses: actions/checkout@v2
            with:
              token: ${{secrets.GH_TOKEN}}
          - name: Push to repository
            run: |
              COIN_FLIP=$(($(($RANDOM%10))%3))
              echo $COIN_FLIP
              if [ $COIN_FLIP -eq 1 ];then
                git config user.name ${{ secrets.GH_USER }}
                git config user.email '${{ secrets.GH_USER }}@users.noreply.github.com'
                COMMIT_MESSAGE=$(date "+%F %H:%M")
                rm file.txt
                echo "${COMMIT_MESSAGE}" >> file.txt
                git add .
                git commit -m "I am a productive developer ${COMMIT_MESSAGE}"
                git push
              fi
    
    The Action is triggered if the file trigger.txt is changed in the commit or on the schedule. The file is deleted and recreated and pushed to the repository every time the Action is triggered. I also added a coin flip, which only pushes in 33% of the cases. This is to simulate a "real" contribution.
  5. Create the file trigger.txt and file.txt with random content.
  6. Push the changes to the repository. The workflow should be triggered on the push event, because the trigger.txt file was changed and two times an hour. It is not sure that it is done exactly at the right time due to scheduling constraints.

So, enjoy your increased productivity!