我正在构建一个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 "you@example.com"
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.
如何提供"作者身份"?git在Github页面工作器?
我已经尝试过的事情:
- 在actions/checkout中不使用任何令牌
- 在actions/checkout中使用默认令牌
- 在actions/checkout中使用我的个人访问令牌 使用actions/github-script到
- 设置git配置user.name和user。电子邮件到我自己和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
包。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"
},
我对React/js/npm相当陌生,所以如果需要我提供额外的信息,请告诉我。
我明白了!似乎这是一个权限问题,但即使正确使用PAT,我仍然必须设置git配置变量:
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 'github-actions@github.com'
git config --global user.name 'github-actions'
git remote set-url origin https://${{ secrets.PAT }}@github.com/username/repository.git
CI=false && yarn deploy