name: Update third party assets

on:
  schedule: [{cron: "0 4 * * *"}]
  workflow_dispatch:

jobs:
  push_to_branch_and_create_pr:
    name: Create PR for 3rd party assets
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        name: Check out current commit
          
      - name: Download pyscript.js
        run: curl https://pyscript.net/alpha/pyscript.js -o assets/pyscript.js
          
      - name: Download pyscript.py
        run: curl https://pyscript.net/alpha/pyscript.py -o assets/pyscript.py
          
      - name: Download pyscript.css
        run: curl https://pyscript.net/alpha/pyscript.css -o assets/pyscript.css
        
      - name: Download d3.v7.min.js
        run: curl https://d3js.org/d3.v7.min.js -o assets/d3.v7.min.js
        
      - name: Download chart.js
        run: curl https://cdn.jsdelivr.net/npm/chart.js -o assets/chart.js
          
      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v4.0.4
        with:
          commit-message: Update 3rd party assets
          title: Update 3rd party assets
          body: |
            This is an automated PR.
            <sub>[workflow](https://github.com/marvinscham/pa-pyscript/blob/main/.github/workflows/asset-updater.yml).</sub>
          branch: update-assets
