- Published on
Automate your GitHub Contributions with GitHub Actions
- Authors
- Name
- Avasdream
- @avasdream_
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:
- 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. - The Commits will only appear if the email used in the Git configuration is associated with your GitHub account.
- Opening Issues and Discussions is also considered as a contribution.
- Commits Do Not Equal Productivity! Money Quote:
What should be committed is often a matter of personal preference and is subject to debate.
- 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.
- Initialize a Git Repository.
- Create a GitHub Personal Access Token. The authorization scope
repo
is required. - Add the Secrets
GH_TOKEN
containing the previously created token andGH_USER
containing your username. - Create the file
.github/workflows/contribution-bot.yaml
and add the following content:The Action is triggered if the filename: 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
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. - Create the file
trigger.txt
andfile.txt
with random content. - 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!