How do I add a comment in GitHub action YML file?
Asked Answered
F

2

9

In the below syntax:

jobs:
  testing:
    name: some test
    runs-on: [ self-hosted, linux, xyz ]
    steps:
      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.15.0
        id: go

      - name: Configure git client
        run: git config --global url."ssh://[email protected]:".insteadOf "https://github.com/"

How do I add run git client to fix some issue as a comment for the run command?

Firsthand answered 11/2, 2021 at 7:19 Comment(0)
J
15

tl; dr

  • Use : #
- run: git config --global url."ssh://[email protected]:".insteadOf "https://github.com/" # run git client to fix some issue
+ run: |
+   : # run git client to fix some issue
+   git config --global url."ssh://[email protected]:".insteadOf "https://github.com/"

ts; dr

I've been searching the official GitHub docs and googling around but couldn't find any working sample.

And I came up with the answer by using the : operand which just returns true followed by the comment # like so:

jobs:
  testing:
    name: some test
    runs-on: [ self-hosted, linux, xyz ]
    steps:
      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.15.0
        id: go

      - name: Configure git client
        run: |
          : # run git client to fix some issue
          git config --global url."ssh://[email protected]:".insteadOf "https://github.com/"
Jackjackadandy answered 17/7, 2021 at 14:1 Comment(1)
I don't know if this is because it is now changed, but this is wrong, commenting is done with just the pound sign, as in YAML. You can see plenty of it in the official Actions sources. Example : github.com/actions/checkout/blob/…Deflocculate
D
1

As other answers are either incomplete or sidetracked, here is it straightforward :

Add a pound sign (#) and the rest of the line is commented, which is the standard YAML way to add a comment.
Do note that a whitespace is required between the # and the comment.

Usually it is a good practice for readability to just put it at the beginning of the line and have the comment on its own line.

jobs:
  testing:
    name: some test
    runs-on: [ self-hosted, linux, xyz ]
    steps:
      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.15.0
        id: go

      - name: Configure git client
        # run git client to fix some issue
        run: git config --global url."ssh://[email protected]:".insteadOf "https://github.com/"

As the Stackoverflow preview will show you, it is added as a comment.


Now if, like me, you ended up here because your comment is not showing as a comment in VS Code, and you are using the Github Actions extension (the official one by Github), there is no special way to add comment in Github Actions, it is just a bug of the extension that does not highlight comments correctly if they contain templating syntax. See : https://github.com/github/vscode-github-actions/issues/158

Deflocculate answered 6/8, 2024 at 13:37 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.