Ilj*_*lja 9 git continuous-integration github github-actions
在我的操作工作流程结束时,我有以下步骤。它在代码推送到 master 时运行,其想法是一旦此操作完成,将所有由 github 操作更改的文件提交回 master。
- name: Commit and push changes
run: |
git config --global user.name 'myGithubUserName'
git config --global user.email 'myEmail@gmail.com'
git add -A
git commit -m "Increased build number [skip ci]"
git push -u origin HEAD
Run Code Online (Sandbox Code Playgroud)
但是,即使我正在配置用户和电子邮件,我也不断收到以下错误。
致命:无法读取“ https://github.com ”的用户名:设备未配置
[错误]进程已完成,退出代码为 128。
请注意,这会继续运行macOS-latest
并使用预打包的 git。
pet*_*ans 12
动作/结帐@v2
结帐的第 2 版解决了分离的 HEAD 状态问题并简化了推送到源的过程。
name: Push commit
on: push
jobs:
report:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Create report file
run: date +%s > report.txt
- name: Commit report
run: |
git config --global user.name 'Your Name'
git config --global user.email 'your-username@users.noreply.github.com'
git commit -am "Automated report"
git push
Run Code Online (Sandbox Code Playgroud)
如果您需要推送事件来触发其他工作流,请使用repo
范围内的Personal Access Token。
- uses: actions/checkout@v2
with:
token: ${{ secrets.PAT }}
Run Code Online (Sandbox Code Playgroud)
动作/结帐@v1(原始答案)
问题是该actions/checkout@v1
操作使 git 存储库处于分离的 HEAD 状态。有关更多详细信息,请参阅此问题:https : //github.com/actions/checkout/issues/6
我成功使用的解决方法是按如下方式设置遥控器:
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/username/repository
Run Code Online (Sandbox Code Playgroud)
您可能还需要结帐。您可以从以下位置提取分支名称GITHUB_REF
:
git checkout "${GITHUB_REF:11}"
Run Code Online (Sandbox Code Playgroud)
这里有一个完整的例子来演示。
name: Push commit example
on: push
jobs:
report:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Create report file
run: date +%s > report.txt
- name: Commit report
run: |
git config --global user.name 'Your Name'
git config --global user.email 'your-username@users.noreply.github.com'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
git checkout "${GITHUB_REF:11}"
git commit -am "Automated report"
git push
Run Code Online (Sandbox Code Playgroud)
顺便说一下,我写了一个 GitHub 操作,它可以帮助你实现你想要做的事情。它将在工作流期间在本地进行任何更改,将它们提交到新分支并提出拉取请求。 https://github.com/peter-evans/create-pull-request
另请参阅此相关问答。从 GitHub 操作推送到源