如何使用 github 操作创建对提交的评论?

how create a comment on commit with github actions?

我在此配置中使用 github 操作

name: Node CI

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v1
      - name: install node
        uses: actions/setup-node@v1
        with:
          node-version: 12.x
      - name: npm install
        run: npm install
      - name: npm build
        run: npm run build --if-present
      - name: npm test
        run: npm test
      - name: make storybook
        run: npm run build-storybook
      - uses: dswistowski/surge-sh-action@v1
        with:
          domain: 'https://react-strix-$(git rev-parse --short HEAD).surge.sh'
          project: '.out'
          login: straxico@gmail.com
          token: ${{ secrets.SURGE_PASSWORD }}
      - name: deploy image
        run: |
          docker login docker.pkg.github.com --username straxico --password ${{ secrets.DOCKER_PASSWORD }}
          docker build . --file Dockerfile --tag docker.pkg.github.com/straxico/react-strix/master:$(git describe --tags)
          docker push docker.pkg.github.com/straxico/react-strix/master:$(git describe --tags)

我想在最新推送的提交信息中自动创建评论,包括我的故事书和 docker URL。喜欢 "now" 机器人

如何使用 github 操作对提交进行评论?

更新: 我写了一个动作来简化提交评论的创建。下面我把原来的解决办法留给大家参考

有关完整用法的详细信息,请参阅 commit-comment

      - name: Create commit comment
        uses: peter-evans/commit-comment@v1
        with:
          body: |
            This is a multi-line test comment
            - With GitHub **Markdown**
            - Created by [commit-comment][1]

            [1]: https://github.com/peter-evans/commit-comment

原始解决方案: 以下工作流程应该是一个很好的起点。您可以在此处找到 API 的完整文档: https://developer.github.com/v3/repos/comments/#create-a-commit-comment

name: commit comment
on: push
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: Add commit comment
        run: |
          jq -nc '{"body": "test comment"}' | \
          curl -sL  -X POST -d @- \
            -H "Content-Type: application/json" \
            -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
            "https://api.github.com/repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/comments"

它将像这样在提交上创建评论。