name: Tests on: pull_request_target: push: branches: - main 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: package the latest changes" run: npm run build - name: "unit(test): perform unit test checks" run: npm test - name: "unit(test): check unit test coverage" run: npm run test:gen-cov - name: "unit(test): upload coverage to CodeCov" uses: codecov/codecov-action@v4.6.0 with: directory: ./coverage token: ${{ secrets.CODECOV_TOKEN }} - name: "integration(botToken): post a message to channel" id: slackToken uses: ./ with: channel-id: ${{ secrets.SLACK_CHANNEL_ID }} slack-message: 'CI Post from slack-send GitHub Action! Succeeded!!' env: SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} - 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: channel-id: ${{ secrets.SLACK_CHANNEL_ID }} payload: | { "text": "This message should be posted as a response in thread", "thread_ts": "${{ steps.slackToken.outputs.thread_ts }}" } env: SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} - 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 }}\"}" env: SLACK_WEBHOOK_URL: ${{ 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: 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}}]}" env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_INCOMING_WEBHOOK_URL }} SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK - 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 env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_INCOMING_WEBHOOK_URL }} SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK 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 }}" - name: "chore(health): check up on recent changes to the health score" uses: slackapi/slack-health-score@v0.1.1 with: codecov_token: ${{ secrets.CODECOV_TOKEN }} github_token: ${{ secrets.GITHUB_TOKEN }} extension: js