Sync JSON Data #30
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: Sync JSON Data | |
on: | |
schedule: | |
- cron: '0 17 * * *' # Run at midnight UTC+7 daily | |
workflow_dispatch: # Allows manual trigger | |
permissions: | |
contents: write | |
jobs: | |
sync-json: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout 🛎 | |
uses: actions/checkout@v4 | |
- name: Fetch current law.json 🧾 | |
run: cp data/law.json old_law.json | |
- name: Fetch new data 🏃🏻♂️ | |
run: | | |
curl -L -s "https://script.google.com/macros/s/${{ secrets.KEY_APP_SCRIPT }}/exec?action=getData" -o data/law.json | |
- name: Check for changes 📊 | |
id: check_changes | |
run: | | |
if diff -q data/law.json old_law.json > /dev/null; then | |
echo "No changes detected, exiting." | |
echo "changes_detected=false" >> $GITHUB_ENV | |
else | |
echo "Changes detected." | |
echo "changes_detected=true" >> $GITHUB_ENV | |
fi | |
- name: Remove old_law.json to prevent untracked file error 🧹 | |
run: rm old_law.json | |
- name: Commit and Push Changes | |
if: env.changes_detected == 'true' # Only run if changes were detected | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add data/law.json | |
git commit -m "Sync JSON data from Google Apps Script" | |
git push origin main | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |