adding branch & merge #13
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 1 | |
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: | | |
timestamp=$(date +'%Y%m%d%H%M%S') | |
branch_name="update-csv-$timestamp" | |
git checkout -b "$branch_name" | |
git add data/childcare_locations.csv | |
git commit -m "Update CSV file" | |
git push origin "$branch_name" | |
git checkout main | |
git merge --no-ff "$branch_name" | |
git push origin main | |
# delete the temporary branch | |
git branch -d "$branch_name" | |
git push origin --delete "$branch_name" |