diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ba7c612b..5590c6ac 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,3 +29,15 @@ jobs: binary_name: "hrp" ldflags: "-s -w" extra_files: LICENSE README.md docs/CHANGELOG.md + - name: Setup aliyun OSS + uses: manyuanrong/setup-ossutil@v2.0 + with: + endpoint: "oss-cn-beijing.aliyuncs.com" + access-key-id: ${{ secrets.ALIYUN_ACCESSKEY_ID }} + access-key-secret: ${{ secrets.ALIYUN_ACCESSKEY_SECRET }} + # - name: Upload to aliyun OSS + # run: | + # ossutil cp -rf cli/scripts/install.sh oss://httprunner/ + # ossutil cp -rf hrp-*.tar.gz hrp-*.zip oss://httprunner/ || true + # - name: Test install.sh + # run: bash -c "$(curl -ksSL https://httprunner.oss-cn-beijing.aliyuncs.com/install.sh)" diff --git a/.gitignore b/.gitignore index e5528b08..5d528d38 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ __debug_bin .idea/ __pycache__ .DS_Store +*.bak site/ output/ diff --git a/Makefile b/Makefile index b75eb2cc..98c17985 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,11 @@ test: ## run unit tests @echo "go test -race -v ./..." @go test -race -v ./... +.PHONY: bump +bump: ## bump hrp version + @echo "[info] bump hrp version" + @. cli/scripts/bump_version.sh $(version) + .PHONY: build build: ## build hrp cli tool @echo "[info] build hrp cli tool" diff --git a/README.md b/README.md index 4dcc78d1..b3a17c04 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,10 @@ See [CHANGELOG]. You can install `hrp` with one shell command, which will download the latest version's released binary and install to the current system. ```bash -$ curl -sL https://raw.githubusercontent.com/httprunner/hrp/main/cli/scripts/install.sh | bash +# install via curl +$ bash -c "$(curl -ksSL https://httprunner.oss-cn-beijing.aliyuncs.com/install.sh)" +# install via wget +$ bash -c "$(wget https://httprunner.oss-cn-beijing.aliyuncs.com/install.sh -O -)" ``` If you are a golang developer, you can also install `hrp` with `go get`. diff --git a/cli/hrp/cmd/root.go b/cli/hrp/cmd/root.go index 916e6db8..fbb9a633 100644 --- a/cli/hrp/cmd/root.go +++ b/cli/hrp/cmd/root.go @@ -2,6 +2,7 @@ package cmd import ( "os" + "runtime" "strings" "github.com/rs/zerolog" @@ -31,8 +32,12 @@ Website: https://httprunner.com Github: https://github.com/httprunner/hrp Copyright 2021 debugtalk`, PersistentPreRun: func(cmd *cobra.Command, args []string) { + var noColor = false + if runtime.GOOS == "windows" { + noColor = true + } if !logJSON { - log.Logger = zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).With().Timestamp().Logger() + log.Logger = zerolog.New(zerolog.ConsoleWriter{NoColor: noColor, Out: os.Stderr}).With().Timestamp().Logger() log.Info().Msg("Set log to color console other than JSON format.") } }, diff --git a/cli/scripts/bump_version.sh b/cli/scripts/bump_version.sh new file mode 100644 index 00000000..7be0a2b6 --- /dev/null +++ b/cli/scripts/bump_version.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# build hrp cli binary for testing +# release will be triggered on github actions, see .github/workflows/release.yml + +# Usage: +# $ make bump version=v0.5.2 +# or +# $ bash cli/scripts/bump_version.sh v0.5.2 + +set -e + +version=$1 + +if [ -z "$version" ]; then + echo "version is required" + exit 1 +fi + +echo "bump hrp version to $version" +sed -i'.bak' "s/\"v.*\"/\"$version\"/g" internal/version/init.go + +echo "bump install.sh version to $version" +sed -i'.bak' "s/LATEST_VERSION=\"v.*\"/LATEST_VERSION=\"$version\"/g" cli/scripts/install.sh diff --git a/cli/scripts/install.sh b/cli/scripts/install.sh index b76f0adc..b236a689 100644 --- a/cli/scripts/install.sh +++ b/cli/scripts/install.sh @@ -1,6 +1,8 @@ #!/bin/bash # install hrp with one shell command -# curl -sL https://raw.githubusercontent.com/httprunner/hrp/main/cli/scripts/install.sh | bash +# bash -c "$(curl -ksSL https://httprunner.oss-cn-beijing.aliyuncs.com/install.sh)" + +LATEST_VERSION="v0.5.2" set -e @@ -24,6 +26,11 @@ function get_latest_version() { curl -sL https://github.com/httprunner/hrp/releases/latest | grep 'Release' | cut -d" " -f4 } +function get_os() { + os=$(uname -s) + echo "$os" | tr '[:upper:]' '[:lower:]' +} + function get_arch() { arch=$(uname -m) if [ "$arch" == "x86_64" ]; then @@ -32,31 +39,64 @@ function get_arch() { echo "$arch" } +function get_pkg_suffix() { + os=$1 + if [ "$os" == "windows" ]; then + echo ".zip" + else + echo ".tar.gz" + fi +} + +function extract_pkg() { + pkg=$1 + if [[ $pkg == *.zip ]]; then # windows + echo "$ unzip -o $pkg -d ." + unzip -o $pkg -d . + else + echo "$ tar -xzf $pkg" + tar -xzf "$pkg" + fi +} + function main() { echoInfo "Detect target hrp package..." - version=$(get_latest_version) - echo "Latest version: $version" - os=$(uname -s) + version=$LATEST_VERSION + os=$(get_os) echo "Current OS: $os" arch=$(get_arch) echo "Current ARCH: $arch" - pkg="hrp-$version-$os-$arch.tar.gz" - url="https://github.com/httprunner/hrp/releases/download/$version/$pkg" - echo "Selected package: $url" + pkg_suffix=$(get_pkg_suffix $os) + pkg="hrp-$version-$os-$arch$pkg_suffix" + + # download from aliyun OSS + url="https://httprunner.oss-cn-beijing.aliyuncs.com/$pkg" + if ! curl --output /dev/null --silent --head --fail "$url"; then + # aliyun OSS url is invalid, try to download from github + version=$(get_latest_version) + pkg="hrp-$version-$os-$arch$pkg_suffix" + url="https://github.com/httprunner/hrp/releases/download/$version/$pkg" + fi + + echo "Latest version: $version" + echo "Download url: $url" echo echoInfo "Created temp dir..." - tmp_dir=$(mktemp -d -t hrp) + echo "$ mktemp -d -t hrp.XXXX" + tmp_dir=$(mktemp -d -t hrp.XXXX) echo "$tmp_dir" cd "$tmp_dir" echo echoInfo "Downloading..." - curl -L $url -o "$pkg" + echo "$ curl -kL $url -o $pkg" + curl -kL $url -o "$pkg" echo echoInfo "Extracting..." - tar -zxf "$pkg" + extract_pkg "$pkg" + echo "$ ls -lh" ls -lh echo @@ -67,7 +107,7 @@ function main() { rm -rf "$(which hrp)" fi - echo "chmod +x hrp && mv hrp /usr/local/bin/" + echo "$ chmod +x hrp && mv hrp /usr/local/bin/" chmod +x hrp mv hrp /usr/local/bin/ echo diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 39453cc7..0ad7b3cd 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,10 @@ # Release History +## v0.5.3 (2022-01-20) + +- change: download package assets from aliyun OSS +- fix: disable color logging on Windows + ## v0.5.2 (2022-01-19) - feat: support creating and calling custom functions with [hashicorp/go-plugin](https://github.com/hashicorp/go-plugin)