-
Notifications
You must be signed in to change notification settings - Fork 181
feat: support slack cli commands with composite action inputs #560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
zimeg
wants to merge
18
commits into
main
Choose a base branch
from
cli
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ae50e2e
feat: cli
zimeg 165d9f6
feat: cli
zimeg 2d8c996
fix: echo output
zimeg 077f882
ci: use development build
zimeg 35b8102
fix: add to windows path
zimeg 5d5197b
ci: remove feature build cli version
zimeg 613ab73
test: verbose version
zimeg 47ed37c
fix: run windows build in powershell
zimeg 4e7d5d3
ci: dev
zimeg f50140b
ci: debug
zimeg b48e5cf
ci: tee output
zimeg 32371dd
test: write empty credentials for windows tests for io speed
zimeg 059f8f3
test: attempt to create all windows files or quit
zimeg eaed8db
build: use .net api for better diagnostics
zimeg 65f25ff
test: remove debug from windows
zimeg 4b307de
chore: remove verbose flag option
zimeg 2d3baa1
fix: remove duplicate output for unix
zimeg c6baa4b
test: improve checks of existing cache or path
zimeg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,146 @@ | ||||||
| name: "Slack: Run CLI Command" | ||||||
| author: "slackapi" | ||||||
| description: "Install the Slack CLI and run a command in a GitHub Actions workflow" | ||||||
| inputs: | ||||||
| command: | ||||||
| description: "A Slack CLI command to run without the 'slack' prefix." | ||||||
| required: true | ||||||
| token: | ||||||
| description: "A service token passed as the '--token' flag to the CLI command." | ||||||
| required: false | ||||||
| version: | ||||||
| description: "The version of the Slack CLI to install. Defaults to the latest." | ||||||
| required: false | ||||||
| outputs: | ||||||
| ok: | ||||||
| description: "If the command completed with a '0' exit code." | ||||||
| value: ${{ steps.slack-cli-unix.outputs.ok || steps.slack-cli-windows.outputs.ok }} | ||||||
| response: | ||||||
| description: "The standard output from the CLI command." | ||||||
| value: ${{ steps.slack-cli-unix.outputs.response || steps.slack-cli-windows.outputs.response }} | ||||||
| time: | ||||||
| description: "The Unix epoch time that the step completed." | ||||||
| value: ${{ steps.slack-cli-unix.outputs.time || steps.slack-cli-windows.outputs.time }} | ||||||
| runs: | ||||||
| using: composite | ||||||
| steps: | ||||||
| - name: Check if Slack CLI already exists | ||||||
| id: slack-cli-check | ||||||
| shell: bash | ||||||
| run: | | ||||||
| if command -v slack &> /dev/null; then | ||||||
| echo "exists=true" >> "$GITHUB_OUTPUT" | ||||||
| else | ||||||
| echo "exists=false" >> "$GITHUB_OUTPUT" | ||||||
| fi | ||||||
|
|
||||||
| - name: Cache Slack CLI | ||||||
| if: steps.slack-cli-check.outputs.exists != 'true' | ||||||
| id: cache-cli | ||||||
| uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 | ||||||
| with: | ||||||
| path: | | ||||||
| ${{ runner.os == 'Windows' && format('{0}\AppData\Local\slack-cli', env.USERPROFILE) || format('{0}/.slack/bin', env.HOME) }} | ||||||
| key: slack-cli-${{ runner.os }}-${{ runner.arch }}-${{ inputs.version }} | ||||||
|
|
||||||
| - name: Add Slack CLI to PATH | ||||||
| if: steps.slack-cli-check.outputs.exists != 'true' && runner.os != 'Windows' | ||||||
| shell: bash | ||||||
| run: echo "$HOME/.slack/bin" >> "$GITHUB_PATH" # zizmor: ignore[github-env] | ||||||
|
|
||||||
| - name: Add Slack CLI to PATH | ||||||
| if: steps.slack-cli-check.outputs.exists != 'true' && runner.os == 'Windows' | ||||||
| shell: pwsh | ||||||
| run: Add-Content -Path $env:GITHUB_PATH -Value "$env:USERPROFILE\AppData\Local\slack-cli\bin" # zizmor: ignore[github-env] | ||||||
|
Comment on lines
+46
to
+54
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clever 💯 |
||||||
|
|
||||||
| - name: Install Slack CLI | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit
Suggested change
|
||||||
| if: >- | ||||||
| steps.slack-cli-check.outputs.exists != 'true' && | ||||||
| steps.cache-cli.outputs.cache-hit != 'true' && | ||||||
| runner.os != 'Windows' | ||||||
| shell: bash | ||||||
| run: | | ||||||
| if [ -n "$SLACK_CLI_VERSION" ]; then | ||||||
| curl -fsSL https://downloads.slack-edge.com/slack-cli/install.sh | bash -s -- -v "$SLACK_CLI_VERSION" | ||||||
| else | ||||||
| curl -fsSL https://downloads.slack-edge.com/slack-cli/install.sh | bash -s | ||||||
| fi | ||||||
| env: | ||||||
| SLACK_CLI_VERSION: ${{ inputs.version }} | ||||||
|
|
||||||
| - name: Install Slack CLI | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit
Suggested change
|
||||||
| if: >- | ||||||
| steps.slack-cli-check.outputs.exists != 'true' && | ||||||
| steps.cache-cli.outputs.cache-hit != 'true' && | ||||||
| runner.os == 'Windows' | ||||||
| shell: pwsh | ||||||
| run: | | ||||||
| if ($env:SLACK_CLI_VERSION) { | ||||||
| $installer = Join-Path $env:TEMP "install-slack-cli.ps1" | ||||||
| Invoke-WebRequest -Uri "https://downloads.slack-edge.com/slack-cli/install-windows-dev.ps1" -OutFile $installer | ||||||
| & $installer -v $env:SLACK_CLI_VERSION | ||||||
| } else { | ||||||
| irm https://downloads.slack-edge.com/slack-cli/install-windows-dev.ps1 | iex | ||||||
| } | ||||||
| env: | ||||||
| SLACK_CLI_VERSION: ${{ inputs.version }} | ||||||
|
|
||||||
| - name: Run Slack CLI command | ||||||
| if: runner.os != 'Windows' | ||||||
| id: slack-cli-unix | ||||||
| shell: bash | ||||||
| env: | ||||||
| SLACK_COMMAND: ${{ inputs.command }} | ||||||
| SLACK_TOKEN: ${{ inputs.token }} | ||||||
| run: | | ||||||
| args="$SLACK_COMMAND --skip-update" | ||||||
| if [ -n "$SLACK_TOKEN" ]; then | ||||||
| args="$args --token $SLACK_TOKEN" | ||||||
| fi | ||||||
|
|
||||||
| set +e | ||||||
| output=$(slack $args 2>&1 | tee /dev/stderr) | ||||||
| exit_code=$? | ||||||
| set -e | ||||||
|
|
||||||
| echo "ok=$([ $exit_code -eq 0 ] && echo 'true' || echo 'false')" >> "$GITHUB_OUTPUT" | ||||||
| echo "time=$(date +%s)" >> "$GITHUB_OUTPUT" | ||||||
|
|
||||||
| echo "response<<SLACKCLIEOF" >> "$GITHUB_OUTPUT" | ||||||
| echo "$output" >> "$GITHUB_OUTPUT" | ||||||
| echo "SLACKCLIEOF" >> "$GITHUB_OUTPUT" | ||||||
|
|
||||||
| if [ $exit_code -ne 0 ]; then | ||||||
| echo "::error::Slack CLI command failed with exit code $exit_code" | ||||||
| exit $exit_code | ||||||
| fi | ||||||
|
|
||||||
| - name: Run Slack CLI command | ||||||
| if: runner.os == 'Windows' | ||||||
| id: slack-cli-windows | ||||||
| shell: pwsh | ||||||
| env: | ||||||
| SLACK_COMMAND: ${{ inputs.command }} | ||||||
| SLACK_TOKEN: ${{ inputs.token }} | ||||||
| run: | | ||||||
| $cliArgs = "$env:SLACK_COMMAND --skip-update" | ||||||
| if ($env:SLACK_TOKEN) { | ||||||
| $cliArgs = "$cliArgs --token $env:SLACK_TOKEN" | ||||||
| } | ||||||
|
|
||||||
| $outputFile = New-TemporaryFile | ||||||
| slack $cliArgs.Split(' ') 2>&1 | Tee-Object -FilePath $outputFile.FullName | ||||||
| $exit_code = $LASTEXITCODE | ||||||
| $output = Get-Content $outputFile.FullName -Raw | ||||||
|
|
||||||
| "ok=$( if ($exit_code -eq 0) { 'true' } else { 'false' } )" >> $env:GITHUB_OUTPUT | ||||||
| "time=$([DateTimeOffset]::UtcNow.ToUnixTimeSeconds())" >> $env:GITHUB_OUTPUT | ||||||
|
|
||||||
| "response<<SLACKCLIEOF" >> $env:GITHUB_OUTPUT | ||||||
| $output >> $env:GITHUB_OUTPUT | ||||||
| "SLACKCLIEOF" >> $env:GITHUB_OUTPUT | ||||||
|
|
||||||
| if ($exit_code -ne 0) { | ||||||
| Write-Output "::error::Slack CLI command failed with exit code $exit_code" | ||||||
| exit $exit_code | ||||||
| } | ||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 💯