配置 Github 工作流操作以将操作结果发送到松弛消息
Configure Github Workflow Action to send result of action to slack message
我正在努力将操作结果输出到松弛消息。
这是我目前尝试过的方法
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 操作时,我可以在那里看到整个输出,但在松弛消息中看不到。
我想要达到的目标:
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"
我正在努力将操作结果输出到松弛消息。
这是我目前尝试过的方法
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 操作时,我可以在那里看到整个输出,但在松弛消息中看不到。
我想要达到的目标:
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"