Fix shell escaping in Mastodon workflow body parsing #28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| BODYLINE=$(echo ${BODY} | sed 's/^\"//g' | sed 's/\"$//g' | sed 's/\"/\\"/g' ) | |
| echo " | |
| {\"text\": | |
| \"## ${ICON} ${REF}\n | |
| Status: ${STATUS_TEXT} \n | |
| in: [${REPOSITORY}](${REPOSITORY_URL}) by: **${AUTHOR}**\n\n | |
| \`\`\`text\n | |
| ${BODYLINE}\n | |
| \`\`\` | |
| \n----\n | |
| [Commit](${LINK}) | |
| \" | |
| } | |
| " | paste -d' ' -s - > mattermost.json | |
| - name: Read Content | |
| id: getcontent | |
| run: echo "::set-output name=payload::$(cat mattermost.json)" | |
| - name: Send Mattermost Message | |
| uses: mattermost/action-mattermost-notify@master | |
| with: | |
| MATTERMOST_WEBHOOK_URL: ${{ secrets.WEBHOOK }} | |
| PAYLOAD: ${{ steps.getcontent.outputs.payload }} |