2023-06-22 21:48:42 +03:00
|
|
|
name: Slack notification on pushes to releases/*
|
2023-04-27 05:32:42 +03:00
|
|
|
|
|
|
|
# This CI job will push notifications to Slack whenever code is merged into any releases/* branch
|
|
|
|
#
|
|
|
|
# The steps of the command line kung-fu shown below are as follows:
|
|
|
|
# First we take the JSON-formatted Github context
|
|
|
|
# echo $GITHUB_CONTEXT \
|
|
|
|
# Then we parse out the specific fields we want for our messages using jq and format it into tab-separated values
|
|
|
|
# | jq '.event.commits[] | [.url, .id[0:7], .author.username, .timestamp, .message] | @tsv' \
|
|
|
|
# We need to do some cleaning on this output - specifically removing quotes and replacing newlines with something easier to split
|
|
|
|
# | sed 's/"//g' | sed 's/\\t/;/g' | sed 's/\\n/;/g' | sed 's/\\//g' \
|
|
|
|
# We then use awk to format the TSV into a Slack message
|
|
|
|
# | awk -F';' '{print "• <"$1"|"$2"> (<https://github.com/"$3"|"$3">, "$4") - "$5}' \
|
2023-05-17 23:29:06 +03:00
|
|
|
# We need to deal with some escaping issues with newlines so that we don't break the Slack message format
|
2023-04-27 05:32:42 +03:00
|
|
|
# | sed 's/$/\\n/g' | tr -d '\n' \
|
2023-05-17 23:29:06 +03:00
|
|
|
# Finally we have to truncate the message to 3,000 characters max, otherwise Slack will reject it
|
|
|
|
# | awk '{print substr($0,0,3000);}' \
|
2023-04-27 05:32:42 +03:00
|
|
|
# Then shove the bytes into a file to store them in their exact format
|
|
|
|
# > /tmp/parsed_github_context
|
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- 'releases/*'
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
notify-slack:
|
|
|
|
runs-on: ubuntu-latest
|
2023-05-19 01:30:03 +03:00
|
|
|
environment:
|
|
|
|
name: notify/releases
|
2023-04-27 05:32:42 +03:00
|
|
|
steps:
|
|
|
|
- name: Parse event to slug
|
|
|
|
id: parse-slug
|
|
|
|
env:
|
|
|
|
GITHUB_CONTEXT: ${{ toJson(github) }}
|
|
|
|
# Formats the contents of the GitHub event into slugs: one line per commit, formatted for Slack.
|
|
|
|
# Explanation for each line is in the comments above.
|
|
|
|
run: |
|
|
|
|
echo $GITHUB_CONTEXT \
|
|
|
|
| jq '.event.commits[] | [.url, .id[0:7], .author.username, .timestamp, .message] | @tsv' \
|
|
|
|
| sed 's/"//g' | sed 's/\\t/;/g' | sed 's/\\n/;/g' | sed 's/\\//g' \
|
|
|
|
| awk -F';' '{print "• <"$1"|"$2"> (<https://github.com/"$3"|"$3">, "$4") - "$5}' \
|
|
|
|
| sed 's/$/\\n/g' | tr -d '\n' \
|
2023-05-17 23:29:06 +03:00
|
|
|
| awk '{print substr($0,0,3000);}' \
|
2023-04-27 05:32:42 +03:00
|
|
|
> /tmp/parsed_github_context
|
|
|
|
echo "SLACK_COMMITS=$(cat /tmp/parsed_github_context)" >> "$GITHUB_OUTPUT"
|
2023-06-22 21:48:42 +03:00
|
|
|
- uses: slackapi/slack-github-action@007b2c3c751a190b6f0f040e47ed024deaa72844
|
2023-04-27 05:32:42 +03:00
|
|
|
with:
|
|
|
|
payload: |
|
|
|
|
{
|
|
|
|
"text": "GitHub Action build result: ${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}",
|
|
|
|
"blocks": [
|
|
|
|
{
|
|
|
|
"type": "divider"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "section",
|
|
|
|
"text": {
|
|
|
|
"type": "mrkdwn",
|
|
|
|
"text": "*Code merged to <https://github.com/Uniswap/interface/tree/${{ github.ref }}|${{ github.ref_name }}> branch:*\n"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "divider"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "section",
|
|
|
|
"text": {
|
|
|
|
"type": "mrkdwn",
|
|
|
|
"text": "*Actor*: <https://github.com/${{ github.triggering_actor }}/|${{ github.triggering_actor }}>\n*Force pushed*: ${{ github.event.forced || false }}\n"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "section",
|
|
|
|
"text": {
|
|
|
|
"type": "mrkdwn",
|
|
|
|
"text": "${{ steps.parse-slug.outputs.SLACK_COMMITS || 'New branch created' }}"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "section",
|
|
|
|
"text": {
|
|
|
|
"type": "mrkdwn",
|
|
|
|
"text": "<${{ github.event.compare}}|View Diff>"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
env:
|
|
|
|
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
|
|
|
|
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
|