如何解决配置 Github 工作流操作以将操作结果发送到 slack 消息
我正在努力将操作结果输出到 slack 消息。
这是我目前尝试过的
jobs:
scratch-org-test:
runs-on: ubuntu-latest
outputs:
deploy: ${{ steps.deploy.outputs:text }}
apex-tests: ${{ steps.apex-tests.outputs.text }}
steps:
- name: "Push source to scratch org"
id: "deploy"
run: echo "::set-output name=text::$(sfdx force:source:push)"
- name: 'Run Apex tests'
run: 'sfdx force:apex:test:run -c -r human -d ./tests/apex -w 20'
- uses: pCYSl5EDgo/cat@master
id: hello
with:
path: ./tests/apex/test-result.txt
- name: 'Output Apex Tests Execution results'
id: "apex-tests"
run: echo "::set-output name=text::${{ steps.hello.outputs.text }}"
slack-notification-with-optional-parameters:
runs-on: ubuntu-latest
needs: scratch-org-test
name: Sends a message to Slack when a push,a pull request or an issue is made
steps:
- name: Send message to Slack API
uses: archive/github-actions-slack@v1.0.3
id: notify
with:
slack-bot-user-oauth-access-token: {{secrets.token}}
slack-channel: random
slack-text: Deploy ${{needs.scratch-org-test.outputs.deploy}} Apex-tests ${{needs.scratch-org-test.outputs.apex-tests}}
slack-optional-icon_emoji: ":fire:"
- name: Result from "Send Message"
run: echo "The result was ${{ steps.notify.outputs.slack-result }}"
我收到了什么
看起来完整的输出没有传递给输出变量。我不明白为什么。当我查看 Github Actions 时,我可以在那里看到整个输出,但在 slack 消息中看不到。
我想要实现的目标:
NotifierAPP 上午 10:51 部署
Run echo "::set-output name=text::$(sfdx force:source:push)"
SOURCE PROGRESS | ████████████████████████████████████████ | 0/0 Components
SOURCE PROGRESS | ████████████████████████████████████████ | 0/0 Components
SOURCE PROGRESS | ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ | 0/61 Components
SOURCE PROGRESS | ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ | 0/61 Components
SOURCE PROGRESS | ███░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ | 4/61 Components
SOURCE PROGRESS | ███░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ | 4/61 Components
SOURCE PROGRESS | ████████████████████████░░░░░░░░░░░░░░░░ | 37/61 Components
SOURCE PROGRESS | ████████████████████████████░░░░░░░░░░░░ | 42/61 Components
SOURCE PROGRESS | ███████████████████████████████████████░ | 60/61 Components
SOURCE PROGRESS | ███████████████████████████████████████░ | 60/61 Components
SOURCE PROGRESS | ███████████████████████████████████████░ | 60/61 Components
SOURCE PROGRESS | ████████████████████████████████████████ | 61/61 Components
SOURCE PROGRESS | ████████████████████████████████████████ | 61/61 Components
=== 推送源 州全名类型项目路径 ────────────────────────────────────────────────────── ──────────────────────── ──────────────────────────── ────────────────────────────────────────────────────── ────────────────────────────────────────────────────── ────────────────
Apex Tests
=== Apex Code Coverage
ID NAME % COVERED UNCOVERED LInes
────────────────── ────────────────────────── ───────── ───────────────
01p1j000004BegPAAS Class1 100%
01p1j000004BegUAAS Class2 100%
01p1j000004BegGAAS Class3 100%
01q1j000000rclOAAQ Class4 100%
01p1j000004BegIAAS Class5 100%
01p1j000004BegOAAS Class6 100%
01p1j000004BegTAAS Class7 100%
01p1j000004BegKAAS Class8 100%
01p1j000004BegNAAS Class9 100%
01p1j000004BegRAAS Class10 100%
有没有办法将完整的输出发送到 slack?
解决方法
我终于找到了solution here
基本上应该对新行进行转义以使其工作。
此外,我真的不需要 CYSl5EDgo/cat@master
操作,而是可以使用 cat
命令。
- name: "Push source to scratch org"
id: "deploy"
run: |
deploy=$(sfdx force:source:push)
echo $deploy
deploy="${deploy//'%'/'%25'}"
deploy="${deploy//$'\n'/'%0A'}"
deploy="${deploy//$'\r'/'%0D'}"
echo "::set-output name=text::$deploy"
- name: 'Run Apex tests'
run: 'sfdx force:apex:test:run -c -r human -d ./tests/apex -w 20'
- name: 'Output Apex Tests Execution results'
id: "apex-tests"
run: |
text=$(cat ./tests/apex/test-result.txt)
echo $text
text="${text//'%'/'%25'}"
text="${text//$'\n'/'%0A'}"
text="${text//$'\r'/'%0D'}"
echo "::set-output name=text::$text"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。