Github 操作:自动评论拉取请求的控制台输出
Github Actions: Auto commenting a console output on a pull request
我正在尝试设置一个 git 集线器操作,该操作会在基于拉取请求构建后自动评论大小增量。本质上,我需要将“计算代码大小增量”命令的输出包含在根据拉取请求自动创建的注释中。
以下是该操作的 2 个步骤现在的样子:
- name: Diff revision
id: diff_rev
shell: bash
working-directory: cobrax
run: |
echo "::set-output name=delta_code::$(python3 codesizes.py diff build/zephyr/zephyr.elf)\n"
- name: Auto Comment
uses: bubkoo/auto-comment@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pullRequestOpened: >
@{{ author }}
Thank you for raising your pull request.
This is the code delta:
${{join(steps.diff_rev.outputs.delta_code, '\n')}}
Please make sure you have followed our contributing guidelines. We will review it as soon as possible
控制台显示如下结果:
Using git merge-base against master branch
Comparing code size of current .elf against: 30ac63fd5ea039c7b874a999f928f41220ad883f
+---------+--------+-------+-------+
| Region | .text | .data | .bss |
+---------+--------+-------+-------+
| Local | 113298 | 2412 | 31355 |
| Against | 113298 | 2412 | 31355 |
| Delta | 0 | 0 | 0 |
+---------+--------+-------+-------+\n
如您所见,我使用 set-output 来存储结果(或者,我认为它就是这样做的),然后在注释中使用输出变量。但这显然行不通。
bubkoo/auto-comment 动作的输出是:
octokit.reactions.deleteLegacy() is deprecated, see https://developer.github.com/v3/reactions/#delete-a-reaction-legacy
(node:3588) UnhandledPromiseRejectionWarning: HttpError: Not Found
at /__w/_actions/bubkoo/auto-comment/v1/dist/index.js.cache.js:1:76457
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:3588) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:3588) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
并且,评论显示为:“[...] 这是代码增量:使用 git merge-base against master branch Please make sure [...]”。短语“Using git merge-base agains master branch 确实附加到评论中,但显然不是整个控制台输出。
我做错了什么,你会如何使用 github 操作来做到这一点?
感谢您的帮助。
此致。
您的问题是输出包含多行并且只有第一行分配给了变量。正如在 GitHub 支持社区的 post 上看到的那样,您可以将换行符转义为单行,使用时会自动展开。另一件需要考虑的事情是,您应该在 .yml
中留下一行 space,以便稍后在 GitHub 评论中开始一个新行。
您的代码段应如下所示:
- name: Diff revision
id: diff_rev
shell: bash
working-directory: cobrax
run: |
delta=$(python3 codesizes.py diff build/zephyr/zephyr.elf)
delta="${delta//'%'/'%25'}"
delta="${delta//$'\n'/'%0A'}"
delta="${delta//$'\r'/'%0D'}"
echo "::set-output name=delta_code::$delta"
- name: Auto Comment
uses: bubkoo/auto-comment@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pullRequestOpened: >
@{{ author }}
Thank you for raising your pull request.
This is the code delta:
```
${{ steps.diff_rev.outputs.delta_code }}
```
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
样本 $(git log)
:
完整 auto-comment.yml
:
name: Auto Comment
on:
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Diff revision
id: diff_rev
shell: bash
run: |
delta=$(git log)
delta="${delta//'%'/'%25'}"
delta="${delta//$'\n'/'%0A'}"
delta="${delta//$'\r'/'%0D'}"
echo "::set-output name=delta_code::$delta"
- name: Auto Comment
uses: bubkoo/auto-comment@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pullRequestOpened: >
@{{ author }}
Thank you for raising your pull request.
This is the code delta:
```
${{ steps.diff_rev.outputs.delta_code }}
```
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
我正在尝试设置一个 git 集线器操作,该操作会在基于拉取请求构建后自动评论大小增量。本质上,我需要将“计算代码大小增量”命令的输出包含在根据拉取请求自动创建的注释中。
以下是该操作的 2 个步骤现在的样子:
- name: Diff revision
id: diff_rev
shell: bash
working-directory: cobrax
run: |
echo "::set-output name=delta_code::$(python3 codesizes.py diff build/zephyr/zephyr.elf)\n"
- name: Auto Comment
uses: bubkoo/auto-comment@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pullRequestOpened: >
@{{ author }}
Thank you for raising your pull request.
This is the code delta:
${{join(steps.diff_rev.outputs.delta_code, '\n')}}
Please make sure you have followed our contributing guidelines. We will review it as soon as possible
控制台显示如下结果:
Using git merge-base against master branch
Comparing code size of current .elf against: 30ac63fd5ea039c7b874a999f928f41220ad883f
+---------+--------+-------+-------+
| Region | .text | .data | .bss |
+---------+--------+-------+-------+
| Local | 113298 | 2412 | 31355 |
| Against | 113298 | 2412 | 31355 |
| Delta | 0 | 0 | 0 |
+---------+--------+-------+-------+\n
如您所见,我使用 set-output 来存储结果(或者,我认为它就是这样做的),然后在注释中使用输出变量。但这显然行不通。
bubkoo/auto-comment 动作的输出是:
octokit.reactions.deleteLegacy() is deprecated, see https://developer.github.com/v3/reactions/#delete-a-reaction-legacy
(node:3588) UnhandledPromiseRejectionWarning: HttpError: Not Found
at /__w/_actions/bubkoo/auto-comment/v1/dist/index.js.cache.js:1:76457
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:3588) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:3588) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
并且,评论显示为:“[...] 这是代码增量:使用 git merge-base against master branch Please make sure [...]”。短语“Using git merge-base agains master branch 确实附加到评论中,但显然不是整个控制台输出。
我做错了什么,你会如何使用 github 操作来做到这一点?
感谢您的帮助。
此致。
您的问题是输出包含多行并且只有第一行分配给了变量。正如在 GitHub 支持社区的 post 上看到的那样,您可以将换行符转义为单行,使用时会自动展开。另一件需要考虑的事情是,您应该在 .yml
中留下一行 space,以便稍后在 GitHub 评论中开始一个新行。
您的代码段应如下所示:
- name: Diff revision
id: diff_rev
shell: bash
working-directory: cobrax
run: |
delta=$(python3 codesizes.py diff build/zephyr/zephyr.elf)
delta="${delta//'%'/'%25'}"
delta="${delta//$'\n'/'%0A'}"
delta="${delta//$'\r'/'%0D'}"
echo "::set-output name=delta_code::$delta"
- name: Auto Comment
uses: bubkoo/auto-comment@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pullRequestOpened: >
@{{ author }}
Thank you for raising your pull request.
This is the code delta:
```
${{ steps.diff_rev.outputs.delta_code }}
```
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
样本 $(git log)
:
完整 auto-comment.yml
:
name: Auto Comment
on:
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Diff revision
id: diff_rev
shell: bash
run: |
delta=$(git log)
delta="${delta//'%'/'%25'}"
delta="${delta//$'\n'/'%0A'}"
delta="${delta//$'\r'/'%0D'}"
echo "::set-output name=delta_code::$delta"
- name: Auto Comment
uses: bubkoo/auto-comment@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pullRequestOpened: >
@{{ author }}
Thank you for raising your pull request.
This is the code delta:
```
${{ steps.diff_rev.outputs.delta_code }}
```
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.