#Github Actions accessing variables

9 messages · Page 1 of 1 (latest)

lime silo
#

I recently removed my .env via .gitignore (because, well, that's good practice) I tried to change to environmental variables in github, I can't figure out how to access them.
I set it in secrets and variables for environment and repository.
I tried setting it in the workflow.yaml
like so:

env:
  CONTENTFUL_DELIVERY_TOKEN: ${{ vars.CONTENTFUL_DELIVERY_TOKEN}}
  CONTENTFUL_PREVIEW_TOKEN: ${{ vars.CONTENTFUL_PREVIEW_TOKEN}}
  CONTENTFUL_SPACE_ID: ${{ vars.CONTENTFUL_SPACE_ID}}

still no luck. Is there any documentation on how to migrate from .env to variables inside CI/CD ?

stoic crest
#

Did you set environment variables or secrets or both?

#

I don't think the syntax matters, but all their examples have a space after ${{ and before }}. You have the first space, but not the second

lime silo
#

Thanks, I'll try that.
Yes, I set them EVERYWHERE 😂. They're in environment and repository secrets and variables

lime silo
#

I change the yaml for test too now, and I get this:
{ dev: false, preview: '', delivery: '' }
from

import contentful from "contentful"
console.log({
    dev: import.meta.env.DEV,
    preview: import.meta.env.CONTENTFUL_PREVIEW_TOKEN,
    delivery: import.meta.env.CONTENTFUL_DELIVERY_TOKEN
})

export const contentfulClient = contentful.createClient({
    space: import.meta.env.CONTENTFUL_SPACE_ID,
    accessToken: import.meta.env.DEV
        ? import.meta.env.CONTENTFUL_PREVIEW_TOKEN
        : import.meta.env.CONTENTFUL_DELIVERY_TOKEN,
    host: import.meta.env.DEV ? "preview.contentful.com" : "cdn.contentful.com",
})

which I copied from astro.build

stoic crest
#

What addons / adapter are you using?

What command are you using in your action? If it's something like

- name: Build
  run: npm run build

what happens if you change it to

- name: Build
  run: CONTENTFUL_PREVIEW_TOKEN=test-token-from-run CONTENTFUL_DELIVERY_TOKEN=${{ vars.CONTENTFUL_DELIVERY_TOKEN }} npm run build

(I'm just trying to bisect the cause)

lime silo
#

Sorry I'm always responding late, I'm not ignoring you and I appreciate the help. I just started a new job, it's like 1 week of orientation. Counting in transportation today was close to 16hrs.
I have sanity in astro.config.mjs ... it's hard coded (TODO: delete that). There is no integration from contentful in the defineConfig.

    - name: Build
      run: pnpm run build

I'm trying:

    - name: Build
      run: |
        CONTENTFUL_DELIVERY_TOKEN=test-token
        CONTENTFUL_PREVIEW_TOKEN=test-preview-token
        pnpm run build
#

hmm, from the last settings, I added DEV: "production" in my env in yaml

#

and now I get output:
{ dev: 'production', preview: '', delivery: '' }