我正在开发一个在 godaddy 上托管的 React 应用程序,目前我想要进行的每个更改都意味着我正在构建项目并删除 cpanel 中的所有先前文件并添加新的构建文件,我如何才能使其自动化将我的代码推送到我的 github 中的特定分支,该分支应该自动上线
谢谢你
我在网上做了研究,发现他们正在 github action main.yml 文件中编写一些代码,因为我对此很陌生,我不知道它是如何工作的,如何根据我的需要修改它
要在Godaddy上部署React应用程序,您可以使用Github操作。 Github actions 对于 CI/CD 管道非常有用,您可以非常轻松地完成它。我为您提供示例 Github actions yaml 文件。
name: Build & Deploy React Application with Github Actions // Ajust it if you want
on: // This is section that what event trigger Github actions.
push:
branches:
- main
env: // Here, you can set environment variables for your React application.
REACT_APP_API_URL: ${{ vars.REACT_APP_API_URL }}
jobs: // In this jobs section, you will set all jobs to deploy your React application on your server.
build-deploy:
name: Build & Deploy Gallerai on server
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Run build
run: npm run build --if-present
- name: Deploy on server
uses: easingthemes/ssh-deploy@main
with:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
ARGS: "-rlgoDzvc -i --delete"
SOURCE: "build/"
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
REMOTE_USER: ${{ secrets.REMOTE_USER }}
REMOTE_PORT: ${{ secrets.REMOTE_PORT }}
TARGET: ${{ secrets.REMOTE_TARGET }}
EXCLUDE: "/dist/, /node_modules/"