我有一个GitHub Action,它在我的repo上推送时运行。基本上,它会编译repo文件,提交已编译的文件,将该提交压缩到前一个提交中,然后强制推送到repo。
本质上,这个想法是无缝地创建构建并将其添加到repo中,使它看起来像这是原始推送的一部分。
我唯一遇到的问题是
这是为了完整性而提供的操作
本质上,这个想法是无缝地创建构建并将其添加到repo中,使它看起来像这是原始推送的一部分。
我唯一遇到的问题是
git config
。我希望能够从最后一次提交复制user.name
和user.email
,以便当我的Action执行提交时,它看起来像是由推送的用户完成的。我知道我可以使用GITHUB_ACTOR
环境变量获取用户名,但似乎没有环境变量提供电子邮件。而且GitHub会发现它们不相同:
那么,我该如何设置git config
来使用最后一次提交的user.name
和user.email
?
这是为了完整性而提供的操作
.yaml
文件:on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Set up Git repository
uses: actions/checkout@v2
with:
fetch-depth: 2
- (... step that creates build files ...)
- name: Upload build files to repo
run: |
# Configure git
git config user.name "$GITHUB_ACTOR"
git config user.email "<>"
# Roll back git history to before last commit
# This also adds all changes in the last commit to the working tree
git reset --soft HEAD~1
# Add build files to working tree
git add (build files)
# Commit changes and build files using same commit info as before
git commit -C HEAD@{1}
# Force push to overwrite git history
git push --force
user.name
和user.email
。 - Jordan Mitchell Barrett