I am using the very simple workflow:
name: Deploy Frontend
# env:
# REACT_APP_API_URL: ${{ vars.REACT_APP_API_URL }}
# CORS_ALLOWED_ORIGINS: ${{ vars.CORS_ALLOWED_ORIGINS }}
env:
REACT_APP_API_URL: MY_REACT_APP_API_URL
CORS_ALLOWED_ORIGINS: MY_CORS_ALLOWED_ORIGINS
on:
push:
branches: [main, staging, frontend]
paths:
- 'frontend/**'
- '.github/workflows/deploy_frontend.yml'
workflow_dispatch:
jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
contents: write
pages: write # Added for GitHub Pages deployment
id-token: write # Necessary for actions/deploy-pages
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v4
- name: Debug REACT_APP_API_URL
shell: bash
run: |
echo -e "e[32m@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@e[0m"
echo -e "e[32mREACT_APP_API_URL=${REACT_APP_API_URL}e[0m"
echo -e "e[32mREACT_APP_API_URL=${CORS_ALLOWED_ORIGINS}e[0m"
env
which writes MY_REACT_APP_API_URL=MY_MY_REACT_APP_API_URL
(and so on) if it is hard coded, or MY_REACT_APP_API_URL=
if I am trying to get it from vars.REACT_APP_API_URL
.
This makes me think I defined it incorrectly in github.
Here is what my github looks like, and please note env
doesn’t recognize anything defined in the variables section.
None of the environment variables are available during the github actions run.
What did I define wrong and how to make it right?
2
Answers
Answer found here (but really it took hours with GPT and a hint from @Bademeister).
I had the environment set to
gh-pages
whereas it should be set toSo the
jobs
section should beAnd suddenly all variables go in the workflow
What I can not see in your workflow is that you also set the environment name. I set the environment name via an input.
Here is an example.