DEV Community

Cover image for 🦄 Sharing DEV Followers Count on Github Profile 🦄
Anna Villarreal
Anna Villarreal Subscriber Community Curator

Posted on

🦄 Sharing DEV Followers Count on Github Profile 🦄

TLDR - I finished a small project that I am sharing for my friends on DEV, that allows you to put your followers count on your Github!


I had started this nonsense last year, and like many silly side projects, let it go to the wayside. But there was one consistent tiny reminder in me email everyday: "Run failed for Github Actions..." 😂

I said well, I could just delete it all. But that bothered me. I should be able to get it to work, right? Feeling determined today, I said enough is enough with the annoying emails and I am going to fix this. A little tweak to the api calling and a little deletion of unused code that I had commented out and things began to get much more clear.

I'm going to share the full code of my working github actions file that is working for me, so someone else on here that wants it doesn't have to silently succumb to a year of annoying emails like I did. Evidence of that can be seen with successful run #343 - the first successful run.

dev followers count


Here's the good part you have been looking for.

YAML File:

name: Update DEV.to Followers Count

on:
  schedule:
    # Runs at midnight UTC daily
    - cron: '0 0 * * *'
  workflow_dispatch:

permissions:
  contents: write

jobs:
  update-count:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '22'

      - name: Run the update script
        env:
          DEVTO_API_KEY: ${{ secrets.DEVTO_API_KEY }}
          DEVTO_USERNAME: annavi11arrea1
        run: node update_script.js

      - name: Commit updated README
        run: |
          if git diff --quiet -- README.md; then
            echo "Follower count has not changed."
            exit 0
          fi
          git config user.name "github-actions[bot]"
          git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git add README.md
          git commit -m "Update DEV.to follower count"
          git push
Enter fullscreen mode Exit fullscreen mode

Notes:

  • Please remember to use environment variables in your code for API keys, don't hard code them into this! We want to keep our privilege to use DEV API for free. 🦋

  • You will need to specify where in your README.md to place the output. You will need appropriate tags. I did it like this:

Scroll so you see the whole thing, there is a start and end tag.

<!-- DEVTO-FOLLOWERS-COUNT:START -->**34996** DEV.to followers<!-- DEVTO-FOLLOWERS-COUNT:END -->
Enter fullscreen mode Exit fullscreen mode

I'm so psyched I got this working. I'm not here to brag about my followers, but we might all want to brag silently on our own profiles elsewhere. Haha.

Important changes made: make sure that I gave it write permissions, and also that the write is auto-pushed when the job runs. Key factors for a real update. Hmm, I wonder how else I might use Github actions for auto-updates?

Top comments (0)