Rebuild Check #20
This file contains hidden or 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 Rebuild Check | |
| on: | |
| schedule: | |
| # Run daily at midnight JST (3pm UTC) | |
| - cron: "0 15 * * *" | |
| workflow_dispatch: | |
| jobs: | |
| check-for-updates: | |
| name: Check for content updates | |
| runs-on: ubuntu-latest | |
| outputs: | |
| has-updates: ${{ steps.check-updates.outputs.has-updates }} | |
| new-commit: ${{ steps.check-updates.outputs.new-commit }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Check for new upstream commit or event end | |
| id: check-updates | |
| run: | | |
| UPSTREAM_REPO="oktechjp/public" | |
| # Read current commit from meta.json | |
| CURRENT_COMMIT=$(jq -r '.commitHash' content/meta.json) | |
| echo "Current commit: $CURRENT_COMMIT" | |
| # Read nextEventEnds from meta.json | |
| NEXT_EVENT_ENDS=$(jq -r '.nextEventEnds' content/meta.json) | |
| 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" | |
| # Check if we need to trigger a build | |
| NEEDS_BUILD=false | |
| # Check for new commit | |
| if [ "$CURRENT_COMMIT" != "$LATEST_COMMIT" ]; then | |
| echo "New commit detected!" | |
| NEEDS_BUILD=true | |
| echo "new-commit=$LATEST_COMMIT" >> $GITHUB_OUTPUT | |
| fi | |
| # Check if an event has ended and we need to rebuild | |
| 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 | |
| if [ "$NEEDS_BUILD" = true ]; then | |
| echo "has-updates=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "No updates needed" | |
| echo "has-updates=false" >> $GITHUB_OUTPUT | |
| fi | |
| trigger-build: | |
| name: Trigger build | |
| needs: check-for-updates | |
| if: needs.check-for-updates.outputs.has-updates == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Trigger builder workflow | |
| 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: 'astro.yml', | |
| ref: 'main' | |
| }) |