我正在使用非常简单的工作流程:
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
如果是硬编码,则写
MY_REACT_APP_API_URL=MY_MY_REACT_APP_API_URL
(等等),或者如果我试图从 MY_REACT_APP_API_URL=
获取它,则写 vars.REACT_APP_API_URL
。
这让我觉得我在 github 中定义错误。
这是我的 github 的样子,请注意
env
无法识别变量部分中定义的任何内容。
在 github 操作运行期间,没有任何环境变量可用。
我定义了什么错误以及如何纠正?
我在您的工作流程中看不到的是您还设置了环境名称。我通过输入设置环境名称。
这是一个例子。
name: Build and Deploy
on:
workflow_dispatch:
inputs:
environment:
type: choice
description: Choose environment
options:
- stage
- production
jobs:
deploy:
environment: ${{inputs.environment}}
runs-on: ubuntu-latest
steps:
# ..