scr*_*ipt 22 github elixir github-actions
我有这个运行测试的 GitHub 操作文件,但现在我正在其中集成松弛通知。我想获取该Run tests步骤的输出并将其作为消息发送到 slack 步骤
- name: Run tests
run: |
mix compile --warnings-as-errors
mix format --check-formatted
mix ecto.create
mix ecto.migrate
mix test
env:
MIX_ENV: test
PGHOST: localhost
PGUSER: postgres
- name: Slack Notification
uses: rtCamp/action-slack-notify@master
env:
SLACK_MESSAGE: Run tests output
SLACK_TITLE: CI Test Suite
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
Run Code Online (Sandbox Code Playgroud)
任何帮助都感激不尽。谢谢
sma*_*c89 38
你需要做3件事:
id到您想要输出的步骤set-output命令创建输出- name: Run tests
run: |
echo "::set-output name=mix-compile--warnings-as-errors::$(mix compile --warnings-as-errors)\n"
echo "::set-output name=mix-format--check-formatted::$(mix format --check-formatted)\n"
echo "::set-output name=mix-ecto_create::$(mix ecto.create)\n"
echo "::set-output name=mix-ecto_migrate::$(mix ecto.migrate)\n"
echo "::set-output name=mix-test::$(mix test)\n"
id: run_tests
env:
MIX_ENV: test
PGHOST: localhost
PGUSER: postgres
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_MESSAGE: ${{join(steps.run_tests.outputs.*, '\n')}}
SLACK_TITLE: CI Test Suite
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
Run Code Online (Sandbox Code Playgroud)
有关输出名称说明,请参阅元数据语法
小智 21
我使用与存储和输出变量相同的接口进行了操作,以简化某些情况,如下所示:runstdoutstderr
- name: Run tests
uses: mathiasvr/command-output@v1
id: tests
with:
run: |
mix compile --warnings-as-errors
mix format --check-formatted
mix ecto.create
mix ecto.migrate
mix test
- name: Slack Notification
uses: rtCamp/action-slack-notify@master
env:
SLACK_MESSAGE: ${{ steps.tests.outputs.stdout }}
SLACK_TITLE: CI Test Suite
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
Run Code Online (Sandbox Code Playgroud)
当前接受的答案的问题是该步骤的结果将始终是成功的,因为测试执行结果被屏蔽,但echo命令被屏蔽。
对最后一行的修改应该可以保留原始退出状态:
mix test 2>&1 | tee test.log
result_code=${PIPESTATUS[0]}
echo "::set-output name=mix-test::$(cat test.log)"
exit $result_code
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16952 次 |
| 最近记录: |