动作/结帐@ v2
签出的版本2解决了分离的HEAD状态问题,并简化了向原点的推送。
name: Push commiton: pushjobs: 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
如果您需要push事件来触发其他工作流程,请使用
repo范围限定的Personal Access
Token。
- uses: actions/checkout@v2 with: token: ${{ secrets.PAT }}动作/结帐@ v1(原始答案)
在@rmunn的出色答案中添加更多详细信息。问题是该
actions/checkout@v1操作使git存储库处于分离的HEAD状态。请参阅此问题以获取更多详细信息:https
:
//github.com/actions/checkout/issues/6
这是一个完整的示例,以演示如何使已签出的存储库进入可用状态并推送到远程服务器。
name: Push commiton: pushjobs: 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要包括未跟踪的(新)文件,请更改工作流程以使用以下内容。
git add -A git commit -m "Automated report"
以上工作流程应适用于大多数事件。对于
on: pull_request工作流,
GITHUB_HEAD_REF应检出合并分支()以替换默认的合并提交。
重要提示:
如果除了以下工作流程之外还进行其他拉取请求检查,则必须使用个人访问令牌代替默认访问令牌
GITHUB_TOKEN。这是由于GitHub
Actions故意施加的限制,由工作流程引发的事件(例如
push)无法触发进一步的工作流程运行。这是为了防止意外的“无限循环”情况,并且是一种防止滥用的措施。使用
repo范围限定的个人访问令牌是一种公认的解决方法。有关解决方法的更多详细信息,请参见此GitHub问题。
name: Push commit on pull requeston: pull_requestjobs: report: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 with: ref: ${{ github.head_ref }} - 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 commit -am "Automated report" git push有关在
on: pull_request工作流期间推送到原点的更多示例,请参阅此博客文章GitHub Actions:如何在Pull
Requests中自动执行代码格式设置。



