diff --git a/.circleci/config.yml b/.circleci/config.yml index 09f0e6b42f..d4fb6d4e22 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -85,7 +85,7 @@ jobs: # specify any bash command here prefixed with `run: ` - run: make nightlybuild - nightly_ioctl_build_docker: + nightly_bin_build_docker: docker: # specify the version - image: iotex/iotex-core-ci:latest @@ -97,8 +97,10 @@ jobs: - run: sudo apt-get install python python-pip - run: sudo pip install awscli - run: aws s3 sync cli/ioctl/release/ ${S3_BUCKET_DIR} + - run: cd tools/actioninjector.v2/ && ./build_injector.sh + - run: aws s3 sync tools/actioninjector.v2/release/ ${S3_BUCKET_DIR} - nightly_ioctl_build_darwin: + nightly_bin_build_darwin: macos: xcode: "10.2.0" # not supported > 10.2.0 @@ -121,7 +123,8 @@ jobs: cd cli/ioctl/ && ./buildcli.sh sudo pip install awscli aws s3 sync release/ ${S3_BUCKET_DIR} - + cd tools/actioninjector.v2/ && ./build_injector.sh + aws s3 sync tools/actioninjector.v2/release/ ${S3_BUCKET_DIR} workflows: version: 2 commit: @@ -140,5 +143,5 @@ workflows: - master jobs: - nightly_build_docker - - nightly_ioctl_build_docker - - nightly_ioctl_build_darwin + - nightly_bin_build_docker + - nightly_bin_build_darwin diff --git a/install-injector.sh b/install-injector.sh new file mode 100755 index 0000000000..2bad7639a8 --- /dev/null +++ b/install-injector.sh @@ -0,0 +1,152 @@ +#!/bin/sh + +# This install script is intended to download and install the latest available +# release of the ioctl dependency manager for Golang. +# +# It attempts to identify the current platform and an error will be thrown if +# the platform is not supported. +# +# Environment variables: +# - INSTALL_DIRECTORY (optional): defaults to $GOPATH/bin (if $GOPATH exists) +# or /usr/local/bin (else) +# - CLI_RELEASE_TAG (optional): defaults to fetching the latest release +# +# You can install using this script: +# $ curl https://raw.githubusercontent.com/iotexproject/iotex-core/master/install-cli.sh | sh + +set -e + +RELEASES_URL="https://github.com/iotexproject/iotex-core/releases" +S3URL="https://s3-ap-southeast-1.amazonaws.com/ioctl" +INSTALL_DIRECTORY='/usr/local/bin' + +downloadJSON() { + url="$2" + + echo "Fetching $url.." + if test -x "$(command -v curl)"; then + response=$(curl -s -L -w 'HTTPSTATUS:%{http_code}' -H 'Accept: application/json' "$url") + body=$(echo "$response" | sed -e 's/HTTPSTATUS\:.*//g') + code=$(echo "$response" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://') + elif test -x "$(command -v wget)"; then + temp=$(mktemp) + body=$(wget -q --header='Accept: application/json' -O - --server-response "$url" 2> "$temp") + code=$(awk '/^ HTTP/{print $2}' < "$temp" | tail -1) + rm "$temp" + else + echo "Neither curl nor wget was available to perform http requests." + exit 1 + fi + if [ "$code" != 200 ]; then + echo "Request failed with code $code" + exit 1 + fi + + eval "$1='$body'" +} + +downloadFile() { + url="$1" + destination="$2" + + echo "Fetching $url.." + if test -x "$(command -v curl)"; then + code=$(curl -s -w '%{http_code}' -L "$url" -o "$destination") + elif test -x "$(command -v wget)"; then + code=$(wget -q -O "$destination" --server-response "$url" 2>&1 | awk '/^ HTTP/{print $2}' | tail -1) + else + echo "Neither curl nor wget was available to perform http requests." + exit 1 + fi + + if [ "$code" != 200 ]; then + echo "Request failed with code $code" + exit 1 + fi +} + +initArch() { + ARCH=$(uname -m) + case $ARCH in + amd64) ARCH="amd64";; + x86_64) ARCH="amd64";; + i386) ARCH="386";; + ppc64) ARCH="ppc64";; + ppc64le) ARCH="ppc64le";; + s390x) ARCH="s390x";; + armv6*) ARCH="arm";; + armv7*) ARCH="arm";; + aarch64) ARCH="arm64";; + *) echo "Architecture ${ARCH} is not supported by this installation script"; exit 1;; + esac + echo "ARCH = $ARCH" +} + +initOS() { + OS=$(uname | tr '[:upper:]' '[:lower:]') + OS_CYGWIN=0 + case "$OS" in + darwin) OS='darwin';; + linux) OS='linux';; + freebsd) OS='freebsd';; + mingw*) OS='windows';; + msys*) OS='windows';; + cygwin*) + OS='windows' + OS_CYGWIN=1 + ;; + *) echo "OS ${OS} is not supported by this installation script"; exit 1;; + esac + echo "OS = $OS" +} + +# identify platform based on uname output +initArch +initOS +INSTALL_NAME="injector" + +# assemble expected release artifact name +if [ "${OS}" != "linux" ] && { [ "${ARCH}" = "ppc64" ] || [ "${ARCH}" = "ppc64le" ];}; then + # ppc64 and ppc64le are only supported on Linux. + echo "${OS}-${ARCH} is not supported by this instalation script" +else + BINARY="${INSTALL_NAME}-${OS}-${ARCH}" +fi + +# add .exe if on windows +if [ "$OS" = "windows" ]; then + BINARY="$BINARY.exe" +fi + +if [ -z "$CLI_RELEASE_TAG" ]; then + downloadJSON LATEST_RELEASE "$RELEASES_URL/latest" + CLI_RELEASE_TAG=$(echo "${LATEST_RELEASE}" | tr -s '\n' ' ' | sed 's/.*"tag_name":"//' | sed 's/".*//' ) +fi + +if [ "$1" = "unstable" ]; then + BINARY_URL="$S3URL/$BINARY" + +else + # fetch the real release data to make sure it exists before we attempt a download + downloadJSON RELEASE_DATA "$RELEASES_URL/tag/$CLI_RELEASE_TAG" + BINARY_URL="$RELEASES_URL/download/$CLI_RELEASE_TAG/$BINARY" +fi + +DOWNLOAD_FILE=$(mktemp) + +downloadFile "$BINARY_URL" "$DOWNLOAD_FILE" + +echo "Setting executable permissions." +chmod +x "$DOWNLOAD_FILE" + + +if [ "$OS" = "windows" ]; then + INSTALL_NAME="$INSTALL_NAME.exe" + echo "Moving executable to $HOME/$INSTALL_NAME" + mv "$DOWNLOAD_FILE" "$HOME/$INSTALL_NAME" +else + echo "Moving executable to $INSTALL_DIRECTORY/$INSTALL_NAME" + sudo mv "$DOWNLOAD_FILE" "$INSTALL_DIRECTORY/$INSTALL_NAME" +fi + + diff --git a/tools/actioninjector.v2/README.md b/tools/actioninjector.v2/README.md new file mode 100644 index 0000000000..1681afcf87 --- /dev/null +++ b/tools/actioninjector.v2/README.md @@ -0,0 +1,27 @@ +# injector +injector is a command-line interface for interacting with IoTeX blockchains. + +# Build +`./buildcli.sh` + +After this command, target bin files will be placed in ./release/ folder, upload them to +specific release so install-cli.sh can download them. + +# Intall +## Install released build + curl --silent https://raw.githubusercontent.com/iotexproject/iotex-core/master/install-injector.sh | sh + +## Install latest build + curl https://raw.githubusercontent.com/iotexproject/iotex-core/master/install-injector.sh | sh -s "unstable" + +# Usage + injector [command] + + Available Commands: + help Help about any command + random inject random actions + + Flags: + -h, --help help for injector + + Use "injector [command] --help" for more information about a command. diff --git a/tools/actioninjector.v2/build_injector.sh b/tools/actioninjector.v2/build_injector.sh new file mode 100755 index 0000000000..2bdd77a757 --- /dev/null +++ b/tools/actioninjector.v2/build_injector.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +initOS() { + OS=$(uname | tr '[:upper:]' '[:lower:]') + OS_CYGWIN=0 + if [ -n "$DEP_OS" ]; then + echo "Using DEP_OS" + OS="$DEP_OS" + fi + case "$OS" in + darwin) OS='darwin';; + linux) OS='linux';; + freebsd) OS='freebsd';; + mingw*) OS='windows';; + msys*) OS='windows';; + cygwin*) + OS='windows' + OS_CYGWIN=1 + ;; + *) echo "OS ${OS} is not supported by this installation script"; exit 1;; + esac + echo "OS = $OS" +} + +initVersion() { + PACKAGE_VERSION=$(git describe --tags) + PACKAGE_COMMIT_ID=$(git rev-parse HEAD) + GIT_STATUS=$(git status --porcelain) + if ! [ -z "$GIT_STATUS" ];then + #if git_status=$(git status --porcelain) && [[ -z ${git_status} ]]; then + GIT_STATUS="dirty" + else + GIT_STATUS="clean" + fi + GO_VERSION=$(go version) + BUILD_TIME=$(date +%F-%Z/%T) + VersionImportPath='github.com/iotexproject/iotex-core/pkg/version' + PackageFlags="-X '${VersionImportPath}.PackageVersion=${PACKAGE_VERSION}' " + ## Ubuntu PackageFlags+="-X " have fault + if [ "$OS" = "linux" ]; then + PackageFlags=${PackageFlags}"-X '${VersionImportPath}.PackageCommitID=${PACKAGE_COMMIT_ID}' " + PackageFlags=${PackageFlags}"-X '${VersionImportPath}.GitStatus=${GIT_STATUS}' " + PackageFlags=${PackageFlags}"-X '${VersionImportPath}.GoVersion=${GO_VERSION}' " + PackageFlags=${PackageFlags}"-X '${VersionImportPath}.BuildTime=${BUILD_TIME}' " + PackageFlags=${PackageFlags}"-s -w" + else + PackageFlags+="-X '${VersionImportPath}.PackageCommitID=${PACKAGE_COMMIT_ID}' " + PackageFlags+="-X '${VersionImportPath}.GitStatus=${GIT_STATUS}' " + PackageFlags+="-X '${VersionImportPath}.GoVersion=${GO_VERSION}' " + PackageFlags+="-X '${VersionImportPath}.BuildTime=${BUILD_TIME}' " + PackageFlags+="-s -w" + fi +} +initOS +initVersion +project_name="injector" + +release_dir=./release +rm -rf $release_dir/* +mkdir -p $release_dir + +cd $(dirname $0) + +gofmt -w ./ + +CGO_ENABLED=1 GOARCH=amd64 go build -ldflags "${PackageFlags}" -o $release_dir/$project_name-$OS-amd64 -v . +#CGO_ENABLED=1 GOARCH=386 go build -o $release_dir/$project_name-$OS-386 -v .