From 3dde685942e9317e8faa0808d1be4d78b6e39bf9 Mon Sep 17 00:00:00 2001 From: Sam Johnston Date: Tue, 11 Jan 2022 14:40:43 -0600 Subject: [PATCH] Push binaries to S3 --- .circleci/config.yml | 20 +++++++++- slack-post.sh | 87 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100755 slack-post.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 2ee1ab059..f0afec39f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,3 +1,7 @@ +orbs: + aws-cli: circleci/aws-cli@1.0.0 #See: https://circleci.com/orbs/registry/orb/circleci/aws-cli + + version: 2.1 jobs: test: @@ -64,7 +68,20 @@ jobs: NAME=plugeth-$PLUGETH_UTILS_VERSION-${CIRCLE_TAG} VERSION=${CIRCLE_TAG} ghr -draft -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -name $NAME -delete ${VERSION} ./artifacts/ - + - aws-cli/setup: #See: https://circleci.com/orbs/registry/orb/circleci/aws-cli + aws-access-key-id: ACCESS_KEY + aws-secret-access-key: SECRET_ACCESS_KEY + aws-region: AWS_REGION + - run: + name: push to s3 + command: | + export PLUGETH_UTILS_VERSION=$(grep "github.com/openrelayxyz/plugeth-utils v" go.mod | cut -d ' ' -f 2) + aws s3 cp ./artifacts/geth-linux-amd64-$PLUGETH_UTILS_VERSION-${CIRCLE_TAG} s3://ethercattle-binaries/plugeth/$CIRCLE_TAG/geth-linux-amd64 --acl=public-read + aws s3 cp ./artifacts/geth-linux-arm64-$PLUGETH_UTILS_VERSION-${CIRCLE_TAG} s3://ethercattle-binaries/plugeth/$CIRCLE_TAG/geth-linux-arm64 --acl=public-read + - run: + name: Message Slack + command: | + ./slack-post.sh -w $SLACK_WEBHOOK -m "*plugeth*:\nTag: $CIRCLE_TAG \n" workflows: version: 2 @@ -83,6 +100,7 @@ workflows: branches: ignore: /.*/ - build_geth_push: + context: Rivet requires: - test filters: diff --git a/slack-post.sh b/slack-post.sh new file mode 100755 index 000000000..56f342ee0 --- /dev/null +++ b/slack-post.sh @@ -0,0 +1,87 @@ +#!/usr/bin/env bash + +# Usage: slackpost -w -c -u -m [-a ] +# Usage: echo | slackpost -w -c -u [-a ] + +# exit immediately if a command exits with a non-zero status +set -e + +# error if variable referenced before being set +set -u + +# produce failure return code if any command fails in pipe +set -o pipefail + +# accepted values: good, warning, danger +alert_type="" +channel="" +message="" +username="" +webhook_url="" + +# colon after var means it has a value rather than it being a bool flag +while getopts 'a:c:m:u:w:' OPTION; do + case "$OPTION" in + a) + alert_type="$OPTARG" + ;; + c) + channel="$OPTARG" + ;; + m) + message="$OPTARG" + ;; + u) + username="$OPTARG" + ;; + w) + webhook_url="$OPTARG" + ;; + ?) + echo "script usage: $(basename $0) {-c channel} {-m message} {-u username} {-w webhook} [-a alert_type]" >&2 + exit 1 + ;; + esac +done +shift "$(($OPTIND -1))" + +# # exit if channel not provided +# if [[ -z "$channel" ]] +# then +# echo "No channel specified" +# exit 1 +# fi + +# read piped data as message if message argument is not provided +if [[ -z "$message" ]] +then + message=$* + + while IFS= read -r line; do + message="$message$line\n" + done +fi + +# # exit if username not provided +# if [[ -z "$username" ]] +# then +# echo "No username specified" +# exit 1 +# fi + +# exit if webhook not provided +if [[ -z "$webhook_url" ]] +then + echo "No webhook_url specified" + exit 1 +fi + +# escape message text +escapedText=$(echo $message | sed 's/"/\"/g' | sed "s/'/\'/g") + +# create JSON payload +# json="{\"channel\": \"$channel\", \"username\":\"$username\", \"icon_emoji\":\"ghost\", \"attachments\":[{\"color\":\"$alert_type\" , \"text\": \"$escapedText\"}]}" +json="{\"attachments\":[{\"color\":\"$alert_type\" , \"text\": \"$escapedText\"}]}" + +# fire off slack message post +curl -s -d "payload=$json" "$webhook_url"