From 0461f449db1c0fb0f68ba175efaf3d119c979bf4 Mon Sep 17 00:00:00 2001 From: Kamran Farhadi Date: Wed, 17 May 2023 17:34:09 -0400 Subject: [PATCH 1/2] feat: allow passing status as optional input --- README.md | 15 +++++++++++++-- action.yml | 12 ++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ea5c633..e76616c 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ steps: message: ``` -### 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. @@ -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 @@ -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. \ No newline at end of file +Made with ❤️ by the Service Foundations teams. diff --git a/action.yml b/action.yml index 8f3fe8b..b0d42c6 100644 --- a/action.yml +++ b/action.yml @@ -5,7 +5,7 @@ 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. @@ -13,6 +13,10 @@ inputs: 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. @@ -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 @@ -64,7 +68,7 @@ runs: channel-id: ${{ inputs.channel }} payload: | { - "text": ":${{ steps.fields.outputs.emoji }}: *Workflow ${{ job.status }}*", + "text": ":${{ steps.fields.outputs.emoji }}: *Workflow ${{ inputs.status }}*", "attachments": [ { "color": "${{ steps.fields.outputs.color }}", From 4b34ce2f77e93ac5d6cf0b9822ee50afc3fc5fb5 Mon Sep 17 00:00:00 2001 From: Kamran Farhadi Date: Tue, 23 May 2023 11:42:03 -0400 Subject: [PATCH 2/2] add CI test per code-review feedback --- .github/workflows/ci.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9e07c6..98b5ce4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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