From 622cd92a13725b1af9c468c9f9c1395da1492e18 Mon Sep 17 00:00:00 2001 From: tresabhi Date: Fri, 14 Jul 2023 01:52:05 +0000 Subject: [PATCH] feat: added cron job --- .github/workflows/{host.yml => cd-host.yml} | 2 +- .../workflows/cd-ratings-leaderboard-na.yml | 21 +++++++++++++++++++ .github/workflows/ci-build.yml | 2 +- scripts/generateRatingsLeaderboard.js | 12 +++++++++-- 4 files changed, 33 insertions(+), 4 deletions(-) rename .github/workflows/{host.yml => cd-host.yml} (98%) create mode 100644 .github/workflows/cd-ratings-leaderboard-na.yml diff --git a/.github/workflows/host.yml b/.github/workflows/cd-host.yml similarity index 98% rename from .github/workflows/host.yml rename to .github/workflows/cd-host.yml index 2ff7cc2b1..8ed9ceb7b 100644 --- a/.github/workflows/host.yml +++ b/.github/workflows/cd-host.yml @@ -1,4 +1,4 @@ -name: Host +name: CD Host on: schedule: diff --git a/.github/workflows/cd-ratings-leaderboard-na.yml b/.github/workflows/cd-ratings-leaderboard-na.yml new file mode 100644 index 000000000..01d668990 --- /dev/null +++ b/.github/workflows/cd-ratings-leaderboard-na.yml @@ -0,0 +1,21 @@ +name: CD Ratings Leaderboard North America + +on: + schedule: + - cron: '0 5 * * *' + +jobs: + host: + runs-on: ubuntu-latest + + steps: + - name: Get code + uses: actions/checkout@v3 + + - name: Use node + uses: actions/setup-node@v3 + with: + node-version: 18 + + - name: Generate leaderboard + run: GH_TOKEN=${{ secrets.GH_TOKEN }} yarn publish:ratingsleaderboard --region=asia diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index df3789d87..156d57820 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -16,7 +16,7 @@ jobs: node-version: [18.x] steps: - - name: Get code + - name: Checkout uses: actions/checkout@v3 - name: Use node diff --git a/scripts/generateRatingsLeaderboard.js b/scripts/generateRatingsLeaderboard.js index 488be99d2..e1d4c59c1 100644 --- a/scripts/generateRatingsLeaderboard.js +++ b/scripts/generateRatingsLeaderboard.js @@ -3,8 +3,16 @@ import { rm, writeFile } from 'fs/promises'; import { argv, env } from 'process'; import commitMultipleFiles from './commitMultipleFiles.js'; +/* +For Central North American Time (UTC-5), use 0 5 * * *. +For Central European Time (UTC+1), use 0 23 * * *. +For Central Asia Standard Time (UTC+7), use 0 17 * * *. +*/ + const publish = argv.includes('--publish'); -const server = 'na'; +const server = argv.find((arg) => arg.startsWith('--region='))?.split('=')[1]; + +if (!server) throw new Error('Region parameter not specified'); const NEIGHBORS = 1000; const PLAYERS = await fetch( @@ -80,7 +88,7 @@ for (let index = 0; index < PLAYERS; index++) { const leaderboardJSON = JSON.stringify(leaderboard); if (publish) { - const octokit = new Octokit({ auth: env.GITHUB_TOKEN }); + const octokit = new Octokit({ auth: env.GH_TOKEN }); const info = await fetch( `https://${server}.wotblitz.com/en/api/rating-leaderboards/season/`,