Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
80b2da0
add optional arguments
Tim108 Oct 7, 2022
82337f0
add blocks as proper argument
Tim108 Oct 7, 2022
07d8a55
update argument list
Tim108 Oct 7, 2022
9351853
adding integration test
archive Oct 13, 2022
ff4faba
Merge branch 'master' into update_message_with_blocks
archive Oct 13, 2022
9f4f5b2
integration test needs to be on right branch :)
archive Oct 13, 2022
452ecba
integration test for update block
archive Oct 13, 2022
4bd4707
Rename since they were wrong :)
archive Oct 13, 2022
d1ab528
hope to solve 'invalid_blocks_format' error
archive Oct 13, 2022
20ac7c7
hope to solve 'invalid_blocks_format' error
archive Oct 13, 2022
244c2bb
Merge branch 'master' into update_message_with_blocks
archive Oct 14, 2022
1e66227
Sometimes slack returns 200 but with an inner error, we need to handl…
archive Oct 14, 2022
2bcb64c
build
archive Oct 14, 2022
f4d5903
assignment to constant variable :)
archive Oct 14, 2022
fe2c5c9
build
archive Oct 14, 2022
2ec7555
temp disable other integration tests (to speed up feedback)
archive Oct 14, 2022
fc907c8
build
archive Oct 14, 2022
3008666
temp disable other integration tests (to speed up feedback)
archive Oct 14, 2022
a2090c1
added missing ts to test and moved ts above text/blocks
archive Oct 14, 2022
b328e13
build
archive Oct 14, 2022
ee8c02c
build
archive Oct 14, 2022
bbb55d4
build
archive Oct 14, 2022
1f8cd0c
build
archive Oct 14, 2022
7ded302
build
archive Oct 14, 2022
bc63b6b
build
archive Oct 14, 2022
1b51211
build
archive Oct 14, 2022
201c6c1
build
archive Oct 14, 2022
6b27139
build
archive Oct 14, 2022
102b45c
text and blocks needs to be handle in the builders
archive Oct 14, 2022
2e105ca
wip
archive Oct 14, 2022
779b57c
extracted optional
archive Oct 14, 2022
fdbbefe
added blocks in readme
archive Oct 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/0-codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ on:

jobs:
analyze:
#if: ${{ false }}
name: Analyze
runs-on: ubuntu-latest
permissions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: [push]

jobs:
slack-action:
#if: ${{ false }}
runs-on: ubuntu-20.04
name: Test 1 [ubuntu-20.04]

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/10-slack-fake-build-updates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: [push]

jobs:
slack-action:
#if: ${{ false }}
runs-on: ubuntu-20.04
name: Test 10 [ubuntu-20.04]

Expand Down Expand Up @@ -36,5 +37,5 @@ jobs:
slack-function: update-message
slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }}
slack-channel: C036UR31LTD
slack-update-message-text: "${{ format('{0}\n\n```{1}```', ':no_entry_sign: Build status: Failed!', steps.fake-build-process.outputs.BUILD_RESULT) }}"
slack-update-message-ts: ${{ fromJson(steps.slack-build-started.outputs.slack-result).response.message.ts }}
slack-update-message-text: "${{ format('{0}\n\n```{1}```', ':no_entry_sign: Build status: Failed!', steps.fake-build-process.outputs.BUILD_RESULT) }}"
52 changes: 52 additions & 0 deletions .github/workflows/11-slack-message-blocks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: test-11-slack-message-blocks

on: [push, issues]

jobs:
slack-action:
#if: ${{ false }}
runs-on: ubuntu-20.04
name: Test 11 [ubuntu-20.04]

steps:
- name: Send Slack Message (Blocks)
uses: archive/github-actions-slack@update_message_with_blocks
id: send-message
with:
slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }}
slack-channel: C046J5U2RGC
slack-blocks: >-
[
{
"block_id": "text1",
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Building repo *product-service*"
}
},
{
"type": "divider"
},
{
"block_id": "text2",
"type": "context",
"elements": [
{
"type": "image",
"image_url": "https://upload.wikimedia.org/wikipedia/en/thumb/4/4c/Flag_of_Sweden.svg/1200px-Flag_of_Sweden.svg.png",
"alt_text": "images"
},
{
"type": "plain_text",
"text": "Estimated time: 1 min"
}
]
},
{
"type": "divider"
}
]

- name: Result from "Send Slack Message"
run: echo '${{ steps.send-message.outputs.slack-result }}'
51 changes: 51 additions & 0 deletions .github/workflows/12-slack-message-blocks-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: test-12-slack-message-blocks-update

on: [push, issues]

jobs:
slack-action:
#if: ${{ false }}
runs-on: ubuntu-20.04
name: Test 12 [ubuntu-20.04]

steps:
- name: Send Slack Message (Blocks)
uses: archive/github-actions-slack@update_message_with_blocks
id: send-message
with:
slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }}
slack-channel: C046FKM3TNF
slack-blocks: >-
[
{
"block_id": "text1",
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Building... *please wait*"
}
}
]

- name: Result from "Send Slack Message"
run: echo '${{ steps.send-message.outputs.slack-result }}'

- name: Send Slack Message (Blocks) - Update
uses: archive/github-actions-slack@update_message_with_blocks
id: send-message-update
with:
slack-function: update-message
slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }}
slack-channel: C046FKM3TNF
slack-update-message-ts: ${{ fromJson(steps.send-message.outputs.slack-result).response.message.ts }}
slack-update-message-blocks: >-
[
{
"block_id": "text1",
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Building... *done!*"
}
}
]
1 change: 1 addition & 0 deletions .github/workflows/2-slack-notification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: [push]

