Skip to content

Commit 0aaee72

Browse files
dekimseyshore
andauthored
docs: Add image and another example (#3)
* docs: Add image and another example Include a link to vault-helm usage for in-the-wild examples. Explain what the job status variables are and when to use them. Co-authored-by: brian shore <[email protected]>
1 parent cfde6ad commit 0aaee72

File tree

2 files changed

+58
-9
lines changed

2 files changed

+58
-9
lines changed

README.md

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,30 @@ _For internal HashiCorp use only. The output of this action is specifically desi
22

33
# Slack workflow status action
44

5-
No bells, no whistles, just status.
5+
No bells, no whistles, just status a status message.
6+
7+
## Example
8+
9+
See also some implementations in the wild:
10+
- [hashicorp/vault-helm](https://github.com/hashicorp/vault-helm/blob/bb9a069/.github/workflows/update-helm-charts-index.yml#L34-L40)
11+
12+
Notifications will be emitted with some simple formatting:
13+
14+
![sample color coded slack notifications](docs/example-notifications.png)
615

716
## Usage
817

9-
Create a webhook through either [Technique 2](https://github.com/slackapi/slack-github-action#technique-2-slack-app) or
18+
1. Create a webhook
19+
20+
Use either [Technique 2](https://github.com/slackapi/slack-github-action#technique-2-slack-app) or
1021
[Technique 3](https://github.com/slackapi/slack-github-action#technique-3-slack-incoming-webhook) here. Alternatively,
1122
Release Engineering may provision one on your behalf for status notifications from our [Release Bot](https://api.slack.com/apps/A034FRWL0RK/incoming-webhooks).
1223

13-
To use, add a step like:
24+
Do *not* use Slack's Workflow Builder integration to generate the webhook link.
25+
26+
2. Add the step to the workflow
27+
28+
To use, add a step that tests the job status (success, failure, cancelled):
1429

1530
```yaml
1631
steps:
@@ -21,13 +36,14 @@ steps:
2136
- uses: hashicorp/actions-slack-status@v1
2237
if: ${{always()}}
2338
with:
24-
success-message: ":tada: A success message."
25-
failure-message: ":boom: A failure message."
26-
status: ${{job.status}
39+
success-message: "A *bolded success* message."
40+
failure-message: "A failure message."
41+
#cancelled-message: "Operation cancelled, but that's okay!"
42+
status: ${{job.status}}
2743
slack-webhook-url: ${{secrets.slack_webhook_url}}
2844
```
2945
30-
Or more advanced usage, pass a specific step conclusion:
46+
Or more advanced usage with, pass a specific step conclusion (success, failure, cancelled, skipped):
3147
3248
```yaml
3349
steps:
@@ -38,8 +54,41 @@ steps:
3854
exit 0
3955
- uses: hashicorp/actions-slack-status@v1
4056
with:
41-
skipped-message: ":skip: A successfully skipped cmd message."
42-
success-message: ":tada: A success message."
57+
skipped-message: "A successfully skipped `cmd` message."
58+
success-message: "A success message."
4359
status: ${{steps.demo.conclusion}}
4460
slack-webhook-url: ${{secrets.slack_webhook_url}}
4561
```
62+
63+
64+
Note: Normally, if a `${status}-message` is not defined for a given status a
65+
GH warning will be emitted on the action and no message will be sent to slack.
66+
To avoid this, one can use an approprate `if` statement to skip this step.
67+
68+
In this example, success messages are never sent and no GHA warning will be
69+
emitted regarding this omission.
70+
```yaml
71+
steps:
72+
- run: |
73+
exit 0
74+
- uses: hashicorp/actions-slack-status@v1
75+
if: failure()
76+
with:
77+
failure-message: "Since our job never fails, this message will never send nor will it warn about a missing success-message field"
78+
status: 'failure'
79+
slack-webhook-url: ${{secrets.slack_webhook_url}}
80+
```
81+
82+
### Job Status Meanings
83+
84+
In the examples we used different ways of obtaining the statuses. Their usage can be nuanced, but generally they are:
85+
86+
* [jobs.status docs](https://docs.github.com/en/actions/learn-github-actions/contexts#job-context): `success`, `failure`, or `cancelled`
87+
* [steps.id.conclusion docs](https://docs.github.com/en/actions/learn-github-actions/contexts#steps-context): `success`, `failure`, `cancelled`, or `skipped`
88+
* [steps.id.outcome docs](https://docs.github.com/en/actions/learn-github-actions/contexts#steps-context): `success`, `failure`, `cancelled`, or `skipped`
89+
90+
If in doubt, use `${{jobs.status}}`. The specific step status can be useful if we need to report skips or when multiple
91+
steps are mutually exclusive, and we would like to notify exactly which one fired.
92+
93+
Step conclusion and outcome can differ depending on whether `continue-on-error` is set. In otherwords, if
94+
a step's `continue-on-error: true`, the outcome may be `failure` or `success` but the conclusion would be `success`.

docs/example-notifications.png

78 KB
Loading

0 commit comments

Comments
 (0)