|
| 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 | + } |
0 commit comments