Push binaries to S3

This commit is contained in:
Sam Johnston 2022-01-11 14:40:43 -06:00
parent aaf9446523
commit 3dde685942
2 changed files with 106 additions and 1 deletions

View File

@ -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 version: 2.1
jobs: jobs:
test: test:
@ -64,7 +68,20 @@ jobs:
NAME=plugeth-$PLUGETH_UTILS_VERSION-${CIRCLE_TAG} NAME=plugeth-$PLUGETH_UTILS_VERSION-${CIRCLE_TAG}
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/ 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: workflows:
version: 2 version: 2
@ -83,6 +100,7 @@ workflows:
branches: branches:
ignore: /.*/ ignore: /.*/
- build_geth_push: - build_geth_push:
context: Rivet
requires: requires:
- test - test
filters: filters:

87
slack-post.sh Executable file
View File

@ -0,0 +1,87 @@
#!/usr/bin/env bash
# Usage: slackpost -w <webhook_url> -c <channel> -u <username> -m <message> [-a <alert_type>]
# Usage: echo <message> | slackpost -w <webhook_url> -c <channel> -u <username> [-a <alert_type>]
# 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"