当我将一些代码推送到
master
时,会运行一个工作流程文件。该文件构建工件并将代码推送到另一个分支production
。
另一个工作流程文件如下所示,设置为在发生任何推送时运行
production
。
name: Deploy
on:
push:
branches:
- production
jobs:
# Do something
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
但是这个工作流程文件永远不会运行。我希望当工作流文件监听 master 上的推送事件完成后,该文件应该像前一个文件将代码推送到
production
分支一样运行。我如何确保这种情况发生?
您需要使用个人访问令牌 (PAT) 在工作流程中推送代码,而不是默认的
GITHUB_TOKEN
:
注意:您无法使用
触发新的工作流程运行GITHUB_TOKEN
例如,如果工作流运行使用存储库的
推送代码,则即使存储库包含配置为在GITHUB_TOKEN
事件发生时运行的工作流,新工作流也不会运行。push
如果您想从工作流程运行触发工作流程,您可以使用个人访问令牌触发事件。您需要创建个人访问令牌并将其存储为秘密。
name: Push to master
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
# the checkout action persists the passed credentials by default
# subsequent git commands will pick them up automatically
- uses: actions/checkout@v2
with:
token: ${{secrets.PAT}}
- run: |
# do something
git push
如果其他人偶然发现了这一点,那么实际上是 git commit 引发了错误。 '||'捕获错误,然后仅打印到日志,因此该操作甚至不会到达 git push。
- name: Scrape webpage and download file
run: |
python ./python/scraper.py
git config user.name github-actions
git config user.email [email protected]
git commit -am "Auto Generated" || echo "There is nothing to commit"
git push