Skip to content

Commit

Permalink
add build and install action injector (#1009)
Browse files Browse the repository at this point in the history
add build and install action injector
  • Loading branch information
feiren.kuang authored and raullenchai committed Apr 15, 2019
1 parent 5029d8c commit 92bb971
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 5 deletions.
13 changes: 8 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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:
Expand All @@ -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
152 changes: 152 additions & 0 deletions install-injector.sh
Original file line number Diff line number Diff line change
@@ -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


27 changes: 27 additions & 0 deletions tools/actioninjector.v2/README.md
Original file line number Diff line number Diff line change
@@ -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.
67 changes: 67 additions & 0 deletions tools/actioninjector.v2/build_injector.sh
Original file line number Diff line number Diff line change
@@ -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 .

0 comments on commit 92bb971

Please sign in to comment.