Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 52 additions & 8 deletions send-to-teams-channel/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ inputs:
title:
description: Title of message to post in the channel
required: false
default: 'Github workflow notification'
default: "Github workflow notification"
service:
description: Name of the service
required: false
default: 'ServiceNotSet'
default: "ServiceNotSet"
message:
description: Message to post in the channel
required: false
default: 'MessageNotSet'
default: "MessageNotSet"
status:
description: Message status
default: attention
Expand All @@ -28,11 +28,11 @@ inputs:
minimal:
description: Display full or minimal message
required: false
default: 'false'
default: "false"
ghrepo:
description: is this running from a github repository?
required: false
default: 'true'
default: "true"

runs:
using: composite
Expand Down Expand Up @@ -76,6 +76,50 @@ runs:
run: |
echo "SHORT_TAG=$(echo ${{ env.IMAGE_TAG }} | cut -c -7)" >> $GITHUB_ENV

- name: Truncate oversized message
shell: bash
run: |
MAX_BYTES=81920

MESSAGE=$(cat <<'EOF'
${{ inputs.message }}
EOF
)

CURRENT_BYTES=$(printf "%s" "$MESSAGE" | wc -c)

echo "Current bytes: $CURRENT_BYTES"
echo "Max bytes: $MAX_BYTES"

if [ "$CURRENT_BYTES" -gt "$MAX_BYTES" ]; then

SUFFIX="

Message truncated because it exceeded the Teams message size limit.
Please view the GitHub Actions workflow run for the complete output:
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"

SUFFIX_BYTES=$(printf "%s" "$SUFFIX" | wc -c)
TRUNCATE_BYTES=$((MAX_BYTES - SUFFIX_BYTES))

TRUNCATED_MESSAGE=$(printf "%s" "$MESSAGE" | head -c "$TRUNCATE_BYTES" || true)

{
echo "TEAMS_MESSAGE<<EOF"
printf "%s" "$TRUNCATED_MESSAGE"
printf "%s\n" "$SUFFIX"
echo "EOF"
} >> "$GITHUB_ENV"

echo "Teams message truncated from $CURRENT_BYTES bytes to $MAX_BYTES bytes"
else
{
echo "TEAMS_MESSAGE<<EOF"
printf "%s\n" "$MESSAGE"
echo "EOF"
} >> "$GITHUB_ENV"
fi

- name: Send minimal notification to teams
shell: bash
if: inputs.minimal == 'true'
Expand All @@ -98,7 +142,7 @@ runs:
{ "type": "TextBlock", "text": "${{ inputs.title }}", "color": "${{ inputs.status }}", "horizontalAlignment": "left", "size": "large" } ] },
{ "type": "Column", "items": [
{ "type": "TextBlock", "text": "${{ inputs.service }}", "color": "${{ inputs.status }}", "size": "large", "horizontalAlignment": "right", "spacing": "large" } ] } ] },
{ "type": "RichTextBlock", "separator": "true", "inlines": [ { "type": "TextRun", "text": "${{ inputs.message }}" } ] } ]
{ "type": "RichTextBlock", "separator": "true", "inlines": [ { "type": "TextRun", "text": "${{ env.TEAMS_MESSAGE }}" } ] } ]
}
]
}
Expand Down Expand Up @@ -144,7 +188,7 @@ runs:
{ "type": "Action.OpenUrl", "title": "${{ github.actor }}", "url": "https://github.com/${{ github.actor }}" } ] },
{ "type": "ActionSet", "actions": [
{ "type": "Action.OpenUrl", "title": "${{ env.BRANCH_TAG }}", "url": "${{ github.server_url }}/${{ github.repository }}/tree/${{ env.BRANCH_TAG }}" } ] } ] } ] },
{ "type": "RichTextBlock", "separator": "true", "inlines": [ { "type": "TextRun", "text": "${{ inputs.message }}" } ] } ]
{ "type": "RichTextBlock", "separator": "true", "inlines": [ { "type": "TextRun", "text": "${{ env.TEAMS_MESSAGE }}" } ] } ]
}
]
}
Expand Down Expand Up @@ -186,7 +230,7 @@ runs:
{ "type": "Column", "items": [
{ "type": "ActionSet", "actions": [
{ "type": "Action.OpenUrl", "title": "${{ github.actor }}", "url": "https://github.com/${{ github.actor }}" } ] } ] } ] },
{ "type": "RichTextBlock", "separator": "true", "inlines": [ { "type": "TextRun", "text": "${{ inputs.message }}" } ] } ]
{ "type": "RichTextBlock", "separator": "true", "inlines": [ { "type": "TextRun", "text": "${{ env.TEAMS_MESSAGE }}" } ] } ]
}
]
}
Expand Down