Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how create a comment on commit with github actions?

i use github action with this config

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: [email protected]
          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)

I want to automatically create a comment on the latest pushed commit wite msg include my storybook and docker URL. like "now" bot

enter image description here

How can write a comment on commit with github actions?

like image 872
Mehran Motiee Avatar asked Oct 19 '19 22:10

Mehran Motiee


People also ask

How do I comment on a commit on GitHub?

Leave a comment at the bottom of any commit, or on a single line. Up to you. Comments show up in your feed and each repository has its own comment feed. On the commits log or the source browser, commits that have been commented on will be marked with a comment bubble. Try it on the Facebox commit and have fun.

How do I edit a comment on GitHub?

Comment authors and anyone with write access to a repository can also delete sensitive information from a comment's edit history. For more information, see "Tracking changes in a comment." Navigate to the comment you'd like to edit. In the upper-right corner of the comment, click , then click Edit.


1 Answers

Update: I wrote an action to simplify creating commit comments. I will leave the original solution below for reference.

See commit-comment for full usage details.

      - 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

commit-comment action example

Original Solution: The following workflow should be a good starting point. You can find the full documentation for the API here: 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"

It will create a comment on the commit like this. commit comment example

like image 157
peterevans Avatar answered Oct 28 '22 06:10

peterevans