[英]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.