Skip to content

Commit

Permalink
Merge pull request #10 from scribd/kamranf/pass-optional-status
Browse files Browse the repository at this point in the history
feat: allow passing status as optional input
  • Loading branch information
kamranf authored May 24, 2023
2 parents 4e74b15 + 4b34ce2 commit 32583fb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ jobs:
token: ${{ secrets.SCRIBD_SLACK_GENERIC_TOKEN_PUBLIC }}
channel: test-release-notification
repository: scribd/node-chassis
test-overwrite-status:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.SCRIBD_GITHUB_RELEASE_TOKEN }}
- name: Run action
uses: ./
with:
token: ${{ secrets.SCRIBD_SLACK_GENERIC_TOKEN_PUBLIC }}
channel: test-release-notification
status: failure

codeowners:
runs-on: ubuntu-22.04
Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ steps:
message: <https://github.com/${{ github.repository }}|Released update>
```

### Overwrite repository link
### Overwrite repository and status

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.

Expand All @@ -60,6 +60,17 @@ steps:
channel: test-release-notification
repository: scribd/scribd-api-ruby
```
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.

```yaml
steps:
- name: Send notification
uses: scribd/job-notification@main
with:
token: ${{ secrets.SCRIBD_SLACK_GENERIC_TOKEN }}
channel: test-release-notification
status: warning
```

## Development

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

## Maintainers

Made with ❤️ by the Service Foundations teams.
Made with ❤️ by the Service Foundations teams.
12 changes: 8 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ inputs:
description: |
Name of the repository (e.g scribd/job-notification)
Useful for sending notifications on behalf of another repository.
required: true
required: false
default: ${{ github.repository }}
token:
description: Slack token to send the notification via "gitscribd" app.
required: true
channel:
description: The Slack channel name for receiving the notification
required: true
status:
description: Customize the notification status to be "success", "failure" or a custom value.
required: false
default: ${{ job.status }}
message:
description: Customize the notification message.

Expand All @@ -24,10 +28,10 @@ runs:
if: always()
id: fields
run: |
if [ "${{ job.status }}" = "success" ]; then
if [ "${{ inputs.status }}" = "success" ]; then
echo "emoji=large_green_square" >> $GITHUB_OUTPUT
echo "color=good" >> $GITHUB_OUTPUT
elif [ "${{ job.status }}" = "failure" ]; then
elif [ "${{ inputs.status }}" = "failure" ]; then
echo "emoji=large_red_square" >> $GITHUB_OUTPUT
echo "color=danger" >> $GITHUB_OUTPUT
else
Expand Down Expand Up @@ -64,7 +68,7 @@ runs:
channel-id: ${{ inputs.channel }}
payload: |
{
"text": ":${{ steps.fields.outputs.emoji }}: *Workflow <https://github.com/${{ inputs.repository }}/actions/runs/${{ github.run_id }}/|${{ github.workflow }}> ${{ job.status }}*",
"text": ":${{ steps.fields.outputs.emoji }}: *Workflow <https://github.com/${{ inputs.repository }}/actions/runs/${{ github.run_id }}/|${{ github.workflow }}> ${{ inputs.status }}*",
"attachments": [
{
"color": "${{ steps.fields.outputs.color }}",
Expand Down

0 comments on commit 32583fb

Please sign in to comment.