如何将React应用程序部署到GitHub Action中的GitHub页面?

发布于 2025-02-08 03:35:48 字数 2029 浏览 2 评论 0原文

我正在构建一个React应用程序,并且正在尝试通过将其自动部署到GitHub页面来实现某种形式的CI/CD。为此,我正在使用NPM软件包 gh-pages ,但是我正在遇到一个错误:

$ gh-pages -d build
Author identity unknown
*** Please tell me who you are.
Run
  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: empty ident name (for <runner@fv-az72-309.paxcb4zidlwe3mfrpko3itqnmd.bx.internal.cloudapp.net>) not allowed
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Process completed with exit code 1.

我如何提供“作者身份”以在github页面工人上进行git?

到目前为止,我已经尝试过的事情:

  • 使用默认令牌使用
  • 默认令牌/结帐
  • 使用我的个人访问令牌,并
  • 使用
  • 设置git config user.name.name和user.email to我自己和github actions的凭据,我的

工作流文件我的工作流文件如下:

name: Github Pages

on:
  push:
    branches: ["master"]
  pull_request:
    branches: ["master"]

  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      # i've also tried with the default token, and without any token  
      with: 
          token: ${{secrets.PAT}}
      - uses: actions/setup-node@v2
      - name: Deploy
        run: |
          yarn install
          CI=false && yarn deploy

package.json脚本:

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build"
  },

我是反应/JS/NPM的新手,所以让我知道我是否需要提供其他信息。

I'm building a React app, and I'm trying to implement some form of CI/CD by having it automatically deploy to Github Pages whenever I push to the main branch. To accomplish this I am using the npm package gh-pages, but I am running into an error:

$ gh-pages -d build
Author identity unknown
*** Please tell me who you are.
Run
  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: empty ident name (for <runner@fv-az72-309.paxcb4zidlwe3mfrpko3itqnmd.bx.internal.cloudapp.net>) not allowed
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Process completed with exit code 1.

How do i provide "Author identity" to git on the Github Pages worker?

Things I've tried so far:

  • Not using any token with actions/checkout
  • Using the default token with actions/checkout
  • Using my personal access token with actions/checkout
  • Using actions/github-script to
  • Setting git config user.name and user.email to both my own and Github Actions' credentials

My workflow file looks as follows:

name: Github Pages

on:
  push:
    branches: ["master"]
  pull_request:
    branches: ["master"]

  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      # i've also tried with the default token, and without any token  
      with: 
          token: ${{secrets.PAT}}
      - uses: actions/setup-node@v2
      - name: Deploy
        run: |
          yarn install
          CI=false && yarn deploy

package.json scripts:

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build"
  },

I am fairly new to React/js/npm, so let me know if I need to provide additional information.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谜泪 2025-02-15 03:35:48

我弄清楚了!似乎这是一个权限问题,但是即使正确使用PAT,我仍然必须设置Git Config变量:

name: Github Pages

on:
  push:
    branches: ["master"]
  pull_request:
    branches: ["master"]

  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v2
      - name: Deploy
        run: |
          yarn install
          git config --global user.email '[email protected]'
          git config --global user.name 'github-actions'
          git remote set-url origin https://${{ secrets.PAT }}@github.com/username/repository.git
          CI=false && yarn deploy

I figured it out! Seems like it was a permissions problem, but even when using the PAT properly, i still had to set the git config variables:

name: Github Pages

on:
  push:
    branches: ["master"]
  pull_request:
    branches: ["master"]

  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v2
      - name: Deploy
        run: |
          yarn install
          git config --global user.email '[email protected]'
          git config --global user.name 'github-actions'
          git remote set-url origin https://${{ secrets.PAT }}@github.com/username/repository.git
          CI=false && yarn deploy
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文