Using Github (Actions) to mess with Github.

·

2 min read

I recently wrote a Github Action that makes one commit to its parent repo once a day, and I'll attach the code at the end of this article. It was a neat learning exercise, and a satisfying, although there's not much here technically.

I became interested in this idea from two angles:

  1. I was once asked to write a cron job that accessed a legacy API once per day. This was a pretty simple task - all I needed to do was send one API request per day, and I didn't need to handle the response, or do anything in the way of error handling.

The end result of this assignment was a process written in Go and deployed on Google Cloud Platform. It worked, but the level of time and effort felt disproportionate to what I felt was a trivial task.

As such, I started looking into more expedient alternatives for automating certain tasks, and that's how Github actions came to my attention.

  1. At the same time, I've always been looking for ways to maintain my Github contribution count. It's generally recommended that you keep up a steady stream of commits, but it can be challenging to do so. A lot of what I work on does not attach to my personal Github account, or I might forget to push changes on a personal project. As such, there's a lot of work that is 'lost.'

As promised. The result of this process is below:


name: Commit date to master
on:
  schedule:
    # Runs "every day at 12:00" (see https://crontab.guru)
    - cron: '0 12 * * *'
jobs:
  date:
    runs-on: ubuntu-latest
    steps:
      # Checkout the branch
      - name: checkout
        uses: actions/checkout@v3
      - name: save current date
        run: |
          # do some operation that changes a file in the git repo
          date > time.txt
      - name: setup git config
        run: |
          # setup the username and email. 
          git config user.name "Your Name"
          git config user.email "your-email@example.com"

      - name: commit
        run: |
          # Stage the file, commit and push
          git add time.txt
          git commit -m "new date commit"
          git push origin main

I can't say this was any great technical innovation, beyond learning Github actions. For me, the great reward is achieving something that makes life more convenient, solving a problem, even if the means is less than impressive.