Skip to content

Commit 92bb971

Browse files
feiren.kuangraullenchai
feiren.kuang
authored andcommitted
add build and install action injector (iotexproject#1009)
add build and install action injector
1 parent 5029d8c commit 92bb971

File tree

4 files changed

+254
-5
lines changed

4 files changed

+254
-5
lines changed

.circleci/config.yml

+8-5
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585
# specify any bash command here prefixed with `run: `
8686
- run: make nightlybuild
8787

88-
nightly_ioctl_build_docker:
88+
nightly_bin_build_docker:
8989
docker:
9090
# specify the version
9191
- image: iotex/iotex-core-ci:latest
@@ -97,8 +97,10 @@ jobs:
9797
- run: sudo apt-get install python python-pip
9898
- run: sudo pip install awscli
9999
- run: aws s3 sync cli/ioctl/release/ ${S3_BUCKET_DIR}
100+
- run: cd tools/actioninjector.v2/ && ./build_injector.sh
101+
- run: aws s3 sync tools/actioninjector.v2/release/ ${S3_BUCKET_DIR}
100102

101-
nightly_ioctl_build_darwin:
103+
nightly_bin_build_darwin:
102104
macos:
103105
xcode: "10.2.0" # not supported > 10.2.0
104106

@@ -121,7 +123,8 @@ jobs:
121123
cd cli/ioctl/ && ./buildcli.sh
122124
sudo pip install awscli
123125
aws s3 sync release/ ${S3_BUCKET_DIR}
124-
126+
cd tools/actioninjector.v2/ && ./build_injector.sh
127+
aws s3 sync tools/actioninjector.v2/release/ ${S3_BUCKET_DIR}
125128
workflows:
126129
version: 2
127130
commit:
@@ -140,5 +143,5 @@ workflows:
140143
- master
141144
jobs:
142145
- nightly_build_docker
143-
- nightly_ioctl_build_docker
144-
- nightly_ioctl_build_darwin
146+
- nightly_bin_build_docker
147+
- nightly_bin_build_darwin

install-injector.sh

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
#!/bin/sh
2+
3+
# This install script is intended to download and install the latest available
4+
# release of the ioctl dependency manager for Golang.
5+
#
6+
# It attempts to identify the current platform and an error will be thrown if
7+
# the platform is not supported.
8+
#
9+
# Environment variables:
10+
# - INSTALL_DIRECTORY (optional): defaults to $GOPATH/bin (if $GOPATH exists)
11+
# or /usr/local/bin (else)
12+
# - CLI_RELEASE_TAG (optional): defaults to fetching the latest release
13+
#
14+
# You can install using this script:
15+
# $ curl https://raw.githubusercontent.com/iotexproject/iotex-core/master/install-cli.sh | sh
16+
17+
set -e
18+
19+
RELEASES_URL="https://github.com/iotexproject/iotex-core/releases"
20+
S3URL="https://s3-ap-southeast-1.amazonaws.com/ioctl"
21+
INSTALL_DIRECTORY='/usr/local/bin'
22+
23+
downloadJSON() {
24+
url="$2"
25+
26+
echo "Fetching $url.."
27+
if test -x "$(command -v curl)"; then
28+
response=$(curl -s -L -w 'HTTPSTATUS:%{http_code}' -H 'Accept: application/json' "$url")
29+
body=$(echo "$response" | sed -e 's/HTTPSTATUS\:.*//g')
30+
code=$(echo "$response" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
31+
elif test -x "$(command -v wget)"; then
32+
temp=$(mktemp)
33+
body=$(wget -q --header='Accept: application/json' -O - --server-response "$url" 2> "$temp")
34+
code=$(awk '/^ HTTP/{print $2}' < "$temp" | tail -1)
35+
rm "$temp"
36+
else
37+
echo "Neither curl nor wget was available to perform http requests."
38+
exit 1
39+
fi
40+
if [ "$code" != 200 ]; then
41+
echo "Request failed with code $code"
42+
exit 1
43+
fi
44+
45+
eval "$1='$body'"
46+
}
47+
48+
downloadFile() {
49+
url="$1"
50+
destination="$2"
51+
52+
echo "Fetching $url.."
53+
if test -x "$(command -v curl)"; then
54+
code=$(curl -s -w '%{http_code}' -L "$url" -o "$destination")
55+
elif test -x "$(command -v wget)"; then
56+
code=$(wget -q -O "$destination" --server-response "$url" 2>&1 | awk '/^ HTTP/{print $2}' | tail -1)
57+
else
58+
echo "Neither curl nor wget was available to perform http requests."
59+
exit 1
60+
fi
61+
62+
if [ "$code" != 200 ]; then
63+
echo "Request failed with code $code"
64+
exit 1
65+
fi
66+
}
67+
68+
initArch() {
69+
ARCH=$(uname -m)
70+
case $ARCH in
71+
amd64) ARCH="amd64";;
72+
x86_64) ARCH="amd64";;
73+
i386) ARCH="386";;
74+
ppc64) ARCH="ppc64";;
75+
ppc64le) ARCH="ppc64le";;
76+
s390x) ARCH="s390x";;
77+
armv6*) ARCH="arm";;
78+
armv7*) ARCH="arm";;
79+
aarch64) ARCH="arm64";;
80+
*) echo "Architecture ${ARCH} is not supported by this installation script"; exit 1;;
81+
esac
82+
echo "ARCH = $ARCH"
83+
}
84+
85+
initOS() {
86+
OS=$(uname | tr '[:upper:]' '[:lower:]')
87+
OS_CYGWIN=0
88+
case "$OS" in
89+
darwin) OS='darwin';;
90+
linux) OS='linux';;
91+
freebsd) OS='freebsd';;
92+
mingw*) OS='windows';;
93+
msys*) OS='windows';;
94+
cygwin*)
95+
OS='windows'
96+
OS_CYGWIN=1
97+
;;
98+
*) echo "OS ${OS} is not supported by this installation script"; exit 1;;
99+
esac
100+
echo "OS = $OS"
101+
}
102+
103+
# identify platform based on uname output
104+
initArch
105+
initOS
106+
INSTALL_NAME="injector"
107+
108+
# assemble expected release artifact name
109+
if [ "${OS}" != "linux" ] && { [ "${ARCH}" = "ppc64" ] || [ "${ARCH}" = "ppc64le" ];}; then
110+
# ppc64 and ppc64le are only supported on Linux.
111+
echo "${OS}-${ARCH} is not supported by this instalation script"
112+
else
113+
BINARY="${INSTALL_NAME}-${OS}-${ARCH}"
114+
fi
115+
116+
# add .exe if on windows
117+
if [ "$OS" = "windows" ]; then
118+
BINARY="$BINARY.exe"
119+
fi
120+
121+
if [ -z "$CLI_RELEASE_TAG" ]; then
122+
downloadJSON LATEST_RELEASE "$RELEASES_URL/latest"
123+
CLI_RELEASE_TAG=$(echo "${LATEST_RELEASE}" | tr -s '\n' ' ' | sed 's/.*"tag_name":"//' | sed 's/".*//' )
124+
fi
125+
126+
if [ "$1" = "unstable" ]; then
127+
BINARY_URL="$S3URL/$BINARY"
128+
129+
else
130+
# fetch the real release data to make sure it exists before we attempt a download
131+
downloadJSON RELEASE_DATA "$RELEASES_URL/tag/$CLI_RELEASE_TAG"
132+
BINARY_URL="$RELEASES_URL/download/$CLI_RELEASE_TAG/$BINARY"
133+
fi
134+
135+
DOWNLOAD_FILE=$(mktemp)
136+
137+
downloadFile "$BINARY_URL" "$DOWNLOAD_FILE"
138+
139+
echo "Setting executable permissions."
140+
chmod +x "$DOWNLOAD_FILE"
141+
142+
143+
if [ "$OS" = "windows" ]; then
144+
INSTALL_NAME="$INSTALL_NAME.exe"
145+
echo "Moving executable to $HOME/$INSTALL_NAME"
146+
mv "$DOWNLOAD_FILE" "$HOME/$INSTALL_NAME"
147+
else
148+
echo "Moving executable to $INSTALL_DIRECTORY/$INSTALL_NAME"
149+
sudo mv "$DOWNLOAD_FILE" "$INSTALL_DIRECTORY/$INSTALL_NAME"
150+
fi
151+
152+

