Tommerty
Updated on 24th Aug, 2024
And using them to update your GitHub profile can be confusing if you're just getting started. I for one didn't have much experience with using GitHub actions, but thought it would be a cool idea to have a banner image appear when I went live, so I cooked something up!
Head over to your GitHub profile README. This is usually a repo with just your username, for example mine is github.com/tommerty/tommerty
You'll want to have an image created. You shouldn't, but I just uploaded my image to my repository inside a folder called assets. Wherever you upload the image (even on your Doras profile), just take note of the image URL, we'll need that later.
Let's create the workflow file. You can see mine here. In case I've made modifications to mine between right now and you seeing this post, this is it:
name: Twitch Live Status
env:
TWITCH_USERNAME: tommertyboi
LIVE_BANNER_IMAGE: /assets/livebanner.png
GITHUB_USERNAME: Tommerty
GITHUB_EMAIL: tommerty@github.com
on:
schedule:
- cron: '*/10 * * * *' # Runs every 10 minutes
workflow_dispatch:
jobs:
update-readme:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4.1.6
- name: Check Twitch live status
id: twitch-status
run: |
live_status=$(curl -s https://api.doras.to/links/twitch/${{ env.TWITCH_USERNAME }} | jq -r '.live')
echo "live_status=$live_status" >> $GITHUB_OUTPUT
- name: Update README
env:
LIVE_STATUS: ${{ steps.twitch-status.outputs.live_status }}
run: |
echo "Live Status: $LIVE_STATUS"
if [ "$LIVE_STATUS" == "true" ]; then
sed -i "1s|^|[![Twitch Live Banner](${{ env.LIVE_BANNER_IMAGE }})](https:\/\/www.twitch.tv\/${{ env.TWITCH_USERNAME }})\n|" README.md
else
sed -i "/\[!\[Twitch Live Banner\](${{ env.LIVE_BANNER_IMAGE }})\](https:\/\/www\.twitch\.tv\/${{ env.TWITCH_USERNAME }})/d" README.md
echo "Removed Twitch Live Banner"
fi
- name: Check for changes
id: check_changes
run: |
git diff README.md
if [ -n "$(git status --porcelain README.md)" ]; then
echo "changes_detected=true" >> $GITHUB_OUTPUT
else
echo "changes_detected=false" >> $GITHUB_OUTPUT
fi
- name: Commit changes
if: steps.check_changes.outputs.changes_detected == 'true'
run: |
git config --global user.email "${{ env.GITHUB_EMAIL }}"
git config --global user.name "${{ env.GITHUB_USERNAME }}"
git add README.md
git commit -m "Update Twitch Live Banner in README"
git push
Inside the ENV section, make adjustments to these to reflect your content:
env:
TWITCH_USERNAME: TWITCHUSERNAME
LIVE_BANNER_IMAGE: https://URL_TO_YOUR_IMAGE.jpg
GITHUB_EMAIL: GIT EMAIL
GITHUB_USERNAME: GIT USERNAME
Now your action will run and ping the API endpoint to check if your channel is live or not! To avoid rate limiting, we suggest 5 minutes being the shortest time for the cron. We may impose limits if it's being absolutely hammered.