Skip to content

Instantly share code, notes, and snippets.

@hugosenari
Last active December 9, 2021 18:23
Show Gist options
  • Select an option

  • Save hugosenari/f42c0807387994fce843a5f956a597d0 to your computer and use it in GitHub Desktop.

Select an option

Save hugosenari/f42c0807387994fce843a5f956a597d0 to your computer and use it in GitHub Desktop.
Inform Merge
#!/bin/bash
SHIP=":ship: $(echo $GITHUB_REF|cut -f3 -d/)"
PACKAGE=":package: [$(echo $GITHUB_REPOSITORY|cut -f2 -d/)]"
ACTOR=":bust_in_silhouette: ${GITHUB_ACTOR}"
POST_DATA='{\"channel\": \"'$SLACK_BOT_CHANNEL'\", \"text\": \"'$SHIP' \\n '$PACKAGE' \\n '$ACTOR' \"}'
curl -s -X POST \
-H "Content-type: application/json" \
-H "Authorization: Bearer ${SLACK_BOT_TOKEN_GIT_ACTION}" \
-d @<(cat <<EOF
{
"channel": "$SLACK_BOT_CHANNEL",
"text": "$SHIP \n $PACKAGE \n $ACTOR "
}
EOF
) \
https://slack.com/api/chat.postMessage
#!/bin/bash
GIF_URL_VERSION=hugosenari/775386e57b9ffb3b37ff3ce1a3e95114/raw/27baa02a805238c483029d6ade7bad9b723a89b1
GIFED_BRANCH="${GIFED_BRANCH=master}"
PROD_GIF=`
echo $GITHUB_REF | grep -q -E "$GIFED_BRANCH" && \
curl -s https://gist.githubusercontent.com/$GIF_URL_VERSION/random_gif_url.sh | \
bash -s | \
sed -E 's/.+url":"([^"]+)",\s*"slug.+/\1/'
`
SHIP=":ship: $(echo $GITHUB_REF|cut -f3 -d/)"
PACKAGE=":package: [$(echo $GITHUB_REPOSITORY|cut -f2 -d/)]"
ACTOR=":bust_in_silhouette: ${GITHUB_ACTOR}"
curl -s -X POST \
-H "Content-type: application/json" \
-H "Authorization: Bearer ${SLACK_BOT_TOKEN_GIT_ACTION}" \
-d @<(cat <<EOF
{
"channel": "$SLACK_BOT_CHANNEL",
"text": "$SHIP \n $PACKAGE \n $ACTOR \\n $PROD_GIF "
}
EOF
) \
https://slack.com/api/chat.postMessage
@hugosenari

hugosenari commented Jan 27, 2021

Copy link
Copy Markdown
Author

usage with github actions:

jobs:
  InformDeploy:
    runs-on: ubuntu-latest
    steps:
      - name: Notify slack
        run: curl -s https://gist.githubusercontent.com/$SLACK_SCRIPT_VERSION/inform-merge.sh|bash -s
        env:
          SLACK_BOT_TOKEN_GIT_ACTION: ${{ secrets.SLACK_BOT_TOKEN_GIT_ACTION }}
          SLACK_BOT_CHANNEL: ${{ secrets.SLACK_BOT_CHANNEL  }}
          SLACK_SCRIPT_VERSION: hugosenari/f42c0807387994fce843a5f956a597d0/raw/a2288d3388484da91760afe7798b265b9892f834

When branch is master, it uses random gif with a giphy API and require GIPHY_TOKEN

security

https://dev.to/mheap/improve-your-github-actions-security-1im7
https://www.seancassidy.me/dont-pipe-to-your-shell.html

Since you're pointing to specific version, even if I change this file you will point to old version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment