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

    - cron: '0 0 * * *'

  API_KEY: ${{ secrets.WEATHER_API_KEY }}

    runs-on: ubuntu-latest

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

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

    - name: Install dependencies
      run: npm ci

    - name: Get current date and weather
      run: |
        date=$(date +"%B %d, %Y")
        weather=$(curl " 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
        script: |
          git config --local ""
          git config --local "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.

Top comments (0)