Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get environment variables when prebuilding by Github worflow #1843

Open
ieiekk opened this issue Oct 3, 2023 · 5 comments
Open

Can't get environment variables when prebuilding by Github worflow #1843

ieiekk opened this issue Oct 3, 2023 · 5 comments

Comments

@ieiekk
Copy link

ieiekk commented Oct 3, 2023

This is what I wrote in utils.ts:

export const supabase = createClient<Database>(
  Deno.env.get("SUPABASE_URL") as string,
  Deno.env.get("SUPABASE_KEY") as string,
);

After I push the commit, I got this error message on GIthub workflow page:

Build step >
Run deno task build
Task build deno run -A dev.ts build
.
.
.
.
error: Uncaught (in promise) Error: supabaseUrl is required.
    at new p (https://esm.sh/v132/@supabase/supabase-js@2.4.0/esnext/supabase-js.mjs:2:2168)
    at nt (https://esm.sh/v132/@supabase/supabase-js@2.4.0/esnext/supabase-js.mjs:2:5286)
    at file:///home/runner/work/a-pp-greeting-cards-platform/a-pp-greeting-cards-platform/utils/utils.ts:20:25
Error: Process completed with exit code 1.

And I've setup the env var on deno deploy dashboard and this works on local .env file.

@martinrempel
Copy link
Contributor

Did you set up variables or secrets?

@marvinhagemeister
Copy link
Collaborator

@ieiekk Do you happen to use a setup with a fresh.config.ts or without one? Asking because before we introduced fresh.config.ts the dev.ts would always load main.ts which in turn imports every file of the application. In doing so it will encounter the supabase call and complain that the environment variables are not set. That's the main reason we introduced the fresh.config.ts which allows us to properly split the development mode internally so that you can create a build without loading main.ts

@ieiekk
Copy link
Author

ieiekk commented Oct 4, 2023

Did you set up variables or secrets?

This works! I add SUPABASE_URL and SUPABASE_KEY as secrets:

Screenshot 2023-10-04 at 11 40 42 PM

And add these lines in my deploy.yml:

name: Deploy
on:
  push:
    branches: [master, develope]
  pull_request:
    branches: master

jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest

    permissions:
      id-token: write
      contents: read

    steps:
      - name: Clone repository
        uses: actions/checkout@v3

      - name: Install Deno
        uses: denoland/setup-deno@v1
        with:
          deno-version: v1.x

      - name: Build step
+        env: 
+            SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
+            SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
        run: "deno task build"

      - name: Upload to Deno Deploy
        uses: denoland/deployctl@v1
        with:
          project: "pp-greeting-cards-platform"
          entrypoint: "./main.ts"

Hope this helps anyone encountered the same issue.

@ieiekk
Copy link
Author

ieiekk commented Oct 4, 2023

@ieiekk Do you happen to use a setup with a fresh.config.ts or without one? Asking because before we introduced fresh.config.ts the dev.ts would always load main.ts which in turn imports every file of the application. In doing so it will encounter the supabase call and complain that the environment variables are not set. That's the main reason we introduced the fresh.config.ts which allows us to properly split the development mode internally so that you can create a build without loading main.ts

I leave that file as default:

import { defineConfig } from "$fresh/server.ts";
import twindPlugin from "$fresh/plugins/twind.ts";
import twindConfig from "./twind.config.ts";
export default defineConfig({
  plugins: [twindPlugin(twindConfig)],
});

So is there a way to avoid import some files during build time? Thanks in advance 🙏

JackAida added a commit to JackAida/traffic-planner-dev that referenced this issue May 18, 2024
Added
    env: 
      PUBLIC_SUPABASE_URL: ${{ secrets.PUBLIC_SUPABASE_URL }}
      PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.PUBLIC_SUPABASE_ANON_KEY }}

As per denoland/fresh#1843
@avalero
Copy link

avalero commented Jul 8, 2024

Same here, no way to make the build step in github actions without env variables. That is somehow unexpected as they are server side variables @marvinhagemeister

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants