diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..972e686 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,29 @@ +name: Scheduled Health Check + +on: + workflow_dispatch: + schedule: + - cron: "0 0 */5 * *" # each 5 days + +jobs: + health-check: + runs-on: ubuntu-latest + + env: + HEALTHCHECK_URL: ${{ secrets.HEALTHCHECK_URL }} + HEALTHCHECK_TOKEN: ${{ secrets.HEALTHCHECK_TOKEN }} + + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: "18" + + - name: Install Dependencies + run: yarn install --frozen-lockfile + + - name: Run Health Check + run: tsx scripts/check.ts diff --git a/scripts/check.ts b/scripts/check.ts new file mode 100644 index 0000000..0f749da --- /dev/null +++ b/scripts/check.ts @@ -0,0 +1,23 @@ +async function main() { + const url = process.env.HEALTHCHECK_URL; + + if (url == null) { + throw new Error("Healthcheck url is required"); + } + + const res = await fetch(url, { + headers: { + Authorization: process.env.HEALTHCHECK_TOKEN || "", + }, + }); + + if (!res.ok) { + throw new Error(`Request failed with status ${res.status}`); + } + + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const json = await res.json(); + console.log(json); +} + +main().catch(console.error);