feat!: wrap payloads to send to a "method" with "token" or "webhook" #628
This file contains 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
name: Tests | |
on: | |
pull_request: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
tests: | |
name: Run tests | |
runs-on: ubuntu-latest | |
environment: staging | |
steps: | |
- name: "build: checkout the latest changes" | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: "build: install the required dependencies" | |
run: npm ci | |
- name: "build: setup the linter for formatting checks" | |
uses: biomejs/setup-biome@v2 | |
with: | |
version: latest | |
- name: "unit(test): perform lints and formatting checks" | |
run: biome ci . | |
- name: "unit(test): perform check of typings" | |
run: npm run check | |
- name: "unit(test): perform unit test checks" | |
run: npm test | |
- name: "unit(test): upload coverage to CodeCov" | |
uses: codecov/codecov-action@v4.5.0 | |
with: | |
directory: ./coverage | |
token: ${{ secrets.CODECOV_TOKEN }} | |
- name: "integration(botToken): post a message to channel" | |
id: slackToken | |
uses: ./ | |
with: | |
method: chat.postMessage | |
token: ${{ secrets.SLACK_BOT_TOKEN }} | |
payload: | | |
channel: ${{ secrets.SLACK_CHANNEL_ID }} | |
text: "CI Post from slack-send GitHub Action! Succeeded!!" | |
- name: "integration(botToken): confirm a message was posted" | |
run: test -n "${{ steps.slackToken.outputs.ts }}" | |
- name: "integration(botToken): post a threaded response" | |
id: slackThreadResponse | |
uses: ./ | |
with: | |
method: chat.postMessage | |
token: ${{ secrets.SLACK_BOT_TOKEN }} | |
payload: | | |
channel: ${{ secrets.SLACK_CHANNEL_ID }} | |
text: "This message should be posted as a response in thread" | |
thread_ts: ${{ steps.slackToken.outputs.thread_ts }} | |
- name: "integration(botToken): confirm a response was posted" | |
run: test -n "${{ steps.slackThreadResponse.outputs.ts }}" | |
- name: "integration(wfb): save the push event trigger commit URL" | |
if: "contains(github.event_name, 'push')" | |
run: | | |
url=${{ github.event.head_commit.url }} | |
echo "URL=$url" >> "$GITHUB_ENV" | |
- name: "integration(wfb): save the pull request event trigger commit URL" | |
if: "contains(github.event_name, 'pull_request')" | |
run: | | |
url=${{ github.event.pull_request.url }} | |
echo "URL=$url" >> "$GITHUB_ENV" | |
- name: "integration(wfb): send a payload via workflow builder webhook" | |
id: slackWorkflow | |
uses: ./ | |
with: | |
# Workflow builder webhooks need to know the name of the keys in the payload in advance. Without normalizing, the github context payload keys can differ based on the GitHub trigger event type | |
# Normalized payload with info pulled out from GitHub trigger event | |
payload: '{"author":"${{ github.event.sender.login }}","url":"${{ env.URL}}", "repoName":"${{ github.event.repository.full_name }}", "status":"${{ job.status }}"}' | |
webhook: ${{ secrets.SLACK_WEBHOOK_URL }} | |
- name: "integration(wfb): confirm a payload was sent" | |
run: test -n "${{ steps.slackWorkflow.outputs.time }}" | |
- name: "integration(incoming): post a message via incoming webhook" | |
id: slackIncoming | |
uses: ./ | |
with: | |
webhook: ${{ secrets.SLACK_INCOMING_WEBHOOK_URL }} | |
payload: | | |
text: "Incoming Webhook test for slack send" | |
blocks: | |
- type: section | |
text: | |
type: plain_text | |
text: "A post by Slack Send GitHub Action. Testing Incoming webhooks" | |
emoji: true | |
- name: "integration(incoming): confirm a webhook was posted" | |
run: test -n "${{ steps.slackIncoming.outputs.time }}" | |
- name: "integration(incoming): reveal contents of the github payload" | |
run: echo $JSON | |
env: | |
JSON: ${{ toJSON(github) }} | |
- name: "integration(incoming): post a message via payload file" | |
id: slackPayloadFile | |
uses: ./ | |
with: | |
payload-file-path: ./.github/resources/payload-notification.json | |
webhook: ${{ secrets.SLACK_INCOMING_WEBHOOK_URL }} | |
env: | |
JOB_STATUS: ${{ job.status }} | |
ATTACHMENT_COLOR: ${{ (job.status == 'success' && 'good') || (job.status == 'failure' && 'danger') || 'warning' }} | |
- name: "integration(incoming): confirm a payload file was posted" | |
run: test -n "${{ steps.slackPayloadFile.outputs.time }}" |