Skip to content

Fix bash syntax error: missing closing quote in builds-mattermost.yaml #37

Fix bash syntax error: missing closing quote in builds-mattermost.yaml

Fix bash syntax error: missing closing quote in builds-mattermost.yaml #37

name: Builds-Mattermost
on:
workflow_call:
secrets:
WEBHOOK:
required: true
push:
branches:
- main
jobs:
notify:
name: Mattermost
runs-on: ubuntu-latest
steps:
- uses: technote-space/workflow-conclusion-action@v3
- name: Create Mattermost Message
env:
REPOSITORY: ${{ github.repository }}
REPOSITORY_URL: ${{ github.repository.html_url }}
REF: ${{ github.ref_name }}
ACTOR: ${{ github.actor }}
TITLE: ${{ github.workflow }}
BODY: ${{ toJSON(github.event.head_commit.message) }}
ANSWER: ${{ github.event.issue.comments_url }}
LINK: ${{ github.event.head_commit.url }}
shell: bash
run: |
AUTHOR=${ACTOR}
ICON=":octagonal_sign:"
STATUS_TEXT="${{ env.WORKFLOW_CONCLUSION }}"
if [ "${{ env.WORKFLOW_CONCLUSION }}" == "success" ]; then
ICON=":robot:"
fi
if [ "${{ env.WORKFLOW_CONCLUSION }}" == "skipped" ]; then
ICON=":person_doing_cartwheel:"
fi
# Properly handle JSON-escaped body - strip outer quotes and truncate
BODYLINE="$BODY"
BODYLINE="${BODYLINE#\"}"
BODYLINE="${BODYLINE%\"}"
TRIMMED_BODY="${BODYLINE:0:350}"
# Create JSON using jq for proper escaping
jq -nc \
--arg icon "$ICON" \
--arg ref "$REF" \
--arg status "$STATUS_TEXT" \
--arg repo "$REPOSITORY" \
--arg repo_url "$REPOSITORY_URL" \
--arg author "$AUTHOR" \
--arg body "$TRIMMED_BODY" \
--arg link "$LINK" \
'{text: ("## \($icon) \($ref)\nStatus: \($status)\nin: [\($repo)](\($repo_url)) by: **\($author)**\n\n```text\n\($body)\n```\n----\n[Commit](\($link))")}' \
> mattermost.json
- name: Read Content
id: getcontent
run: echo "payload=$(cat mattermost.json)" >> $GITHUB_OUTPUT
- name: Send Mattermost Message
uses: mattermost/action-mattermost-notify@master
with:
MATTERMOST_WEBHOOK_URL: ${{ secrets.WEBHOOK }}
PAYLOAD: |-
${{ steps.getcontent.outputs.payload }}