-
Notifications
You must be signed in to change notification settings - Fork 178
feat: add Slack CLI command runner workflow and installer composite action #486
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| name: Slack CLI Installation | ||
| description: Download and cache the Slack CLI | ||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Cache Slack CLI | ||
| id: cache-cli | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: ~/.slack/bin | ||
| key: slack-cli-${{ runner.os }}-${{ runner.arch }}-${{ env.SLACK_CLI_VERSION }} | ||
|
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. Nice 💯 |
||
|
|
||
| - name: Add Slack CLI to PATH (Linux/macOS) | ||
| if: runner.os != 'Windows' | ||
|
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. Why do we opt to use Could we potentially merge these steps?
Author
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.
|
||
| shell: bash | ||
| run: echo "$HOME/.slack/bin" >> "$GITHUB_PATH" | ||
|
|
||
| - name: Add Slack CLI to PATH (Windows) | ||
| if: runner.os == 'Windows' | ||
| shell: pwsh | ||
| run: Add-Content -Path $env:GITHUB_PATH -Value "$env:USERPROFILE\.slack\bin" | ||
|
|
||
| - name: Install Slack CLI (Linux/macOS) | ||
| if: | ||
| (runner.os == 'Linux' || runner.os == 'macOS') && steps.cache-cli.outputs.cache-hit != 'true' | ||
| shell: bash | ||
| run: | ||
| curl -fsSL https://downloads.slack-edge.com/slack-cli/install.sh | bash -s -- -v $SLACK_CLI_VERSION | ||
|
|
||
| - name: Install Slack CLI (Windows) | ||
| if: runner.os == 'Windows' && steps.cache-cli.outputs.cache-hit != 'true' | ||
| shell: pwsh | ||
| run: | | ||
| irm https://downloads.slack-edge.com/slack-cli/install-windows-dev.ps1 -OutFile 'install-windows-dev.ps1' | ||
| .\install-windows-dev.ps1 -Version $env:SLACK_CLI_VERSION | ||
|
Member
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. 🧪 thought: It might be best to include this technique as part of existing tests workflow? I'm hoping with a composite action setup we could perhaps test the CLI
Author
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. Ah yes definitely more testing on the next iteration 😊 |
| Original file line number | Diff line number | Diff line change | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,43 @@ | |||||||||||||||||
| name: Slack CLI Command Runner | |||||||||||||||||
|
|
|||||||||||||||||
| on: | |||||||||||||||||
| workflow_dispatch: | |||||||||||||||||
| inputs: | |||||||||||||||||
| command: | |||||||||||||||||
| description: 'Slack CLI command to run' | |||||||||||||||||
| required: true | |||||||||||||||||
|
|
|||||||||||||||||
| jobs: | |||||||||||||||||
| deploy: | |||||||||||||||||
| name: "Run Slack CLI command" | |||||||||||||||||
| runs-on: ubuntu-latest | |||||||||||||||||
| env: | |||||||||||||||||
| SLACK_CLI_VERSION: "3.5.2" | |||||||||||||||||
| timeout-minutes: 10 | |||||||||||||||||
|
|
|||||||||||||||||
| defaults: | |||||||||||||||||
| run: | |||||||||||||||||
| shell: bash | |||||||||||||||||
|
|
|||||||||||||||||
| steps: | |||||||||||||||||
| - name: Checkout | |||||||||||||||||
| uses: actions/checkout@v4 | |||||||||||||||||
|
|
|||||||||||||||||
| - name: Install Slack CLI | |||||||||||||||||
| uses: ./.github/resources/.actions/slack-cli-installer | |||||||||||||||||
|
|
|||||||||||||||||
| - name: Setup Node.js | |||||||||||||||||
| uses: actions/setup-node@v4 | |||||||||||||||||
| with: | |||||||||||||||||
| node-version: 18 | |||||||||||||||||
|
|
|||||||||||||||||
| - name: Install dependencies | |||||||||||||||||
| run: npm install shell-quote | |||||||||||||||||
|
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. Based on our discussion and the way we are using this dependency, it may end up being removed, but if we do keep it then we should pin it to a specific version and find a way to easily update it. Dependabot might be useful for this |
|||||||||||||||||
|
|
|||||||||||||||||
| - name: Execute command via script | |||||||||||||||||
| run: | | |||||||||||||||||
| echo "Running command: ${{ github.event.inputs.command }}" | |||||||||||||||||
| node src/parse-command.js ${{ github.event.inputs.command }} | |||||||||||||||||
| env: | |||||||||||||||||
| SLACK_SERVICE_TOKEN: ${{ secrets.SLACK_SERVICE_TOKEN }} | |||||||||||||||||
| SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | |||||||||||||||||
|
Comment on lines
+12
to
+43
Check warningCode scanning / CodeQL Workflow does not contain permissions Medium
Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
Copilot AutofixAI 5 months ago To fix the problem, add a
Suggested changeset
1
.github/workflows/slack-cli-command.yml
Copilot is powered by AI and may make mistakes. Always verify output.
Refresh and try again.
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. In the case of
Author
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. Based on the docs, tokens stored in GitHub secrets or set in the workflow file takes precedence over variables stored in configuration files. |
|||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| const { parse: _parse } = require('shell-quote'); | ||
| const { execFile } = require('child_process'); | ||
|
|
||
| async function parse(rawInput) { | ||
| let tokens; | ||
| try { | ||
| tokens = _parse(rawInput); | ||
| } catch (err) { | ||
| throw Error("Invalid syntax: command contains at least one NULL character"); | ||
| } | ||
|
|
||
| if (tokens.length === 0) { | ||
| throw Error("No command provided"); | ||
| } | ||
|
|
||
| console.log('Executing the command:', tokens.join(' ')); | ||
|
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. In a follow up PR it could be nice to have this script follow the same logging level approach as it does with the |
||
| const args = tokens.slice(1); | ||
|
|
||
| execFile('slack', args, (error, stdout) => { | ||
| if (error) { | ||
| throw Error(`Slack CLI Error: ${error.message}`); | ||
| } | ||
| console.log(stdout); | ||
|
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. Should we log What happens if the error does not have a
Author
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.
|
||
| }); | ||
| } | ||
|
|
||
| if (require.main === module) { | ||
| const rawInput = process.argv.slice(2).join(' '); | ||
| parse(rawInput); | ||
| } | ||
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.
👁️🗨️ suggestion: We might want to move these steps to
action.ymlas part of the compositisation of this action!