DEV Community

Cover image for Github action that generate chat SVG with current date and weather
Tarik Manoar
Tarik Manoar

Posted on

Github action that generate chat SVG with current date and weather

name: Generate chat bubble SVG

on:
  schedule:
    - cron: '0 0 * * *'

env:
  API_KEY: ${{ secrets.WEATHER_API_KEY }}

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout repository
      uses: actions/checkout@v2

    - name: Set up Node.js
      uses: actions/setup-node@v2
      with:
        node-version: 14

    - name: Install dependencies
      run: npm ci

    - name: Get current date and weather
      run: |
        date=$(date +"%B %d, %Y")
        weather=$(curl "http://api.openweathermap.org/data/2.5/weather?q=San Francisco,us&appid=${API_KEY}&units=imperial" | jq '.main.temp')
        echo "::set-env name=DATE::$date"
        echo "::set-env name=WEATHER::$weather°F"

    - name: Generate chat bubble SVG
      run: node generate-svg.js "$DATE" "$WEATHER"

    - name: Commit and push changes
      uses: actions/github-script@0.11.0
      with:
        script: |
          git config --local user.email "github-actions@example.com"
          git config --local user.name "GitHub Actions"
          git add chat-bubble.svg
          git commit -m "Update chat bubble with current date and weather"
          git push

Enter fullscreen mode Exit fullscreen mode

In this example, the Action runs on a schedule (daily at midnight) and uses a weather API to retrieve the current temperature in San Francisco. The date and weather information are then passed to a JavaScript script that generates an SVG file, which is committed and pushed back to the repository.

Note that you'll need to replace WEATHER_API_KEY with your own API key from the OpenWeatherMap API, and you may need to modify the curl command to retrieve weather information for your desired location.

Oldest comments (0)