我正在github中开发一个python包。在github的组织下,我有两个存储库myorg/package
和myorg/documentation
。package
repo包含python包和构建sphinx文档的方法,documentation
包含通过github页面发布的生成的静态html。
我现在正在设置一个github动作工作流来构建package
中的文档,并将其推送到documentation
,这是通过将发布标签推送到package
repo触发的,但我遇到了推送到documentation
repo的问题。
理想情况下,我希望将提交标记为由bot进行,并且我希望所有的提交都具有向两个存储库推送的权限,以便能够运行工作流。
这是我目前的工作流程:
name: Deploy
on:
push:
tags:
- 'v*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
path: package
- uses: actions/checkout@v2
with:
repository: myorg/documentation
path: documentation
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Build documentation
run: |
cd package
tox -e apidoc
tox -e docs
- name: Publish documentation
run: |
cp -RT package/dist/docs/ documentation/latest/
cd documentation
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "Documentation update"
git push
在最后一个命令
中运行失败remote: Permission to pharmpy/pharmpy.github.io.git denied to github-actions[bot].
fatal: unable to access 'https://github.com/pharmpy/pharmpy.github.io/': The requested URL returned error: 403
我不太确定机器人的名字和电子邮件。一些谷歌搜索给人的印象是,这属于一些可以使用的标准机器人。
我怎样才能使它工作?
所以我找到了一个解决方案:
- 创建具有存储库访问权限的个人访问令牌
- 添加这个个人令牌作为github动作的秘密(我命名为
PUSH_TOKEN
) - 在结帐时和按 时使用此令牌
这是修改后的工作流程版本:
name: Deploy
on:
push:
tags:
- 'v*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
path: package
- uses: actions/checkout@v2
with:
repository: myorg/documentation
path: documentation
token: ${{secrets.PUSH_TOKEN}}
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Build documentation
run: |
cd package
tox -e apidoc
tox -e docs
- name: Publish documentation
run: |
cp -RT package/dist/docs/ documentation/latest/
cd documentation
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "Documentation update"
git push https://$USERNAME:$REPO_KEY@github.com/myorg/documentation.git
env:
REPO_KEY: ${{secrets.PUSH_TOKEN}}
USERNAME: github-actions[bot]
可以通过向存储库内容添加写权限来修复该错误。我使用actions/checkout@v3
,并且没有指定任何令牌。推送提交的基本配置如下所示:
name: Example
on: workflow_dispatch
permissions:
contents: write
jobs:
example:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- shell: bash
run: |
date > 1.txt
git config user.name github-actions
git config user.email github-actions@github.com
git add 1.txt
git commit -m updated
git push