runTasks (daily) #420
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: runTasks (daily) | |
| on: | |
| schedule: | |
| - cron: "0 18 * * *" # Scheduled to run daily at 6:00AM NZT | |
| workflow_dispatch: # Allows manual triggering of the workflow | |
| jobs: | |
| run-tasks: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Checkout the repository | |
| - name: Checkout repository | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: "0" | |
| # pulls all commits | |
| # Set up Node.js | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 22 # Use the Node.js version your app requires | |
| cache: 'npm' | |
| # Install dependencies | |
| - name: Install dependencies | |
| run: npm install | |
| # Install Playwright browsers | |
| # Revert if needed to: | |
| # npx playwright install --with-deps chromium | |
| - name: Install Playwright browsers | |
| run: npx playwright install --with-deps --no-shell | |
| # Run the tasks | |
| - name: Run checker tasks | |
| env: | |
| RESEND_API_KEY: ${{ secrets.RESEND_API_KEY }} | |
| DATABASE_HOST: ${{ secrets.DATABASE_HOST }} | |
| DATABASE_NAME: ${{ secrets.DATABASE_NAME }} | |
| DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }} | |
| DATABASE_USER: ${{ secrets.DATABASE_USER }} | |
| DATABASE_URL: ${{ secrets.DATABASE_URL }} | |
| PGHOST: ${{ secrets.PGHOST }} | |
| PGUSER: ${{ secrets.PGUSER }} | |
| PGPASSWORD: ${{ secrets.PGPASSWORD }} | |
| PGDATABASE: ${{ secrets.PGDATABASE }} | |
| DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} | |
| DISCORD_WEBHOOK_VERSIONCHECKER: ${{ secrets.DISCORD_WEBHOOK_VERSIONCHECKER }} | |
| DISCORD_WEBHOOK_NOTIFYUSERS: ${{ secrets.DISCORD_WEBHOOK_NOTIFYUSERS }} | |
| DISCORD_WEBHOOK_MOBOFETCHER: ${{ secrets.DISCORD_WEBHOOK_MOBOFETCHER }} | |
| DISCORD_WEBHOOK_STATSCHARTS: ${{ secrets.DISCORD_WEBHOOK_STATSCHARTS }} | |
| run: node public/js/runTasks.js | |
| # Commit and push changes to models.json (if modified) | |
| - name: Commit and push changes | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| # Check for changes in the working directory and staging area | |
| if git diff --quiet public/data/models.json && git diff --cached --quiet public/data/models.json; then | |
| echo "No changes to models.json. Skipping commit and push." | |
| else | |
| git add public/data/models.json | |
| git commit -m "Update models.json via daily workflow" | |
| # Stash any remaining unstaged changes before rebasing (prevents the error) | |
| git stash --include-untracked | |
| # Fetch latest changes and rebase safely | |
| git fetch origin main | |
| git rebase origin/main || (git rebase --abort && echo "Rebase failed, skipping rebase") | |
| # Apply stashed changes back (if there were any) | |
| git stash pop || echo "No stash to apply" | |
| git push | |
| fi | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # Optional: Notify on workflow success | |
| - name: Notify success | |
| if: success() | |
| run: echo "Scheduled tasks ran successfully!" | |
| # Optional: Notify on workflow failure | |
| - name: Notify failure | |
| if: failure() | |
| run: echo "Scheduled tasks failed to complete." |