[英]Git add and commit with Python script running on GitHub Actions
我想将带有 Python 脚本的文件添加并提交到在 GitHub Actions 服务器上运行的存储库中。 我通过在main.py
文件中运行以下命令来提交文件:
import os
FILE = './file.txt'
os.system(f'git add {FILE}')
os.system("git commit -m 'update file'")
在 GitHub 动作上,我运行 Python 脚本为:
- name: Commit file
run: python commit_file.py
但是在 GitHub 操作运行后,repo master 分支上没有任何脚本提交。
在我的本地机器上, os.system("git commit -m 'update file'")
命令运行正常,我可以使用git log
命令验证提交是否存在。 在 GitHub 动作上,出现以下错误:
Run Commit file
python commit_file.py
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-az112-319.bzi55m0t1ufu323ye4cn5ktith.xx.internal.cloudapp.net>) not allowed
编辑:我添加了另外两行将配置 git 凭据:
os.system('git config --global user.email "you@example.com"')
os.system('git config --global user.name "GitHub Actions"')
现在,警告消失了,但回购协议上仍然没有提交。
这是错误状态,当您想使用 github 操作将新文件提交到存储库时,需要使用git config
配置用户 email 和名称。
注意:这些值可能是假的、硬编码的或依赖于变量。
您只需在 python 脚本中的 git add 和 git 提交命令之前添加这两个命令行。
此外,您需要在脚本末尾执行git push
,以使文件在工作流运行结束时出现在存储库分支上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.