Merge pull request #50 from httprunner/go-plugin

v0.5.0

- feat: install hrp with one shell command
- feat: report GA event for loading go plugin
This commit is contained in:
debugtalk
2022-01-07 18:16:32 +08:00
committed by GitHub
12 changed files with 111 additions and 11 deletions

View File

@@ -21,6 +21,8 @@ jobs:
uses: actions/checkout@v2
- name: Release hrp cli binaries
uses: wangyoucao577/go-release-action@v1.22
env:
GA_TRACKING_ID: ${{ secrets.GA_TRACKING_ID }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}

View File

@@ -28,6 +28,8 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2
- name: Run coverage
env:
GA_TRACKING_ID: ${{ secrets.GA_TRACKING_ID }}
run: go test -coverprofile="cover.out" -covermode=atomic -race ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2

View File

@@ -3,6 +3,8 @@
## v0.5.0 (2022-01-06)
- feat: support creating and calling custom functions with [go plugin](https://pkg.go.dev/plugin)
- feat: install hrp with one shell command
- feat: report GA event for loading go plugin
## v0.4.0 (2022-01-05)

View File

@@ -32,4 +32,4 @@ Copyright 2021 debugtalk
* [hrp har2case](hrp_har2case.md) - Convert HAR to json/yaml testcase files
* [hrp run](hrp_run.md) - run API test
###### Auto generated by spf13/cobra on 6-Jan-2022
###### Auto generated by spf13/cobra on 7-Jan-2022

View File

@@ -38,4 +38,4 @@ hrp boom [flags]
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
###### Auto generated by spf13/cobra on 6-Jan-2022
###### Auto generated by spf13/cobra on 7-Jan-2022

View File

@@ -23,4 +23,4 @@ hrp har2case harPath... [flags]
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
###### Auto generated by spf13/cobra on 6-Jan-2022
###### Auto generated by spf13/cobra on 7-Jan-2022

View File

@@ -31,4 +31,4 @@ hrp run path... [flags]
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
###### Auto generated by spf13/cobra on 6-Jan-2022
###### Auto generated by spf13/cobra on 7-Jan-2022

View File

@@ -51,7 +51,6 @@ func Execute() {
RootCmd.PersistentFlags().BoolVar(&logJSON, "log-json", false, "set log to json format")
if err := RootCmd.Execute(); err != nil {
log.Error().Err(err).Msg("Failed to execute root command")
os.Exit(1)
}
}

View File

@@ -1,6 +1,8 @@
package cmd
import (
"os"
"github.com/spf13/cobra"
"github.com/httprunner/hrp"
@@ -18,7 +20,7 @@ var runCmd = &cobra.Command{
PreRun: func(cmd *cobra.Command, args []string) {
setLogLevel(logLevel)
},
RunE: func(cmd *cobra.Command, args []string) error {
Run: func(cmd *cobra.Command, args []string) {
var paths []hrp.ITestCase
for _, arg := range args {
paths = append(paths, &hrp.TestCasePath{Path: arg})
@@ -29,7 +31,10 @@ var runCmd = &cobra.Command{
if proxyUrl != "" {
runner.SetProxyUrl(proxyUrl)
}
return runner.Run(paths...)
err := runner.Run(paths...)
if err != nil {
os.Exit(1)
}
},
}

84
hrp/scripts/install.sh Normal file
View File

@@ -0,0 +1,84 @@
#!/bin/bash
# install hrp with one shell command
# curl -sL https://raw.githubusercontent.com/httprunner/hrp/main/hrp/scripts/install.sh | bash
set -e
function echoError() {
echo -e "\033[31m✘ $1\033[0m" # red
}
export -f echoError
function echoInfo() {
echo -e "\033[32m✔ $1\033[0m" # green
}
export -f echoInfo
function echoWarn() {
echo -e "\033[33m! $1\033[0m" # yellow
}
export -f echoError
function get_latest_version() {
# <title>Release v0.4.0 · httprunner/hrp · GitHub</title>
curl -sL https://github.com/httprunner/hrp/releases/latest | grep '<title>Release' | cut -d" " -f4
}
function get_arch() {
arch=$(uname -m)
if [ "$arch" == "x86_64" ]; then
arch="amd64"
fi
echo "$arch"
}
function main() {
echoInfo "Detect target hrp package..."
version=$(get_latest_version)
echo "Latest version: $version"
os=$(uname -s)
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"
echo
echoInfo "Created temp dir..."
tmp_dir=$(mktemp -d -t hrp)
echo "$tmp_dir"
cd "$tmp_dir"
echo
echoInfo "Downloading..."
curl -L $url -o "$pkg"
echo
echoInfo "Extracting..."
tar -zxf "$pkg"
ls -lh
echo
echoInfo "Installing..."
if hrp -v > /dev/null; then
echoWarn "$(hrp -v) exists, remove first !!!"
echo "$ rm -rf $(which hrp)"
rm -rf "$(which hrp)"
fi
echo "chmod +x hrp && mv hrp /usr/local/bin/"
chmod +x hrp
mv hrp /usr/local/bin/
echo
echoInfo "Check installation..."
echo "$ which hrp"
which hrp
echo "$ hrp -v"
hrp -v
echo "$ hrp -h"
hrp -h
}
main

View File

@@ -1,17 +1,16 @@
package ga
import (
"os"
"github.com/denisbrodbeck/machineid"
"github.com/google/uuid"
)
const (
trackingID = "UA-114587036-1" // Tracking ID for Google Analytics
)
var gaClient *GAClient
func init() {
trackingID := os.Getenv("GA_TRACKING_ID") // Tracking ID for Google Analytics
clientID, err := machineid.ProtectedID("hrp")
if err != nil {
nodeUUID, _ := uuid.NewUUID()

View File

@@ -9,6 +9,7 @@ import (
"github.com/rs/zerolog/log"
"github.com/httprunner/hrp/internal/builtin"
"github.com/httprunner/hrp/internal/ga"
)
func (p *parser) loadPlugin(path string) error {
@@ -33,6 +34,12 @@ func (p *parser) loadPlugin(path string) error {
return nil
}
// report event for loading go plugin
go ga.SendEvent(ga.EventTracking{
Category: "LoadGoPlugin",
Action: "plugin.Open",
})
// load plugin
plugins, err := plugin.Open(pluginPath)
if err != nil {