|
| 1 | +--- |
| 2 | +# See the "workflow builder" approach in https://github.com/slackapi/slack-github-action/. |
| 3 | +name: Slack alert |
| 4 | +description: Send an alert to a Slack channel using workflow builder |
| 5 | +inputs: |
| 6 | + inputs: |
| 7 | + description: Textual representation of workflow inputs |
| 8 | + required: false |
| 9 | + default: "N/A" |
| 10 | + type: string |
| 11 | + message: |
| 12 | + description: Alert message |
| 13 | + required: false |
| 14 | + default: >- |
| 15 | + ${{ github.workflow }}${{ (github.job != github.workflow) && ('/' + github.job) || '' }} |
| 16 | + GitHub Actions workflow failed :sob: |
| 17 | + type: string |
| 18 | + results-url: |
| 19 | + description: URL for workflow results |
| 20 | + required: false |
| 21 | + default: "N/A" |
| 22 | + type: string |
| 23 | + # Typically this would be a secret. |
| 24 | + slack-webhook-url: |
| 25 | + description: Slack workflow builder webhook URL |
| 26 | + required: true |
| 27 | + type: string |
| 28 | + # Typically this would be a secret or variable. |
| 29 | + slack-channel-id: |
| 30 | + description: ID of Slack channel to send alert to |
| 31 | + required: true |
| 32 | + type: string |
| 33 | +runs: |
| 34 | + using: composite |
| 35 | + steps: |
| 36 | + - name: Send message to Slack via Workflow Builder |
| 37 | + |
| 38 | + with: |
| 39 | + payload: | |
| 40 | + { |
| 41 | + "channel-id": "${{ env.SLACK_CHANNEL_ID }}", |
| 42 | + "inputs": "${{ env.INPUTS }}", |
| 43 | + "message": "${{ env.MESSAGE }}", |
| 44 | + "results-url": "${{ env.RESULTS_URL }}", |
| 45 | + "workflow-url": "${{ env.WORKFLOW_URL }}" |
| 46 | + } |
| 47 | + env: |
| 48 | + SLACK_WEBHOOK_URL: ${{ inputs.slack-webhook-url }} |
| 49 | + SLACK_CHANNEL_ID: ${{ inputs.slack-channel-id }} |
| 50 | + INPUTS: ${{ inputs.inputs }} |
| 51 | + MESSAGE: ${{ inputs.message }} |
| 52 | + RESULTS_URL: ${{ inputs.results-url }} |
| 53 | + WORKFLOW_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
0 commit comments