Pet the cat! - Automating Profile Readme with Github Actions
Tags: actionshackathon, showdev, typescript
Published: 2020-08-18 10:45:39

*Cover photo by <a href="https://unsplash.com/@kstonematheson?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Kate Stone Matheson</a> on <a href="https://unsplash.com/s/photos/cat?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a>*

When I saw [Tim Burgan's awesome community chess game](https://github.com/timburgan), 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](https://github.com/eevajonnapanula)! 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](https://github.com/marketplace/actions/git-auto-commit) -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](https://github.com/marketplace/actions/git-auto-commit) -action.

Here are the yaml-files: 

```yml
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:"
```
and 

```yml
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"

```

### Submission Category: 

Wacky Wildcards


### Link to Code

{% github https://github.com/eevajonnapanula/eevajonnapanula %}

### Additional Resources 

The pictures are from [the Cat Api](https://thecatapi.com/)