您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

从GitHub动作推到起源

从GitHub动作推到起源

签出的版本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

如果您需要push事件来触发其他工作流程,请使用repo范围限定的Personal Access Token

      - uses: actions/checkout@v2
        with:
          token: ${{ secrets.PAT }}

在@rmunn的出色答案中添加更多详细信息。问题是该actions/checkout@v1操作使git存储库处于分离的HEAD状态。请参阅此问题以获取更多详细信息:https ://github.com/actions/checkout/issues/6

这是一个完整的示例,以演示如何使已签出的存储库进入可用状态并推送到远程服务器。

name: Push commit
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

包括未跟踪的(新)文件,请更改工作流程以使用以下内容

          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 request
on: pull_request
jobs:
  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中自动执行代码格式设置

其他 2022/1/1 18:14:06 有556人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