Skip to content

Commit 32583fb

Browse files
authored
Merge pull request #10 from scribd/kamranf/pass-optional-status
feat: allow passing status as optional input
2 parents 4e74b15 + 4b34ce2 commit 32583fb

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ jobs:
5454
token: ${{ secrets.SCRIBD_SLACK_GENERIC_TOKEN_PUBLIC }}
5555
channel: test-release-notification
5656
repository: scribd/node-chassis
57+
test-overwrite-status:
58+
runs-on: ubuntu-22.04
59+
steps:
60+
- name: Checkout
61+
uses: actions/checkout@v3
62+
with:
63+
token: ${{ secrets.SCRIBD_GITHUB_RELEASE_TOKEN }}
64+
- name: Run action
65+
uses: ./
66+
with:
67+
token: ${{ secrets.SCRIBD_SLACK_GENERIC_TOKEN_PUBLIC }}
68+
channel: test-release-notification
69+
status: failure
5770

5871
codeowners:
5972
runs-on: ubuntu-22.04

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ steps:
4545
message: <https://github.com/${{ github.repository }}|Released update>
4646
```
4747

48-
### Overwrite repository link
48+
### Overwrite repository and status
4949

5050
By default, the notification links to the repository that triggers the job. You can overwrite that using the `repository` field, which is useful for managing the release for multiple repositories in one place. See [scribd-api-proto](https://github.com/scribd/scribd-api-proto) for example.
5151

@@ -60,6 +60,17 @@ steps:
6060
channel: test-release-notification
6161
repository: scribd/scribd-api-ruby
6262
```
63+
Additionally, `status` can be set explicitly to `success`, `failure` or another custom value to override the default behavior of using status of the job calling this action.
64+
65+
```yaml
66+
steps:
67+
- name: Send notification
68+
uses: scribd/job-notification@main
69+
with:
70+
token: ${{ secrets.SCRIBD_SLACK_GENERIC_TOKEN }}
71+
channel: test-release-notification
72+
status: warning
73+
```
6374

6475
## Development
6576

@@ -69,4 +80,4 @@ You can test your changes by pushing them to a branch, which will trigger the [t
6980

7081
## Maintainers
7182

72-
Made with ❤️ by the Service Foundations teams.
83+
Made with ❤️ by the Service Foundations teams.

action.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ inputs:
55
description: |
66
Name of the repository (e.g scribd/job-notification)
77
Useful for sending notifications on behalf of another repository.
8-
required: true
8+
required: false
99
default: ${{ github.repository }}
1010
token:
1111
description: Slack token to send the notification via "gitscribd" app.
1212
required: true
1313
channel:
1414
description: The Slack channel name for receiving the notification
1515
required: true
16+
status:
17+
description: Customize the notification status to be "success", "failure" or a custom value.
18+
required: false
19+
default: ${{ job.status }}
1620
message:
1721
description: Customize the notification message.
1822

@@ -24,10 +28,10 @@ runs:
2428
if: always()
2529
id: fields
2630
run: |
27-
if [ "${{ job.status }}" = "success" ]; then
31+
if [ "${{ inputs.status }}" = "success" ]; then
2832
echo "emoji=large_green_square" >> $GITHUB_OUTPUT
2933
echo "color=good" >> $GITHUB_OUTPUT
30-
elif [ "${{ job.status }}" = "failure" ]; then
34+
elif [ "${{ inputs.status }}" = "failure" ]; then
3135
echo "emoji=large_red_square" >> $GITHUB_OUTPUT
3236
echo "color=danger" >> $GITHUB_OUTPUT
3337
else
@@ -64,7 +68,7 @@ runs:
6468
channel-id: ${{ inputs.channel }}
6569
payload: |
6670
{
67-
"text": ":${{ steps.fields.outputs.emoji }}: *Workflow <https://github.com/${{ inputs.repository }}/actions/runs/${{ github.run_id }}/|${{ github.workflow }}> ${{ job.status }}*",
71+
"text": ":${{ steps.fields.outputs.emoji }}: *Workflow <https://github.com/${{ inputs.repository }}/actions/runs/${{ github.run_id }}/|${{ github.workflow }}> ${{ inputs.status }}*",
6872
"attachments": [
6973
{
7074
"color": "${{ steps.fields.outputs.color }}",

0 commit comments

Comments
 (0)