From a5fd786d6421847aac2149846b6c97af179636d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Sun, 23 Jun 2024 20:01:18 -0500 Subject: [PATCH] feat: upgrade rating archivers to bun --- .github/workflows/cd-rating-asia.yml | 17 ++++------------- .github/workflows/cd-rating-eu.yml | 17 ++++------------- .github/workflows/cd-rating-latest.yml | 17 ++++------------- .github/workflows/cd-rating-na.yml | 17 ++++------------- package.json | 1 - src/core/blitzkit/patientFetchJSON.ts | 23 +++++++++++++++++++++++ 6 files changed, 39 insertions(+), 53 deletions(-) create mode 100644 src/core/blitzkit/patientFetchJSON.ts diff --git a/.github/workflows/cd-rating-asia.yml b/.github/workflows/cd-rating-asia.yml index f988da3b5..188642103 100644 --- a/.github/workflows/cd-rating-asia.yml +++ b/.github/workflows/cd-rating-asia.yml @@ -9,20 +9,11 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Use node - uses: actions/setup-node@v4 - with: - node-version: 18 - cache: 'npm' - - - name: Install Yarn - run: npm install --location=global yarn + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v1 - name: Install dependencies - run: yarn + run: bun install - name: Generate leaderboard - run: GH_TOKEN=${{ secrets.GH_TOKEN }} DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} DATABASE_URL=${{ secrets.DATABASE_URL }} yarn publish:ratingleaderboard --region=asia --target=midnight --production + run: GH_TOKEN=${{ secrets.GH_TOKEN }} DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} DATABASE_URL=${{ secrets.DATABASE_URL }} bun scripts/buildRatingLeaderboard.ts --region=asia --target=midnight --production diff --git a/.github/workflows/cd-rating-eu.yml b/.github/workflows/cd-rating-eu.yml index 30ed5f293..239b6ec3a 100644 --- a/.github/workflows/cd-rating-eu.yml +++ b/.github/workflows/cd-rating-eu.yml @@ -9,20 +9,11 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Use node - uses: actions/setup-node@v4 - with: - node-version: 18 - cache: 'npm' - - - name: Install Yarn - run: npm install --location=global yarn + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v1 - name: Install dependencies - run: yarn + run: bun install - name: Generate leaderboard - run: GH_TOKEN=${{ secrets.GH_TOKEN }} DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} DATABASE_URL=${{ secrets.DATABASE_URL }} yarn publish:ratingleaderboard --region=eu --target=midnight --production + run: GH_TOKEN=${{ secrets.GH_TOKEN }} DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} DATABASE_URL=${{ secrets.DATABASE_URL }} bun scripts/buildRatingLeaderboard.ts --region=eu --target=midnight --production diff --git a/.github/workflows/cd-rating-latest.yml b/.github/workflows/cd-rating-latest.yml index fe22d616f..25f811b2e 100644 --- a/.github/workflows/cd-rating-latest.yml +++ b/.github/workflows/cd-rating-latest.yml @@ -9,20 +9,11 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Use node - uses: actions/setup-node@v4 - with: - node-version: 18 - cache: 'npm' - - - name: Install Yarn - run: npm install --location=global yarn + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v1 - name: Install dependencies - run: yarn + run: bun install - name: Generate all leaderboards - run: GH_TOKEN=${{ secrets.GH_TOKEN }} DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} DATABASE_URL=${{ secrets.DATABASE_URL }} yarn publish:ratingleaderboard --region=na,asia,eu --target=latest --production + run: GH_TOKEN=${{ secrets.GH_TOKEN }} DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} DATABASE_URL=${{ secrets.DATABASE_URL }} bun scripts/buildRatingLeaderboard.ts --region=na,asia,eu --target=latest --production diff --git a/.github/workflows/cd-rating-na.yml b/.github/workflows/cd-rating-na.yml index a31cd48e5..a9541b6cc 100644 --- a/.github/workflows/cd-rating-na.yml +++ b/.github/workflows/cd-rating-na.yml @@ -9,20 +9,11 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Use node - uses: actions/setup-node@v4 - with: - node-version: 18 - cache: 'npm' - - - name: Install Yarn - run: npm install --location=global yarn + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v1 - name: Install dependencies - run: yarn + run: bun install - name: Generate leaderboard - run: GH_TOKEN=${{ secrets.GH_TOKEN }} DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} DATABASE_URL=${{ secrets.DATABASE_URL }} yarn publish:ratingleaderboard --region=na --target=midnight --production + run: GH_TOKEN=${{ secrets.GH_TOKEN }} DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} DATABASE_URL=${{ secrets.DATABASE_URL }} bun scripts/buildRatingLeaderboard.ts --region=na --target=midnight --production diff --git a/package.json b/package.json index 4648093d8..3918f9a48 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,6 @@ "start:bot": "node --enable-source-maps dist/bot/index.cjs", "start:website": "next start", "host:docs": "vitepress preview docs", - "publish:ratingleaderboard": "vite-node --script scripts/buildRatingLeaderboard --publish", "lint": "npx tsc", "lint:website": "next lint", "format": "prettier --write \"**/*.@(json|js|jsx|css|md|ts|tsx|html|xml|yml|gltf)\"", diff --git a/src/core/blitzkit/patientFetchJSON.ts b/src/core/blitzkit/patientFetchJSON.ts new file mode 100644 index 000000000..de3a31105 --- /dev/null +++ b/src/core/blitzkit/patientFetchJSON.ts @@ -0,0 +1,23 @@ +export async function patientFetchJSON( + url: string, + timeout = 1000, + options?: Partial<{ cache: 'no-store' }>, +) { + let patientJSON: Type; + + while (patientJSON! === undefined) { + try { + patientJSON = (await fetch(url, options).then((response) => + response.json(), + )) as Type; + } catch (error) { + console.warn( + `Failed to fetch ${url} as JSON; retrying in ${timeout}ms...`, + error, + ); + await new Promise((resolve) => setTimeout(resolve, timeout)); + } + } + + return patientJSON; +}