How to make a workflow file to save the output as a file to my GitHub Repo?

For past 3 days I have been learning about matplotlib and pandas from youtube and I tried to implement my knowledge by making a very basic python project,which analyzes data from an api hosted by the Govt of India containing the data of COVID-19 cases in different states of India.

My project is almost complete and is working fine in my local machine and I have hosted it to github pages as well.

The problem is that I wrote a python script to convert jupyter notebook to static index.html in the root folder and it works fine on my local machine.Basically my jupyter notebook takes data from the API source and analyzes it to display useful information,but GitHub pages cannot host jupyter notebooks so the script converts notebook to index.html file and saves it directly to root directory (Idea is to make index.html serve as the home page for GitHub pages) but when I made a workflow file to serve the purpose and when it executed something unexpected happened.

Below is My Workflow file run.yml located in .github/workflows/run.yml

name: Update index.html

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

jobs:
  run:
    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python
      uses: actions/setup-python@v1
      with:
        python-version: '3.x'
    - name: Install dependencies
      run: |
        dir
        python -m pip install --upgrade pip
        pip install -r requirements.txt
        python update.py
        dir

NOTE: I have Used dir commands to see where the index.html file is getting stored.

Output of first dir command

Output of second dir command

Seems like my script (update.py) is working fine but instead of saving index.html to the root directory of my Github Repo it is saving it somewhere else. I need help to make changes in my code to make index.html file to be saved on my GitHub repo as it will serve as the home page for my Github Pages.

GitHub Repo Link

Hi @piyushke , 

Based on my understanding of your requirement, you want to push the index.html which created/changed during the workflow execution to your GitHub Repo. 

You could add some steps to commit changes and push back to current repo. There is my example workflow yml:

name: Update index.html

on: push

jobs:
  run:
    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python
      uses: actions/setup-python@v1
      with:
        python-version: '3.x'
    - name: Install dependencies
      run: |
        dir
        python -m pip install --upgrade pip
        pip install -r requirements.txt
        python update.py
        dir

    - name: Commit files
      id: commit
      run: |
        git config --local user.email "action@github.com"
        git config --local user.name "github-actions"
        git add --all
        if [-z "$(git status --porcelain)"]; then
           echo "::set-output name=push::false"
        else
           git commit -m "Add changes" -a
           echo "::set-output name=push::true"
        fi
      shell: bash
    - name: Push changes
      if: steps.commit.outputs.push == 'true'
      uses: ad-m/github-push-action@master
      with:
         github_token: ${{ secrets.GITHUB_TOKEN }}

 If I misunderstood your scenario, please feel free to point me out. 

1 Like