-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathaction.yml
More file actions
150 lines (135 loc) · 5.28 KB
/
action.yml
File metadata and controls
150 lines (135 loc) · 5.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
name: "The Slack GitHub Action: CLI"
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' && inputs.version != ''
id: cache-cli
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
with:
path: |
${{ runner.os == 'Windows' && '~/AppData/Local/slack-cli' || '~/.slack/bin' }}
key: slack-cli-${{ runner.os }}-${{ runner.arch }}-${{ inputs.version }}
- name: Bash 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: Pwsh 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]
- name: Bash Install Slack CLI
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: Pwsh Install Slack CLI
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.ps1" -OutFile $installer
& $installer -v $env:SLACK_CLI_VERSION
} else {
irm https://downloads.slack-edge.com/slack-cli/install-windows.ps1 | iex
}
env:
SLACK_CLI_VERSION: ${{ inputs.version }}
- name: Bash Run Slack CLI command
id: slack-cli-unix
if: runner.os != 'Windows'
shell: bash
env:
SLACK_COMMAND: ${{ inputs.command }}
SLACK_TOKEN: ${{ inputs.token }}
run: |
args="$SLACK_COMMAND --skip-update"
if [ "$RUNNER_DEBUG" = "1" ]; then
args="$args --verbose"
fi
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
exit $exit_code
fi
- name: Pwsh Run Slack CLI command
id: slack-cli-windows
if: runner.os == 'Windows'
shell: pwsh
env:
SLACK_COMMAND: ${{ inputs.command }}
SLACK_TOKEN: ${{ inputs.token }}
run: |
$cliArgs = "$env:SLACK_COMMAND --skip-update"
if ($env:RUNNER_DEBUG -eq "1") {
$cliArgs = "$cliArgs --verbose"
}
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) {
exit $exit_code
}