tools/actioninjector.v2/README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# injector
2+
injector is a command-line interface for interacting with IoTeX blockchains.
3+
4+
# Build
5+
`./buildcli.sh`
6+
7+
After this command, target bin files will be placed in ./release/ folder, upload them to
8+
specific release so install-cli.sh can download them.
9+
10+
# Intall
11+
## Install released build
12+
curl --silent https://raw.githubusercontent.com/iotexproject/iotex-core/master/install-injector.sh | sh
13+
14+
## Install latest build
15+
curl https://raw.githubusercontent.com/iotexproject/iotex-core/master/install-injector.sh | sh -s "unstable"
16+
17+
# Usage
18+
injector [command]
19+
20+
Available Commands:
21+
help Help about any command
22+
random inject random actions
23+
24+
Flags:
25+
-h, --help help for injector
26+
27+
Use "injector [command] --help" for more information about a command.
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/sh
2+
3+
initOS() {
4+
OS=$(uname | tr '[:upper:]' '[:lower:]')
5+
OS_CYGWIN=0
6+
if [ -n "$DEP_OS" ]; then
7+
echo "Using DEP_OS"
8+
OS="$DEP_OS"
9+
fi
10+
case "$OS" in
11+
darwin) OS='darwin';;
12+
linux) OS='linux';;
13+
freebsd) OS='freebsd';;
14+
mingw*) OS='windows';;
15+
msys*) OS='windows';;
16+
cygwin*)
17+
OS='windows'
18+
OS_CYGWIN=1
19+
;;
20+
*) echo "OS ${OS} is not supported by this installation script"; exit 1;;
21+
esac
22+
echo "OS = $OS"
23+
}
24+
25+
initVersion() {
26+
PACKAGE_VERSION=$(git describe --tags)
27+
PACKAGE_COMMIT_ID=$(git rev-parse HEAD)
28+
GIT_STATUS=$(git status --porcelain)
29+
if ! [ -z "$GIT_STATUS" ];then
30+
#if git_status=$(git status --porcelain) && [[ -z ${git_status} ]]; then
31+
GIT_STATUS="dirty"
32+
else
33+
GIT_STATUS="clean"
34+
fi
35+
GO_VERSION=$(go version)
36+
BUILD_TIME=$(date +%F-%Z/%T)
37+
VersionImportPath='github.com/iotexproject/iotex-core/pkg/version'
38+
PackageFlags="-X '${VersionImportPath}.PackageVersion=${PACKAGE_VERSION}' "
39+
## Ubuntu PackageFlags+="-X " have fault
40+
if [ "$OS" = "linux" ]; then
41+
PackageFlags=${PackageFlags}"-X '${VersionImportPath}.PackageCommitID=${PACKAGE_COMMIT_ID}' "
42+
PackageFlags=${PackageFlags}"-X '${VersionImportPath}.GitStatus=${GIT_STATUS}' "
43+
PackageFlags=${PackageFlags}"-X '${VersionImportPath}.GoVersion=${GO_VERSION}' "
44+
PackageFlags=${PackageFlags}"-X '${VersionImportPath}.BuildTime=${BUILD_TIME}' "
45+
PackageFlags=${PackageFlags}"-s -w"
46+
else
47+
PackageFlags+="-X '${VersionImportPath}.PackageCommitID=${PACKAGE_COMMIT_ID}' "
48+
PackageFlags+="-X '${VersionImportPath}.GitStatus=${GIT_STATUS}' "
49+
PackageFlags+="-X '${VersionImportPath}.GoVersion=${GO_VERSION}' "
50+
PackageFlags+="-X '${VersionImportPath}.BuildTime=${BUILD_TIME}' "
51+
PackageFlags+="-s -w"
52+
fi
53+
}
54+
initOS
55+
initVersion
56+
project_name="injector"
57+
58+
release_dir=./release
59+
rm -rf $release_dir/*
60+
mkdir -p $release_dir
61+
62+
cd $(dirname $0)
63+
64+
gofmt -w ./
65+
66+
CGO_ENABLED=1 GOARCH=amd64 go build -ldflags "${PackageFlags}" -o $release_dir/$project_name-$OS-amd64 -v .
67+
#CGO_ENABLED=1 GOARCH=386 go build -o $release_dir/$project_name-$OS-386 -v .

0 commit comments

Comments
 (0)