【问题标题】:GitHub Action Get Commit MessageGitHub Action 获取提交消息
【发布时间】:2020-12-16 12:49:46
【问题描述】:

因此,我正在构建一个动作,为将转到 Netlify 的项目进行构建。在操作中,我可以传递部署消息。在该部署消息中,我想传递触发构建的提交的提交消息。我正在查看文档,但找不到这是否可能。谢谢

【问题讨论】:

    标签: github-actions


    【解决方案1】:

    您可以使用以下命令获取具体的提交消息:

    github.event.head_commit.message
    

    如果你使用 bash,也可以使用git log 命令获取提交消息:

    git log -1 --pretty=format:"%s"
    

    更新:关于documentation,有效负载以及提交消息的调用都发生了变化。可以使用 GitHub 操作中的以下行来获取消息:

    github.event.commits[0].message
    

    【讨论】:

      【解决方案2】:

      您可以在操作的github 上下文中获取此信息,如下所述: https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context

      事件键将为您提供 webhook 内容,定义如下: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#push

      因此,对于您的操作,您可以使用类似${{ github.event.head_commit.message }}

      【讨论】:

      【解决方案3】:

      两者有细微的差别:

      ${{ github.event.commits[0].message }}
      

      当 github 推送事件包含多个提交时,commit[0] 包含 oldest 提交。我在合并后看到了这个。

      ${{ github.event.head_commit.message }}
      

      另一方面,head_commit 包含 youngest 提交。

      【讨论】:

        【解决方案4】:

        commit-message 可用于以下键:

        • ${{ github.event.commits[0].message }}
        • ${{ github.event.head_commit.message }}

        还有很多关于活动的其他信息。 例如;以下工作流程将为您提供所有这些信息:

        # .github/workflows/logger.yaml
        name: Event Loggger
        on: push
        
        jobs:
          log-github-event-goodies:
            name: "LOG Everything on GitHub Event"
            runs-on: ubuntu-latest
            steps:
              - name: Logging
                run: |
                  echo "${{toJSON(github.event)}}"
        
        

        【讨论】:

          猜你喜欢
          • 2012-01-11
          • 2015-03-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-08-09
          • 1970-01-01
          相关资源
          最近更新 更多