fresh
fresh copied to clipboard
Can't get environment variables when prebuilding by Github worflow
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/[email protected]/esnext/supabase-js.mjs:2:2168)
at nt (https://esm.sh/v132/@supabase/[email protected]/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.
@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
This works! I add SUPABASE_URL and SUPABASE_KEY as secrets:
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 Do you happen to use a setup with a
fresh.config.ts
or without one? Asking because before we introducedfresh.config.ts
thedev.ts
would always loadmain.ts
which in turn imports every file of the application. In doing so it will encounter thesupabase
call and complain that the environment variables are not set. That's the main reason we introduced thefresh.config.ts
which allows us to properly split the development mode internally so that you can create a build without loadingmain.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 🙏
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