Escaping double quotes
I include the last commit message in my messaging, which works great until I recently did a revert and discovered that commit messages with double quotes break the action.
- name: Deploy Complete Success Notification
uses: slackapi/[email protected]
if: success()
env:
MESSAGE: "${{ github.event.workflow_run.head_commit.message || github.event.head_commit.message }}"
with:
method: chat.postMessage
token: ${{ secrets.SLACK_NOTIFICATIONS_BOT_TOKEN }}
payload: |
channel: monitoring
text: "FRONTEND: Deployment of '${{ env.MESSAGE }}' to ${{ github.ref_name }} Completed"
I've tried wrapping env.MESSAGE in toJSON (as mentioned as a solution in https://github.com/slackapi/slack-github-action/issues/202), but that does not address the issue with double quotes it seems. I'm also not seeing any suggestions for how to overcome in https://tools.slack.dev/slack-github-action/sending-variables. What is the proper way to get this working correctly?
Hey @ohshazbot! 👋 Thanks so much for sharing this example and references :books: ✨
The linked toJSON workaround requires that the variable with quotes is included within the entire text string before an attempt to escape - that expression wraps standalone strings in double quotes which might cause errors when included in another string 👾
For this setup I might recommend making the entire text an environment variable for later escaping as follows:
- name: Deploy Complete Success Notification
uses: slackapi/[email protected]
if: success()
env:
MESSAGE: "FRONTEND: Deployment of '${{ github.event.workflow_run.head_commit.message || github.event.head_commit.message }}' to ${{ github.ref_name }} Completed"
with:
method: chat.postMessage
token: ${{ secrets.SLACK_NOTIFICATIONS_BOT_TOKEN }}
payload: |
channel: monitoring
text: ${{ toJSON(env.MESSAGE) }}
Please let me know if this works for you, or if errors might still appear! 🙏
Sweet, that worked. Thanks
Backticks "`" also fail.