-
Notifications
You must be signed in to change notification settings - Fork 206
180 lines (160 loc) · 7.18 KB
/
beamerAndDiscord.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
name: Push Release Notes to Beamer and Discord
on:
workflow_dispatch
jobs:
push-release-notes:
runs-on: ubuntu-latest
steps:
- name: Setup Bolt
uses: koalalab-inc/bolt@v1
- name: Get Latest Release
id: get_latest_release
run: |
python3 -m pip install --upgrade pip
python3 -m pip install requests
python3 - <<EOF
import os
import requests
github_token = os.getenv('GITHUB_TOKEN')
repo_owner = 'akto-api-security'
repo_name = 'akto'
headers = {'Authorization': f'Bearer {github_token}'}
url = f'https://api.github.com/repos/{repo_owner}/{repo_name}/releases/latest'
response = requests.get(url, headers=headers)
data = response.json()
tag_name = data.get('tag_name')
description = data.get('body')
description_lines = description.split('\n') if description else []
description_lines = [line.strip() for line in description_lines if line.strip()]
release_notes = '<ul>'
if description_lines:
first_line = description_lines[0].lstrip('#').strip()
release_notes += f'<h3>{first_line}</h3>'
for line in description_lines[1:-1]: # Exclude the last line
if 'by' in line:
line = line.split('by', 1)[0].strip()
release_notes += f'<li>{line[1:]}</li>'
release_notes += '</ul>'
release_notes2 = '<p></p>Have questions? Ask on <a href=https://discord.com/invite/Wpc6xVME4s >Discord</a> or our <a href=https://community.akto.io >Community page</a>'
release_notes = release_notes+release_notes2
print(f"::set-output name=tag_name::{tag_name}")
print(f"::set-output name=release_notes::{release_notes}")
EOF
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Print Tag Name and Description
run: |
echo "Tag Name: ${{ steps.get_latest_release.outputs.tag_name }}"
echo "Description: ${{ steps.get_latest_release.outputs.release_notes }}"
- name: Push Release Notes to Beamer
env:
BEAMER_API_TOKEN: ${{ secrets.BEAMER_API_KEY }}
RELEASE_TAG: ${{ steps.get_latest_release.outputs.tag_name }}
RELEASE_NOTES: ${{ steps.get_latest_release.outputs.release_notes}}
run: |
# Push release notes to Beamer
curl --request POST \
--url https://api.getbeamer.com/v0/posts \
--header "Content-Type: application/json" \
--header "Beamer-Api-Key: $BEAMER_API_TOKEN" \
--data "{
\"title\": [ \"Release $RELEASE_TAG\" ],
\"content\": [ \"$RELEASE_NOTES\" ],
\"category\": \"new\",
\"publish\": true
}"
notify_discord:
runs-on: ubuntu-latest
steps:
- name: Setup Bolt
uses: koalalab-inc/bolt@v1
- name: Get Latest Release
id: get_latest_release
run: |
python3 -m pip install --upgrade pip
python3 -m pip install requests
python3 - <<EOF
import os
import requests
import json
github_token = os.getenv('GITHUB_TOKEN')
repo_owner = 'akto-api-security'
repo_name = 'akto'
headers = {'Authorization': f'Bearer {github_token}'}
url = f'https://api.github.com/repos/{repo_owner}/{repo_name}/releases/latest'
response = requests.get(url, headers=headers)
data = response.json()
tag = data.get('tag_name')
description = data.get('body')
# Replace anything after "by" in each line with a "."
if description:
description_lines = description.split('\n')
for i in range(len(description_lines)):
if 'by' in description_lines[i]:
description_lines[i] = description_lines[i].split('by', 1)[0].strip() + '.'
if "'" in description_lines[i]:
description_lines[i] = description_lines[i].replace("'", "''")
# Remove the last line from the description
description_lines = description_lines[:-1]
description = '\n'.join(description_lines)
print(f"::set-output name=tag::{tag}")
print(f"::set-output name=description::{json.dumps(description)}")
EOF
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Send release message to Discord
run: |
curl -X POST -H "Content-Type: application/json" -d '{
"content": "",
"embeds": [
{
"title": "Release ${{ steps.get_latest_release.outputs.tag }}",
"description": ${{ steps.get_latest_release.outputs.description }}
}
]
}' ${{ secrets.DISCORD_WEBHOOK_URL }}
notify_slack:
runs-on: ubuntu-latest
steps:
- name: Setup Bolt
uses: koalalab-inc/bolt@v1
- name: Get Latest Release
id: get_latest_release
run: |
python3 -m pip install --upgrade pip
python3 -m pip install requests
python3 - <<EOF
import os
import requests
import json
github_token = os.getenv('GITHUB_TOKEN')
repo_owner = 'akto-api-security'
repo_name = 'akto'
headers = {'Authorization': f'Bearer {github_token}'}
url = f'https://api.github.com/repos/{repo_owner}/{repo_name}/releases/latest'
response = requests.get(url, headers=headers)
data = response.json()
tag_name = data.get('tag_name')
description = data.get('body').replace("'", "")
print("description", description)
description_lines = description.split('\n') if description else []
description_lines = [line.strip() for line in description_lines if line.strip()]
slack_message_body = "{ 'blocks': [ { 'type': 'header', 'text': { 'type': 'plain_text', 'text': '"
slack_message_body += repo_name
slack_message_body += "' } }, { 'type': 'section', 'text': { 'type': 'mrkdwn', 'text': '"
slack_message_body += tag_name
slack_message_body += "' } }, { 'type': 'section', 'text': { 'type': 'mrkdwn', 'text': '"
slack_message_body += ('%0A'.join(description_lines))[:2000]
slack_message_body += "' } } ] }"
slack_message_body = slack_message_body.replace("'", "\"")
print("slack_message_body", slack_message_body)
print(f"::set-output name=tag_name::{tag_name}")
print(f"::set-output name=slack_message_body::{slack_message_body}")
EOF
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Send to Slack
run: |
echo "Tag Name: ${{ steps.get_latest_release.outputs.tag_name }}"
payload=`echo ${{ toJSON(steps.get_latest_release.outputs.slack_message_body) }}`
curl -X POST -H "Content-Type: application/json" -d "${payload}" ${{secrets.SLACK_WEBHOOK_URL}}