Skip to content

Version 1.25.0

Version 1.25.0 #1

Workflow file for this run

name: Automated Slack message
on:
release:
types: [published]
jobs:
slack_message:
name: Slack message
runs-on: ubuntu-latest
steps:
- name: Download release artifact
uses: dawidd6/action-download-artifact@v6
with:
name: gitlab-data-artifact
github_token: ${{ github.token }}
workflow: info-release.yml
- name: Display artifact content
run: cat artifact.json
- name: Slack Markdown Converter
if: github.event.release.body
id: convert
uses: LoveToKnow/slackify-markdown-action@v1.1.1
with:
text: ${{ github.event.release.body }}
- name: Prepare and send Slack message
env:
EVENT_CONTEXT: ${{ toJSON(github.event) }}
CONVERTED_TEXT: ${{ steps.convert.outputs.text }}
run: |
node <<EOF
const { tickets } = require('./artifact.json');
(async () => {
const project = "HiPay Enterprise SDK Magento2";
const payload = {
channel: "${{ vars.SLACK_CHANNEL_ID }}",
blocks: [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*[NEW]* " + project + " - ${{ github.event.release.tag_name }}",
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Show release :rocket:",
"emoji": true
},
"url": "${{ github.event.release.html_url }}"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":clipboard: Tickets JIRA :"
}
},
{
"type": "rich_text",
"elements": [
{
"type": "rich_text_list",
"style": "bullet",
"elements": []
}
]
}
]
};
tickets.forEach((ticket) => {
ticket = ticket.toUpperCase();
payload.blocks[2].elements[0].elements.push({
"type": "rich_text_section",
"elements": [
{
"type": "link",
"url": "https://${{ vars.JIRA_DOMAIN }}/browse/" + ticket,
"text": ticket
}
]
});
});
console.log("payload", payload);
try {
const slackResponse = await fetch("https://slack.com/api/chat.postMessage", {
method: "POST",
headers: {
"Authorization": "Bearer ${{ secrets.SLACK_API_TOKEN }}",
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
if (!slackResponse.ok) {
const err = await slackResponse.json();
throw new Error("Failed to send message: " + JSON.stringify(err));
}
console.log("Message sent successfully !");
} catch (error) {
console.error("Request error", error.message);
}
})();
EOF