Skip to content

Commit e45cb89

Browse files
zimegClaudeWilliamBergamin
authored
feat: support slack cli commands with composite action inputs (#560)
Co-authored-by: Claude <svc-devxp-claude@slack-corp.com> Co-authored-by: William Bergamin <wbergamin@slack-corp.com>
1 parent 0aed2c2 commit e45cb89

File tree

22 files changed

+572
-39
lines changed

22 files changed

+572
-39
lines changed

.github/resources/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
export SLACK_BOT_TOKEN=xoxb-01010101-example
55
export SLACK_CHANNEL_ID=C0123456789
66
export SLACK_INCOMING_WEBHOOK=https://hooks.slack.com/services/T0123456789/B0123456789/abcdefghijklmnopqrstuvwxyz
7+
export SLACK_SERVICE_TOKEN=xoxp-01010101-example
78
export SLACK_WEBHOOK_TRIGGER=https://hooks.slack.com/triggers/T0123456789/00000000000/abcdefghijklmnopqrstuvwxyz
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
2-
"experiments": ["bolt"],
2+
"manifest": {
3+
"source": "local"
4+
},
35
"project_id": "c4805b41-d1ce-4ea0-b297-ed2f8c64c267"
46
}
57

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"runtime": "actions",
33
"hooks": {
4-
"deploy": "open https://api.slack.com/apps || true",
4+
"deploy": "echo https://api.slack.com/apps",
55
"get-manifest": "cat ./.slack/manifest.json #"
66
},
77
"config": {

.github/resources/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ experiments with the [Slack CLI][cli].
66

77
## Overview
88

9-
This app showcases all three techniques of sending data into Slack and follows
9+
This app showcases all four techniques of interacting with Slack and follows
1010
patterns found in the integration tests.
1111

1212
- **Technique 1** Slack Workflow Builder: Use a Slack webhook trigger to start a
@@ -15,13 +15,18 @@ patterns found in the integration tests.
1515
data provided through the GitHub workflow.
1616
- **Technique 3** Incoming webhook: Post a message to a Slack channel using an
1717
incoming webhook.
18+
- **Technique 4** Slack CLI Command: Install and run Slack CLI commands such as
19+
`deploy` or `manifest` using a service token.
1820

1921
Configurations for the Slack app and workflow, and the GitHub Actions workflow
2022
are found in the following files:
2123

2224
- Slack app setup: [`.github/resources/.slack/manifest.json`][slacktion]
2325
- GitHub Actions steps: [`.github/workflows/develop.yml`][develop]
2426

27+
> **Note:** During CLI integration tests, `.github/resources/.slack` is moved to
28+
> `.slack` at the project root so the Slack CLI can discover the app manifest.
29+
2530
Either the techniques or app setup and workflow steps can be adjusted during
2631
testing and development. For experimenting with new changes, we recommend using
2732
the [steps for development](#experimenting-for-development) while the
@@ -76,6 +81,8 @@ tested. Required values include:
7681
https://hooks.slack.com/services/T0123456789/B0123456789/abcdefghijklmnopqrstuvwxyz
7782
- `SLACK_WEBHOOK_TRIGGER`:
7883
https://hooks.slack.com/triggers/T0123456789/00000000000/abcdefghijklmnopqrstuvwxyz
84+
- `SLACK_SERVICE_TOKEN`: xoxp-service-token-example (secret — for CLI commands)
85+
- `SLACK_APP_ID`: A0123456789 (variable — used with `--app` flag in CLI deploy)
7986

8087
### Experimenting for development
8188

@@ -98,6 +105,7 @@ export SLACK_BOT_TOKEN=xoxb-01010101-example
98105
export SLACK_CHANNEL_ID=C0123456789
99106
export SLACK_INCOMING_WEBHOOK=https://hooks.slack.com/services/T0123456789/B0123456789/abcdefghijklmnopqrstuvwxyz
100107
export SLACK_WEBHOOK_TRIGGER=https://hooks.slack.com/triggers/T0123456789/00000000000/abcdefghijklmnopqrstuvwxyz
108+
export SLACK_SERVICE_TOKEN=xoxp-service-token-example
101109
```
102110

103111
Environment variables and credentials should be set in the created `.env` file

.github/workflows/integration.yml

Lines changed: 92 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212

1313
jobs:
1414
integration:
15-
name: Run integration tests
15+
name: Run API tests
1616
runs-on: ubuntu-latest
1717
environment: staging
1818
permissions:
@@ -68,7 +68,7 @@ jobs:
6868
env:
6969
INPUT_REF: ${{ inputs.ref }}
7070

71-
- name: "integration(wfb): send a payload to workflow builder via webhook trigger"
71+
- name: "test(wfb): send a payload to workflow builder via webhook trigger"
7272
id: wfb
7373
uses: ./
7474
with:
@@ -82,12 +82,12 @@ jobs:
8282
repo_name: ${{ github.event.repository.full_name }}
8383
status: ${{ job.status }}
8484
85-
- name: "integration(wfb): confirm a payload was sent"
85+
- name: "test(wfb): confirm a payload was sent"
8686
run: test -n "$WFB_OUTPUT_TIME"
8787
env:
8888
WFB_OUTPUT_TIME: ${{ steps.wfb.outputs.time }}
8989

90-
- name: "integration(botToken): post a message to channel"
90+
- name: "test(api): post a message to channel"
9191
id: message
9292
uses: ./
9393
with:
@@ -98,12 +98,12 @@ jobs:
9898
channel: ${{ secrets.SLACK_CHANNEL_ID }}
9999
text: ":checkered_flag: Action happens at <https://github.com/${{ github.repository }}>"
100100
101-
- name: "integration(method): confirm a message was posted"
101+
- name: "test(api): confirm a message was posted"
102102
run: test -n "$MESSAGE_OUTPUT_TS"
103103
env:
104104
MESSAGE_OUTPUT_TS: ${{ steps.message.outputs.ts }}
105105

106-
- name: "integration(method): post a message with blocks"
106+
- name: "test(api): post a message with blocks"
107107
id: blocks
108108
uses: ./
109109
with:
@@ -120,12 +120,12 @@ jobs:
120120
short: true
121121
value: "Processing"
122122
123-
- name: "integration(method): confirm the blocks were posted"
123+
- name: "test(api): confirm the blocks were posted"
124124
run: test -n "$BLOCKS_OUTPUT_TS"
125125
env:
126126
BLOCKS_OUTPUT_TS: ${{ steps.blocks.outputs.ts }}
127127

128-
- name: "integration(method): post a threaded message"
128+
- name: "test(api): post a threaded message"
129129
id: timer
130130
uses: ./
131131
with:
@@ -137,15 +137,15 @@ jobs:
137137
text: "Started at `${{ steps.blocks.outputs.time }}`"
138138
thread_ts: "${{ steps.blocks.outputs.ts }}"
139139
140-
- name: "integration(incoming): confirm the thread started"
140+
- name: "test(api): confirm the thread started"
141141
run: test -n "$TIMER_OUTPUT_TIME"
142142
env:
143143
TIMER_OUTPUT_TIME: ${{ steps.timer.outputs.time }}
144144

145-
- name: "integration(method): wait to mock event processing"
145+
- name: "test(api): wait to mock event processing"
146146
run: sleep 3
147147

148-
- name: "integration(method): update the original message"
148+
- name: "test(api): update the original message"
149149
id: finished
150150
uses: ./
151151
with:
@@ -163,7 +163,7 @@ jobs:
163163
short: true
164164
value: "Completed"
165165
166-
- name: "integration(method): post another threaded message"
166+
- name: "test(api): post another threaded message"
167167
id: done
168168
uses: ./
169169
with:
@@ -175,7 +175,7 @@ jobs:
175175
text: "Finished at `${{ steps.finished.outputs.time }}`"
176176
thread_ts: "${{ steps.timer.outputs.thread_ts }}"
177177
178-
- name: "integration(method): post a file into a channel"
178+
- name: "test(api): post a file into a channel"
179179
id: file
180180
uses: ./
181181
with:
@@ -188,7 +188,7 @@ jobs:
188188
file: .github/workflows/integration.yml
189189
filename: integration.yml
190190
191-
- name: "integration(method): react to the completed update message"
191+
- name: "test(api): react to the completed update message"
192192
uses: ./
193193
with:
194194
errors: true
@@ -199,38 +199,38 @@ jobs:
199199
timestamp: ${{ steps.blocks.outputs.ts }}
200200
name: "tada"
201201
202-
- name: "integration(method): confirm the thread ended"
202+
- name: "test(api): confirm the thread ended"
203203
run: test -n "$DONE_OUTPUT_TIME"
204204
env:
205205
DONE_OUTPUT_TIME: ${{ steps.done.outputs.time }}
206206

207-
- name: "integration(incoming): post a message via incoming webhook"
207+
- name: "test(incoming): post a message via incoming webhook"
208208
id: incoming
209209
uses: ./
210210
with:
211211
errors: true
212212
webhook: ${{ secrets.SLACK_INCOMING_WEBHOOK }}
213213
webhook-type: incoming-webhook
214214
payload: |
215-
text: "Incoming webhook test for slack send"
215+
text: "Incoming webhook test for the Slack GitHub Action"
216216
blocks:
217217
- type: section
218218
text:
219219
type: plain_text
220220
text: ":link: A message was received via incoming webhook"
221221
emoji: true
222222
223-
- name: "integration(incoming): confirm a webhook was posted"
223+
- name: "test(incoming): confirm a webhook was posted"
224224
run: test -n "$INCOMING_WEBHOOK_OUTPUT_TIME"
225225
env:
226226
INCOMING_WEBHOOK_OUTPUT_TIME: ${{ steps.incoming.outputs.time }}
227227

228-
- name: "integration(incoming): reveal contents of the github payload"
228+
- name: "test(incoming): reveal contents of the github payload"
229229
run: echo "$JSON"
230230
env:
231231
JSON: ${{ toJSON(github) }}
232232

233-
- name: "integration(incoming): post a message via payload file"
233+
- name: "test(incoming): post a message via payload file"
234234
id: payload_file
235235
uses: ./
236236
with:
@@ -243,15 +243,80 @@ jobs:
243243
JOB_STATUS: ${{ job.status }}
244244
ATTACHMENT_COLOR: ${{ (job.status == 'success' && 'good') || (job.status == 'failure' && 'danger') || 'warning' }}
245245

246-
- name: "integration(incoming): confirm a payload file was posted"
246+
- name: "test(incoming): confirm a payload file was posted"
247247
run: test -n "$PAYLOAD_FILE_OUTPUT_TIME"
248248
env:
249249
PAYLOAD_FILE_OUTPUT_TIME: ${{ steps.payload_file.outputs.time }}
250250

251-
- name: "chore(health): check up on recent changes to the health score"
252-
uses: slackapi/slack-health-score@d58a419f15cdaff97e9aa7f09f95772830ab66f7 # v0.1.1
251+
cli:
252+
name: Run CLI tests
253+
runs-on: ${{ matrix.os }}
254+
environment: staging
255+
strategy:
256+
fail-fast: false
257+
matrix:
258+
os:
259+
- ubuntu-latest
260+
- macos-latest
261+
- windows-latest
262+
permissions:
263+
contents: read
264+
steps:
265+
- name: "build: checkout the latest changes"
266+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
267+
with:
268+
persist-credentials: false
269+
ref: ${{ inputs.ref || github.event.pull_request.head.sha || github.sha }}
270+
271+
- name: "test(cli): run a slack cli version check"
272+
id: version
273+
uses: ./cli
274+
with:
275+
command: "version"
276+
277+
- name: "test(cli): confirm the version check outputs"
278+
shell: bash
279+
run: |
280+
set -ex
281+
[ "$CLI_OK" = "true" ]
282+
echo "$CLI_TIME" | grep -qE '^[0-9]+$'
283+
[ -n "$CLI_RESPONSE" ]
284+
env:
285+
CLI_OK: ${{ steps.version.outputs.ok }}
286+
CLI_RESPONSE: ${{ steps.version.outputs.response }}
287+
CLI_TIME: ${{ steps.version.outputs.time }}
288+
289+
- name: "test(cli): run an unknown command"
290+
id: unknown
291+
continue-on-error: true
292+
uses: ./cli
293+
with:
294+
command: "off"
295+
296+
- name: "test(cli): confirm the unknown command outputs"
297+
shell: bash
298+
run: |
299+
set -ex
300+
[ "$CLI_OK" = "false" ]
301+
echo "$CLI_TIME" | grep -qE '^[0-9]+$'
302+
[ -n "$CLI_RESPONSE" ]
303+
env:
304+
CLI_OK: ${{ steps.unknown.outputs.ok }}
305+
CLI_RESPONSE: ${{ steps.unknown.outputs.response }}
306+
CLI_TIME: ${{ steps.unknown.outputs.time }}
307+
308+
- name: "chore: configure the actioneering application"
309+
shell: bash
310+
run: mv .github/resources/.slack .slack
311+
312+
- name: "test(cli): validate the app manifest"
313+
uses: ./cli
314+
with:
315+
command: "manifest"
316+
token: ${{ secrets.SLACK_SERVICE_TOKEN }}
317+
318+
- name: "test(cli): deploy the app"
319+
uses: ./cli
253320
with:
254-
codecov_token: ${{ secrets.CODECOV_API_TOKEN }}
255-
github_token: ${{ secrets.GITHUB_TOKEN }}
256-
extension: js
257-
include: src
321+
command: "deploy --app ${{ vars.SLACK_APP_ID }} --hide-triggers --force"
322+
token: ${{ secrets.SLACK_SERVICE_TOKEN }}

.github/workflows/publish.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ jobs:
3838
uses: teunmooij/github-versioned-release@3edf649c6e5e5e976d43f2584b15bdc8b4c8f0df # v1.2.1
3939
with:
4040
template: javascript-action
41+
include: |
42+
dist/**/*
43+
cli/**/*
4144
env:
4245
GITHUB_TOKEN: ${{ github.token }}
4346

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
tests:
11-
name: Run tests
11+
name: Run unit tests
1212
runs-on: ubuntu-latest
1313
permissions:
1414
checks: write

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Slack Send GitHub Action
1+
# Slack GitHub Action
22

3-
> the GitHub Action for sending data to Slack
3+
> the GitHub Action for sending data to Slack and running commands
44
55
[![codecov](https://codecov.io/gh/slackapi/slack-github-action/graph/badge.svg?token=OZNX7FHN78)](https://codecov.io/gh/slackapi/slack-github-action)
66

@@ -11,6 +11,7 @@ Use this GitHub Action to:
1111
- [Send data with a webhook to start a workflow in Workflow Builder](https://docs.slack.dev/tools/slack-github-action/sending-techniques/sending-data-webhook-slack-workflow).
1212
- [Send data using a Slack API method and a secret token with required scopes](https://docs.slack.dev/tools/slack-github-action/sending-techniques/sending-data-slack-api-method/).
1313
- [Send data as a message with a Slack incoming webhook URL](https://docs.slack.dev/tools/slack-github-action/sending-techniques/sending-data-slack-incoming-webhook/).
14+
- [Run Slack CLI commands with a service token](https://docs.slack.dev/tools/slack-github-action/sending-techniques/running-slack-cli-commands/).
1415

1516
## Project details
1617

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
name: "Slack: Send to Slack"
1+
name: "Slack GitHub Action"
22
author: "slackapi"
3-
description: "Send data to Slack to start a Slack workflow in Workflow Builder, call a Slack API method, or post a message into a channel"
3+
description: "Post a message, call a Web API method, start a Slack workflow, or run a Slack CLI command from GitHub Actions"
44
inputs:
55
api:
66
description: "A custom API URL to send Slack API method requests to."

0 commit comments

Comments
 (0)