Push Release Notes to Beamer and Discord #146
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: Push Release Notes to Beamer and Discord | |
on: | |
workflow_dispatch | |
jobs: | |
push-release-notes: | |
runs-on: ubuntu-latest | |
steps: | |
- 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}'} | |
tag_num = "38.9" | |
url = f'https://api.github.com/repos/{repo_owner}/{repo_name}/releases/tags/v1.{tag_num}' | |
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>' | |
release_notes2 += '<a href=https://discord.com/invite/Wpc6xVME4s >' | |
release_notes2 += '</a>' | |
release_notes2 += '</p>' | |
release_notes2 += '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: 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}'} | |
tag_num = "38.9" | |
url = f'https://api.github.com/repos/{repo_owner}/{repo_name}/releases/tags/v1.{tag_num}' | |
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: 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}'} | |
tag_num = "38.9" | |
url = f'https://api.github.com/repos/{repo_owner}/{repo_name}/releases/tags/v1.{tag_num}' | |
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}} |