iT邦幫忙

0

請問該如何在github-page配置環境變數?

  • 分享至 

  • xImage

我有一個create-react-app項目是安裝套件 gh-pages,直接用本地下 depoly 到gh-pages分支就完成部署步驟了。

但現在我想要配置自己的環境變數(本地有.env檔案),但這檔案.env我不會推上去github,部署後環境變數則想存在github上,我去了該專案的setting->Actions secrets and variables的variable配了一些。
ex:
REACT_APP_API_KEY=your-api-key
REACT_APP_API_URL=https://test

我以為這可能是github會自己設定幫我預設引用,但實際部署後沒有抓到。(是有抓到我本地設定好的設定,不是github setting裡的)。

關於變數的說明

GitHub sets default variables for each GitHub Actions workflow run. You can also set custom variables for use in a single workflow or multiple workflows.

問題1:從說明看來是否應該自訂yaml設定env區塊?

問題2:該修改或新增workflow action?

我目前有看到現存 action 中有預設 workflow "pages build and deployment"
https://github.com/minilabmemo/f2e-time-twbus/actions

但這一份似乎沒有可以修改的地方?
如果按新增,有蠻多選擇可以選的(不太確定要選哪一種,是否會影響到這一份?)

是否是一定要自訂.github\workflows\xxx.yaml才能抓到環境變數呢?

網路上查到的資訊蠻多種的,不確定方向想先來問問看,

希望有人可以指點迷津,謝謝~

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
codenoob
iT邦新手 5 級 ‧ 2023-10-24 13:40:23

首先,釐清一下原PO的描述?:
creat-react-app是說這個嗎?
https://create-react-app.dev/

接者:
你localhost有一個自己的repo(也就是你提到的creat-react-app?)
你在GitHub上也有一個remote repo(你透過套件:gh-pages將本地的creat-react-app推送到GitHub上對嗎?)
所以,
你使用的套件gh-pages,會幫你完成做哪些操作?
其實它是使用了GitHub Pages這個服務?
那GitHub Pages哪些Deployment limit?
因此,你的佈署方式/架構/平台是?

例如:

#在Linux host上用node.js或其他類似的指令,但其實也是跑類似的dev web serverXD?
node app.js

#寫DockerFile包裝成Docker image,使用docker-eninge/docker-compose/podman/k8s/或其他online services 跑這個container?
docker build . -t creat-react-app:dev
docker run creat-react-app:dev

如果是前面提的creat-react-app那個超連結,
我是有看到這篇:Adding Custom Environment Variables
https://create-react-app.dev/docs/adding-custom-environment-variables/

對,是creat-react-app,部署是透過套件:gh-pages將本地的creat-react-app推送到GitHub上。
本地可以配置你給的環境變數說明就是用.env檔案
但是這個.env檔案我並不會推到GitHub上面,
我是指將環境變數配置到GitHub上面的方法不知道怎麼做,想說是不是要自己寫workflow action。

我要發表回答

立即登入回答