Skip to content

Rebuild Check

Rebuild Check #219

Workflow file for this run

name: Rebuild Check
on:
schedule:
# Run daily at midnight JST (3pm UTC)
- cron: "0 15 * * *"
workflow_dispatch:
jobs:
check-and-trigger:
name: Check for updates and trigger build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check for content updates or event end
id: check-updates
run: |
UPSTREAM_REPO="oktechjp/public"
# Read current values from meta.json
CURRENT_COMMIT=$(jq -r '.commitHash' meta.json)
CURRENT_CONTENT_HASH=$(jq -r '.contentHash // ""' meta.json)
NEXT_EVENT_ENDS=$(jq -r '.nextEventEnds' meta.json)
echo "Current commit: $CURRENT_COMMIT"
echo "Current content hash: $CURRENT_CONTENT_HASH"
echo "Next event ends: $NEXT_EVENT_ENDS"
# Get latest commit from upstream main branch
LATEST_COMMIT=$(curl -s "https://api.github.com/repos/$UPSTREAM_REPO/commits/main" | jq -r '.sha')
echo "Latest upstream commit: $LATEST_COMMIT"
# Initialize NEEDS_BUILD flag
NEEDS_BUILD=false
# First check if an event has ended (this always needs checking)
if [ "$NEXT_EVENT_ENDS" != "null" ] && [ "$NEXT_EVENT_ENDS" != "" ]; then
CURRENT_TIME=$(date -u +"%Y-%m-%dT%H:%M:%S.000Z")
if [[ "$CURRENT_TIME" > "$NEXT_EVENT_ENDS" ]]; then
echo "Event has ended, triggering rebuild to update event status"
NEEDS_BUILD=true
fi
fi
# Early exit if commits are the same and no event ended
if [ "$CURRENT_COMMIT" = "$LATEST_COMMIT" ] && [ "$NEEDS_BUILD" = false ]; then
echo "Commits are identical and no event has ended. No updates needed."
echo "NEEDS_BUILD=false" >> $GITHUB_ENV
exit 0
fi
# Only fetch content if commits are different
if [ "$CURRENT_COMMIT" != "$LATEST_COMMIT" ]; then
echo "Commit has changed, fetching content to check for actual changes..."
# Fetch and hash the content from latest commit
EVENTS_URL="https://raw.githubusercontent.com/$UPSTREAM_REPO/$LATEST_COMMIT/events.json"
PHOTOS_URL="https://raw.githubusercontent.com/$UPSTREAM_REPO/$LATEST_COMMIT/photos.json"
echo "Fetching events.json and photos.json from latest commit..."
# Download both files and compute combined hash
EVENTS_CONTENT=$(curl -sL "$EVENTS_URL")
PHOTOS_CONTENT=$(curl -sL "$PHOTOS_URL")
# Compute hash of combined content
COMBINED_CONTENT="${EVENTS_CONTENT}${PHOTOS_CONTENT}"
NEW_CONTENT_HASH=$(echo -n "$COMBINED_CONTENT" | sha256sum | cut -d' ' -f1)
echo "New content hash: $NEW_CONTENT_HASH"
# Check for content changes (via hash)
if [ "$CURRENT_CONTENT_HASH" != "$NEW_CONTENT_HASH" ]; then
echo "Content has changed (hash mismatch)!"
NEEDS_BUILD=true
else
echo "Commit changed but content is identical (hash match)"
fi
fi
echo "NEEDS_BUILD=$NEEDS_BUILD" >> $GITHUB_ENV
- name: Trigger import workflow
if: env.NEEDS_BUILD == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'import.yml',
ref: 'main'
})
console.log('Import workflow triggered successfully')