Merge pull request #15 from caesarw0/update_github_action_change_diff… #11
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Daily CSV Update | |
on: push | |
#schedule: | |
# - cron: '0 0 * * *' # Runs every day at midnight (UTC) | |
jobs: | |
update-csv: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v2 | |
- name: Download New CSV | |
run: | | |
if curl -o data/new-data.csv https://catalogue.data.gov.bc.ca/dataset/4cc207cc-ff03-44f8-8c5f-415af5224646/resource/9a9f14e1-03ea-4a11-936a-6e77b15eeb39/download/childcare_locations.csv; then | |
echo "CSV download successful." | |
else | |
echo "CSV download failed." | |
exit 1 | |
fi | |
- name: Check CSV File Size | |
id: check-csv | |
run: | | |
if [ -s data/new-data.csv ]; then | |
echo "CSV file is not empty." | |
else | |
echo "CSV file is empty." | |
exit 78 | |
fi | |
- name: Check for Differences | |
id: check-differences | |
run: | | |
if ! diff -q data/new-data.csv data/childcare_locations.csv; then | |
echo "CSV files are different." | |
echo "DIFFERENT_CSV=true" >> $GITHUB_ENV | |
else | |
echo "CSV files are the same. Skipping commit." | |
echo "DIFFERENT_CSV=false" >> $GITHUB_ENV | |
fi | |
- name: Overwrite CSV | |
if: steps.check-csv.outcome == 'success' && env.DIFFERENT_CSV == 'true' | |
run: | | |
mv data/new-data.csv data/childcare_locations.csv | |
- name: Commit and Push Changes | |
if: steps.check-csv.outcome == 'success' && env.DIFFERENT_CSV == 'true' | |
run: | | |
git config --global user.name "GitHub Actions" | |
git config --global user.email "actions@github.com" | |
git add data/childcare_locations.csv | |
git commit -am "Update CSV file" | |
git push | |