Skip to content

Commit 5797c76

Browse files
Add initial workflows (AST-000)
1 parent 316a3aa commit 5797c76

File tree

2 files changed

+172
-0
lines changed

2 files changed

+172
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
name: Notify Teams on Release
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
product_name:
7+
required: true
8+
type: string
9+
release_version:
10+
required: true
11+
type: string
12+
cli_release_version:
13+
required: true
14+
type: string
15+
release_author:
16+
required: true
17+
type: string
18+
release_url:
19+
required: true
20+
type: string
21+
22+
jobs:
23+
notify-teams:
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- name: Fetch Release Notes
28+
id: fetch_release_notes
29+
uses: actions/github-script@v6
30+
with:
31+
script: |
32+
const releaseUrl = '${{ inputs.release_url }}';
33+
const urlPattern = /https:\/\/github\.com\/([^\/]+)\/([^\/]+)\/releases\/tag\/(.+)/;
34+
const match = releaseUrl.match(urlPattern);
35+
if (!match) {
36+
throw new Error('Invalid release URL format.');
37+
}
38+
const [_, owner, repo, tag] = match;
39+
const { data: release } = await github.rest.repos.getReleaseByTag({
40+
owner,
41+
repo,
42+
tag
43+
});
44+
core.setOutput('release_notes', release.body);
45+
46+
- name: Sanitize Release Notes
47+
id: sanitize_release_notes
48+
run: |
49+
sanitized=$(echo "${{ steps.fetch_release_notes.outputs.release_notes }}" | sed '1{/^<!--/d}')
50+
sanitized=$(echo "$sanitized" | jq -Rs '.')
51+
echo $sanitized
52+
echo "sanitized_release_notes=$sanitized" >> $GITHUB_OUTPUT
53+
54+
- name: Extract Contributors
55+
id: extract_contributors
56+
run: |
57+
58+
contributors=$(echo "${{ steps.fetch_release_notes.outputs.release_notes }}" | grep -o '@[a-zA-Z0-9_-]\+' | sort -u)
59+
60+
echo "Contributors: $contributors"
61+
62+
# Format contributors as a comma-separated list
63+
formatted_contributors=$(echo "$contributors" | tr '\n' ', ' | sed 's/, $//')
64+
formatted_contributors=$(echo "$contributors" | paste -sd ' , ' -)
65+
echo "Formatted Contributors: $formatted_contributors"
66+
67+
# Initialize an empty string to hold formatted contributors
68+
formatted_contributors_links=""
69+
70+
# Iterate over each contributor and format as a Markdown link
71+
for contributor in $contributors; do
72+
username=${contributor#@}
73+
formatted_contributors_links+="[${username}](https://github.com/${username}), "
74+
done
75+
76+
echo "Formatted Contributors Links: $formatted_contributors_links"
77+
78+
escaped_contributors_links=$(jq -Rsa . <<< "$formatted_contributors_links")
79+
echo "Escaped Contributors Links: $escaped_contributors_links"
80+
81+
echo "formatted_contributors=$formatted_contributors" >> $GITHUB_OUTPUT
82+
echo "escaped_contributors_links=escaped_contributors_links" >> $GITHUB_OUTPUT
83+
84+
85+
- name: Send notification to Teams
86+
uses: Skitionek/notify-microsoft-teams@v1.0.8
87+
with:
88+
webhook_url: https://checkmarx.webhook.office.com/webhookb2/5f811a29-905e-413f-bba5-231695e0d7fe@6677be72-cda1-47e8-ae4a-320b4692c7d7/IncomingWebhook/853350f9e4464a6b8fd322267efb88b0/0579dadb-7831-4e0e-8639-95fa06390117/V2TQWXTTo3Ul7lb9WZsSJQrCVAQgkCFURVVVHHvbUbUi81
89+
raw: >
90+
{
91+
"type": "message",
92+
"attachments": [
93+
{
94+
"contentType": "application/vnd.microsoft.card.adaptive",
95+
"content": {
96+
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
97+
"type": "AdaptiveCard",
98+
"version": "1.4",
99+
"msteams": {
100+
"width": "Full"
101+
},
102+
"body": [
103+
{
104+
"type": "TextBlock",
105+
"text": "New Release: **${{ inputs.product_name }} - ${{ inputs.release_version }}**",
106+
"weight": "Bolder",
107+
"size": "Medium"
108+
},
109+
{
110+
"type": "FactSet",
111+
"facts": [
112+
{ "title": "Product:", "value": "${{ inputs.product_name }}" },
113+
{ "title": "Version:", "value": "${{ inputs.release_version }}" },
114+
{ "title": "CLI Version:", "value": "${{ inputs.cli_release_version }}" },
115+
{ "title": "Contributors:", "value": "${{ steps.extract_contributors.outputs.formatted_contributors }}" }
116+
]
117+
},
118+
{
119+
"type": "TextBlock",
120+
"text": ${{ steps.sanitize_release_notes.outputs.sanitized_release_notes }},
121+
"wrap": true
122+
}
123+
],
124+
"actions": [
125+
{
126+
"type": "Action.OpenUrl",
127+
"title": "View Release",
128+
"url": "${{ inputs.release_url }}"
129+
}
130+
]
131+
}
132+
}
133+
]
134+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Test Notify Teams Workflow
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
inputs:
9+
product_name:
10+
description: 'Name of the product'
11+
required: true
12+
default: 'JetBrains'
13+
release_version:
14+
description: 'Version of the release'
15+
required: true
16+
default: 'v2.2.3'
17+
cli_release_version:
18+
description: 'Version of the cli in release'
19+
required: true
20+
default: 'v2.3.9'
21+
release_author:
22+
description: 'Author of the release'
23+
required: true
24+
default: 'test-author'
25+
release_url:
26+
description: 'URL of the release'
27+
required: true
28+
default: 'https://github.com/Checkmarx/ast-jetbrains-plugin/releases/tag/2.2.3'
29+
30+
jobs:
31+
test-notify:
32+
uses: ./.github/workflows/release-notify.yml
33+
with:
34+
product_name: ${{ github.event.inputs.product_name }}
35+
release_version: ${{ github.event.inputs.release_version }}
36+
cli_release_version: ${{ github.event.inputs.cli_release_version }}
37+
release_author: ${{ github.event.inputs.release_author }}
38+
release_url: ${{ github.event.inputs.release_url }}

0 commit comments

Comments
 (0)