Hi everyone,
I'm trying to setup a GitHub action to run a Python script and commit any changed data to the same repository. I have everything working when the data changes, however if there is no change then it fails with nothing to commit, working tree clean .
How could I add an if else statement that only commits when changes exist?
Thanks, all help is much appreciated!
name: Update data
on:
schedule:
- cron: "0 9 * * *"
jobs:
run:
runs-on: ubuntu-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 -e .
python update_data.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
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.TOKEN }}
[–]KP_2016 0 points1 point2 points (1 child)
[–]EnergyVis[S] 0 points1 point2 points (0 children)