From 9922d0c495f457ddb58798994d9a1ee4f1b14a1e Mon Sep 17 00:00:00 2001 From: Chris Wilkinson Date: Thu, 8 Aug 2024 16:26:43 +0100 Subject: [PATCH] Allow builds in environments where secrets aren't available Refs 5888b0c0ee9a0ca57148c8101e162b1b6b385db4 --- .github/workflows/ci.yml | 3 +-- src/data/clubs.json.ts | 6 ++++++ src/data/reviews.json.ts | 6 ++++++ src/data/users.json.ts | 6 ++++++ src/data/visitors-by-country.json.ts | 6 ++++++ src/data/visitors-by-referrer.json.ts | 6 ++++++ 6 files changed, 31 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 387cb30..90772b6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,6 @@ jobs: name: 'Build dist' runs-on: ubuntu-22.04 timeout-minutes: 30 - if: github.ref == 'refs/heads/main' steps: - name: 'Checkout code' @@ -53,6 +52,7 @@ jobs: env: PREREVIEW_REVIEWS_DATA_TOKEN: ${{ secrets.PREREVIEW_REVIEWS_DATA_TOKEN }} FATHOM_TOKEN: ${{ secrets.FATHOM_TOKEN }} + SANDBOX: ${{ github.ref != 'refs/heads/main' }} - name: 'Upload build' uses: actions/upload-artifact@v4.3.6 @@ -64,7 +64,6 @@ jobs: name: 'Build image' runs-on: ubuntu-22.04 timeout-minutes: 30 - if: github.ref == 'refs/heads/main' && !failure() && !cancelled() outputs: image: ${{ steps.build.outputs.imageid }} needs: diff --git a/src/data/clubs.json.ts b/src/data/clubs.json.ts index 5b2deb3..77f4de8 100644 --- a/src/data/clubs.json.ts +++ b/src/data/clubs.json.ts @@ -14,6 +14,12 @@ const Output = Schema.Record({ key: Schema.String, value: Schema.String }) const program = Effect.gen(function* () { const terminal = yield* Terminal.Terminal + const sandbox = yield* Config.withDefault(Config.boolean('SANDBOX'), false) + + if (sandbox) { + return yield* terminal.display('[]') + } + const token = yield* Config.redacted('PREREVIEW_REVIEWS_DATA_TOKEN') const request = HttpClientRequest.bearerToken( diff --git a/src/data/reviews.json.ts b/src/data/reviews.json.ts index 74d81a6..1cb48cf 100644 --- a/src/data/reviews.json.ts +++ b/src/data/reviews.json.ts @@ -126,6 +126,12 @@ const getLegacyReviews = Effect.gen(function* () { }) const getReviews = Effect.gen(function* () { + const sandbox = yield* Config.withDefault(Config.boolean('SANDBOX'), false) + + if (sandbox) { + return [] + } + const token = yield* Config.redacted('PREREVIEW_REVIEWS_DATA_TOKEN') const request = HttpClientRequest.bearerToken( diff --git a/src/data/users.json.ts b/src/data/users.json.ts index 77d3d1c..421bfc7 100644 --- a/src/data/users.json.ts +++ b/src/data/users.json.ts @@ -24,6 +24,12 @@ const Output = Schema.Array( const program = Effect.gen(function* () { const terminal = yield* Terminal.Terminal + const sandbox = yield* Config.withDefault(Config.boolean('SANDBOX'), false) + + if (sandbox) { + return yield* terminal.display('[]') + } + const token = yield* Config.redacted('PREREVIEW_REVIEWS_DATA_TOKEN') const request = HttpClientRequest.bearerToken( diff --git a/src/data/visitors-by-country.json.ts b/src/data/visitors-by-country.json.ts index 2a6df38..6d08591 100644 --- a/src/data/visitors-by-country.json.ts +++ b/src/data/visitors-by-country.json.ts @@ -23,6 +23,12 @@ const Output = Schema.Array( const program = Effect.gen(function* () { const terminal = yield* Terminal.Terminal + const sandbox = yield* Config.withDefault(Config.boolean('SANDBOX'), false) + + if (sandbox) { + return yield* terminal.display('[]') + } + const token = yield* Config.redacted('FATHOM_TOKEN') const request = HttpClientRequest.bearerToken( diff --git a/src/data/visitors-by-referrer.json.ts b/src/data/visitors-by-referrer.json.ts index 5cf57d2..d06945b 100644 --- a/src/data/visitors-by-referrer.json.ts +++ b/src/data/visitors-by-referrer.json.ts @@ -23,6 +23,12 @@ const Output = Schema.Array( const program = Effect.gen(function* () { const terminal = yield* Terminal.Terminal + const sandbox = yield* Config.withDefault(Config.boolean('SANDBOX'), false) + + if (sandbox) { + return yield* terminal.display('[]') + } + const token = yield* Config.redacted('FATHOM_TOKEN') const request = HttpClientRequest.bearerToken(