如何在 GitHub Action 的 YML 文件中添加注释?

4
在下面的语法中:

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://git@github.com:".insteadOf "https://github.com/"

我该如何将“运行git客户端以解决某些问题”作为运行命令的注释添加?
2个回答

9

简述

  • 使用#
- run: git config --global url."ssh://git@github.com:".insteadOf "https://github.com/" # run git client to fix some issue
+ run: |
+   : # run git client to fix some issue
+   git config --global url."ssh://git@github.com:".insteadOf "https://github.com/"

简述:

我已经搜索了官方的 GitHub 文档,也在谷歌上搜索过,但没有找到任何可用的示例。

最终我使用了冒号操作符 : ,紧跟着注释符号 # 就返回了 true 。具体代码如下:

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://git@github.com:".insteadOf "https://github.com/"

今天我学到了。谢谢。 - Raja Anbazhagan

0
在“run git client to fix some issue”之前加上一个井号,它就变成了一条注释。
(YML)
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://git@github.com:".insteadOf "https://github.com/" # run git client to fix some issue

如果你不确定编程语言使用什么注释前缀,可以尝试使用 # 或 //

Python 使用 # 前缀进行注释,CSharp 使用 // 前缀进行注释。

(Python)

# please use my def (actually I thought I made an error in this code but I guess not)

def someDef(string):
    print(string)

someDef("Hi")

(CSharp)

// I have a bad memory and actually can't find any code in my memory to put below

如果你不确定我在说什么,只需将以下内容复制并粘贴到你的YML文件中:
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://git@github.com:".insteadOf "https://github.com/" # run git client to fix some issue

1
Github actions 是用 Python 编写的吗? - overexchange
不,我是在给你展示编程语言中用于注释的示例。请再次阅读完整的帖子。 - WhatTheClown
1
.yml文件是用YML编写的,因此它将使用YML编码语言。 - WhatTheClown
@overexchange 我已经编辑了帖子,将评论添加到正确的行中。起初我不知道你在“run git client to fix some issue作为运行命令的注释”中的意思,但后来我发现你是想将该注释添加到运行命令的末尾。 - WhatTheClown

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接