Skip to content

Update Contributions #218

Update Contributions

Update Contributions #218

name: Update Contributions
on:
schedule:
# Monthly full sync at 00:01 UTC on the 1st of the month
- cron: '1 0 1 * *'
# Daily update at 01:00 UTC
- cron: '0 1 * * *'
workflow_dispatch:
jobs:
run_scheduled_update:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# Fetch full history to properly determine the last update date.
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm' # Automatically handles node_modules caching
- name: Install dependencies
run: npm ci # Uses package-lock.json for exact versions
- name: Conditionally run full sync or daily update
run: |
echo "github.event.schedule is ${{ github.event.schedule }}"
# Check if the triggering schedule is the monthly cron
if [ "${{ github.event.schedule }}" = "1 0 1 * *" ]; then
echo "Running monthly full sync..."
# Force the script to do a full run by deleting the cache files
rm -f data/all-contributions.json
rm -f data/commit-cache.json
rm -f data/pr-cache.json
node scripts/src/main.js
else
echo "Running daily update..."
# Run the script incrementally, relying on existing data files
node scripts/src/main.js
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Format generated files
run: npm run format
- name: Commit and push changes
id: commit
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Add the generated files to the staging area
git add contributions/markdown-generated/ contributions/html-generated/ data/
# Check if there are any changes to commit
if ! git diff --staged --quiet; then
# Use a different commit message based on the update type
if [ "${{ github.event.schedule }}" = "1 0 1 * *" ]; then
git commit -m "docs: Monthly full sync [skip ci]"
else
git commit -m "docs: Daily contributions update [skip ci]"
fi
git push
# Signal that a push occurred
echo "pushed=true" >> $GITHUB_OUTPUT
else
echo "No changes to commit"
# Signal no push occurred
echo "pushed=false" >> $GITHUB_OUTPUT
fi
# Triggers the Netlify build only if new content was committed and pushed
- name: Trigger Netlify Deployment
# Check the output from the previous step
if: steps.commit.outputs.pushed == 'true'
run: |
echo "Content updated. Triggering Netlify deployment via Build Hook..."
curl -s -X POST -d {} ${NETLIFY_BUILD_HOOK} -o /dev/null
env:
# Reference the Build Hook URL secret
NETLIFY_BUILD_HOOK: ${{ secrets.NETLIFY_BUILD_HOOK }}