DEV Community

Cover image for Pet the cat! - Automating Profile Readme with Github Actions
Eevis (she/her)
Eevis (she/her)

Posted on

Pet the cat! - Automating Profile Readme with Github Actions

Cover photo by Kate Stone Matheson on Unsplash

When I saw Tim Burgan's awesome community chess game, I knew I had to do something with similar logic (so, something interactive in my profile readme). I started thinking and realized that the world has too few cat pictures (like, is there ever too much?) and the idea of my own (virtual) cat was born.

Here you have it - go to my profile and pet my cat! She loves hoomans, and petting. Like a lot.

My Workflow

There are two different workflows - one for updating what the cat is doing every hour and one for whenever someone pets the cat (meaning that they submit an issue with a certain title). After some content editing, the new text will be updated to the <!-- Cat Widget --> area of README.

The structure for the workflows is pretty much similar:

  1. Check out the repo and set env vars
  2. Use node and install dependencies
  3. Run the script for the action to be performed (so, either do the hourly update or pet the cat)
  4. Auto commit the changed README with stefanzweifel/git-auto-commit-action@v4 -action.

My Workflow

There are two different workflows - one for updating what the cat is doing every hour and one for whenever someone pets the cat (meaning that they submit an issue with a certain title). After some content editing, the new text will be updated to the <!-- Cat Widget --> area of README.

The structure for the workflows is pretty much similar:

  1. Check out the repo and set env vars
  2. Use node and install dependencies
  3. Run the script for the action to be performed (so, either do the hourly update or pet the cat)
  4. Auto commit the changed README with stefanzweifel/git-auto-commit-action@v4 -action.

Here are the yaml-files:

name: Update cat

on:
  schedule:
    - cron: "*/60 * * * *"
jobs:
  update:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: Set env vars
        run: |
          echo ::set-env name=REPOSITORY::${{ github.repository }}
      - name: Use Node.js
        uses: actions/setup-node@v1
        with:
          node-version: "12.x"
      - name: Install node modules
        run: npm install
      - name: Update cat
        run: npm start
        env:
          API_KEY: ${{ secrets.API_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - uses: stefanzweifel/git-auto-commit-action@v4
        with:
          commit_user_name: github-actions[bot]
          commit_user_email: github-actions[bot]@users.noreply.github.com
          commit_author: Actions <github-actions[bot]@users.noreply.github.com>
          commit_message: "Hourly update :cat:"
Enter fullscreen mode Exit fullscreen mode

and

name: Pet cat

on:
  issues:
    types: [opened]
jobs:
  pet:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js
        if: startsWith(github.event.issue.title, 'pet-')
        uses: actions/setup-node@v1
        with:
          node-version: "12.x"
      - name: Install node modules
        if: startsWith(github.event.issue.title, 'pet-')
        run: npm install
      - name: Set env vars
        if: startsWith(github.event.issue.title, 'pet-')
        run: |
          echo ::set-env name=REPOSITORY::${{ github.repository }}
          echo ::set-env name=EVENT_ISSUE_NUMBER::${{ github.event.issue.number }}
          echo ::set-env name=EVENT_USER_LOGIN::${{ github.event.issue.user.login }}
      - name: Update cat
        if: startsWith(github.event.issue.title, 'pet-')
        run: npm start
        env:
          API_KEY: ${{ secrets.API_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - uses: stefanzweifel/git-auto-commit-action@v4
        if: startsWith(github.event.issue.title, 'pet-')
        with:
          commit_user_name: github-actions[bot]
          commit_user_email: github-actions[bot]@users.noreply.github.com
          commit_author: Actions <github-actions[bot]@users.noreply.github.com>
          commit_message: "@${{ github.event.issue.user.login }} petted the cat"

Enter fullscreen mode Exit fullscreen mode

Submission Category:

Wacky Wildcards

Link to Code

Heippa! 👋 (Hello in Finnish 🇫🇮)

Short about me:

  • I'm software developer and accessibility specialist
  • I work at Oura Health
  • I blog and speak at meetups and conferences
  • When not coding or sharing my knowledge, I play ultimate frisbee and explore the world by foot and a kayak.

You can find more about me from my website.

Mau 🐱

There's a (virtual) cat living in this repo! Right now she's having a friend over

cat

Happiness

She loves hooomans, and petting. This is how happy she is right now:

💖 🖤 🖤 🖤 🖤 🖤 🖤 🖤 🖤 🖤

Happiness level: 10/100

If you want to pet her, you can do it by clicking this link.

Last times she's been petted:

Date User
06/04/2022 @NzakiCodes
04/04/2022 @late-e
09/03/2022 @ahwelgemoed
19/01/2022 @NicolasOmar
29/11/2021 @thezacharytaylor

The pictures are from the Cat Api

Additional Resources

The pictures are from the Cat Api

Discussion (0)