jobs:
slack-action:
#if: ${{ false }}
runs-on: windows-latest
name: Test 2 [windows-latest]

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/3-slack-reaction.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: [push]

jobs:
slack-action:
#if: ${{ false }}
runs-on: ubuntu-latest
name: Test 3 [ubuntu-latest]

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/4-slack-thread.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: [push]

jobs:
slack-action:
#if: ${{ false }}
runs-on: macos-latest
name: Test 4 [macos-latest]

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/5-slack-update-message.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: [push]

jobs:
slack-action:
#if: ${{ false }}
runs-on: ubuntu-20.04
name: Test 5 [ubuntu-20.04]

Expand All @@ -30,8 +31,8 @@ jobs:
slack-function: update-message
slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }}
slack-channel: ${{ fromJson(steps.send-message.outputs.slack-result).response.channel }}
slack-update-message-text: Test 5.1 - Message to update - updated
slack-update-message-ts: ${{ fromJson(steps.send-message.outputs.slack-result).response.message.ts }}
slack-update-message-text: Test 5.1 - Message to update - updated

- name: Send Slack Reaction To Message Result
run: echo 'Data - ${{ steps.send-message.outputs.slack-result }}'
1 change: 1 addition & 0 deletions .github/workflows/6-slack-thread-with-broadcast.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: [push]

jobs:
slack-action:
#if: ${{ false }}
runs-on: ubuntu-20.04
name: Test 6 [ubuntu-20.04]

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/7-slack-notification-multi-channel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: [push]

jobs:
slack-action:
#if: ${{ false }}
runs-on: windows-2019
name: Test 7 [windows-2019]

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/8-slack-notification-line-breaks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: [push]

jobs:
slack-action:
#if: ${{ false }}
runs-on: windows-latest
name: Test 8 [windows-latest]

Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/9-slack-update-message-line-breaks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: [push]

jobs:
slack-action:
#if: ${{ false }}
runs-on: ubuntu-latest
name: Test 9 [ubuntu-latest]

Expand All @@ -27,13 +28,13 @@ jobs:
slack-function: update-message
slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }}
slack-channel: ${{ fromJson(steps.send-message-1.outputs.slack-result).response.channel }}
slack-update-message-ts: ${{ fromJson(steps.send-message-1.outputs.slack-result).response.message.ts }}
slack-update-message-text: |
Test 9.1 - 1/2

Message to update

Updated!
slack-update-message-ts: ${{ fromJson(steps.send-message-1.outputs.slack-result).response.message.ts }}

- name: Send Slack Reaction To Message Result
run: echo 'Data - ${{ steps.send-message-1.outputs.slack-result }}'
Expand Down Expand Up @@ -62,8 +63,8 @@ jobs:
slack-function: update-message
slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }}
slack-channel: ${{ fromJson(steps.send-message-2.outputs.slack-result).response.channel }}
slack-update-message-text: "${{ format('{0}\n\n{1}', 'Test 9.1 - 2/2', toJson(runner)) }}"
slack-update-message-ts: ${{ fromJson(steps.send-message-2.outputs.slack-result).response.message.ts }}
slack-update-message-text: "${{ format('{0}\n\n{1}', 'Test 9.1 - 2/2', toJson(runner)) }}"

- name: Send Slack Reaction To Message Result
run: echo 'Data - ${{ steps.send-message-2.outputs.slack-result }}'
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Github Action for sending message (and reactions/threads/update) to Slack
# Github Action for sending message (and reactions/threads/update/blocks) to Slack

— With support for Slack's optional arguments

Expand All @@ -7,7 +7,7 @@
![](https://api.codiga.io/project/30889/status/svg)
![](https://api.codiga.io/project/30889/score/svg)

This Action allows you to send messages (and reactions/threads/update) to Slack from your Github Actions. Supports Slack's required arguments as well as all the optional once. It's JavaScript-based and thus fast to run.
This Action allows you to send messages (and reactions/threads/update/blocks) to Slack from your Github Actions. Supports Slack's required arguments as well as all the optional once. It's JavaScript-based and thus fast to run.

![Slack result](./images/slack-result.png "Slack result")

Expand Down Expand Up @@ -49,7 +49,7 @@ This action supports:

- `slack-channel` - The channel/channels where you want the message (comma separated)

- `slack-text` - The text of the message
- `slack-text` - The text of the message (or use `slack-blocks`)

**Optional: Github Action Parameters:**

Expand Down Expand Up @@ -291,6 +291,15 @@ Similar to Add Reaction, but with text instead.

Please see [.github/workflows/5-slack-update-message.yml](.github/workflows/5-slack-update-message.yml)

## 5. Using blocks

With blocks you can create more rich and complex messages / message layouts: https://api.slack.com/messaging/composing/layouts

For some examples, please see:

- [.github/workflows/11-slack-message-blocks.yml](.github/workflows/11-slack-message-blocks.yml)
- [.github/workflows/12-slack-message-blocks-update.yml](.github/workflows/12-slack-message-blocks-update.yml)

## How to setup your first Github Action in your repository that will call this Action

### 1. Create a Slack bot
Expand Down
8 changes: 7 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ inputs:
required: true
slack-text:
description: "Text"
required: true
required: false
slack-blocks:
description: "Blocks"
required: false
slack-optional-as_user:
description: "https://api.slack.com/methods/chat.postMessage#arg_as_user"
required: false
Expand Down Expand Up @@ -67,6 +70,9 @@ inputs:
slack-update-message-text:
description: https://api.slack.com/methods/chat.update#text
required: false
slack-update-message-blocks:
description: https://api.slack.com/methods/chat.update#blocks
required: false

outputs:
slack-result:
Expand Down
Loading