-
Notifications
You must be signed in to change notification settings - Fork 149
138 lines (127 loc) · 4.79 KB
/
main.yml
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
name: Tests
on:
pull_request_target:
push:
branches:
- main
jobs:
unit_tests:
runs-on: ubuntu-latest
environment: staging
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- run: npm ci && npm run build
- run: npm test
integration_test_botToken:
runs-on: ubuntu-latest
environment: staging
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- run: npm ci && npm run build
- name: Post message to Slack via botToken
id: slackToken
uses: ./
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
slack-message: 'CI Post from slack-send GitHub Action! Succeeded!!'
# payload: "{\"key\":\"value\",\"foo\":\"bar\"}"
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
# Use the output from the `slackToken` step
- name: Check Action output is not empty
run: test -n "${{ steps.slackToken.outputs.time }}"
- name: Post 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 }}
integration_test_webhook:
runs-on: ubuntu-latest
environment: staging
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- run: npm ci && npm run build
- run: echo "${{ github.event_name }}"
- name: push trigger
# Save commit url from GitHub Trigger event payload to URL env
if: "contains(github.event_name, 'push')"
run: |
url=${{ github.event.head_commit.url }}
echo "URL=$url" >> "$GITHUB_ENV"
- name: pull request trigger
# Save pull request url from GitHub Trigger event payload to URL env
if: "contains(github.event_name, 'pull_request')"
run: |
url=${{ github.event.pull_request.url }}
echo "URL=$url" >> "$GITHUB_ENV"
- name: Post message to Slack via 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 }}
# Use the output from the `slackWorkflow` step
- name: Check Action output is not empty
run: test -n "${{ steps.slackWorkflow.outputs.time }}"
integration_test_incoming_webhook:
runs-on: ubuntu-latest
environment: staging
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- run: npm ci && npm run build
- run: echo "${{ github.event_name }}"
- name: Post message to Slack via incoming webhook
id: slackIncoming
uses: ./
with:
# block kit payload
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
# Use the output from the `slackIncoming` step
- name: Check Action output is not empty
run: test -n "${{ steps.slackIncoming.outputs.time }}"
integration_test_file_payload:
runs-on: ubuntu-latest
environment: staging
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- run: npm ci && npm run build
- name: Dump out GitHub Context
run: echo $JSON
env:
JSON: ${{ toJSON(github) }}
- name: Post message to Slack with Payload path
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' }}
# Use the output from the `slackIncoming` step
- name: Check Action output is not empty
run: test -n "${{ steps.slackPayloadFile.outputs.time }}"