diff --git a/.circleci/config.yml b/.circleci/config.yml index 0259050..8b4ff8b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ jobs: build: docker: - image: circleci/golang:1.12 - working_directory: /go/src/github.com/haroon-sheikh/gauge-reportserver + working_directory: /go/src/github.com/sitture/gauge-reportserver steps: - checkout - run: @@ -17,10 +17,21 @@ jobs: command: go run build/make.go --all-platforms deploy: docker: - - image: maven:3-jdk-8-alpine + - image: circleci/golang:1.12 + working_directory: /go/src/github.com/sitture/gauge-reportserver steps: - checkout - + - run: + name: Get all dependencies + command: go get ./... + - run: + name: Install github-release + command: go get -v -u github.com/aktau/github-release + - run: + name: Build and Release + command: | + go run build/make.go --all-platforms --distro + .circleci/release.sh workflows: version: 2 build_and_deploy: diff --git a/.circleci/release.sh b/.circleci/release.sh new file mode 100755 index 0000000..57a86d4 --- /dev/null +++ b/.circleci/release.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +if [ -z "${GITHUB_TOKEN}" ]; then + echo "GITHUB_TOKEN is not set" + exit 1 +fi + +${GOPATH}/bin/github-release release \ + -u ${CIRCLE_PROJECT_USERNAME} \ + -r ${CIRCLE_PROJECT_REPONAME} \ + --draft -t ${CIRCLE_TAG} \ + -n "${CIRCLE_TAG}" + +cd deploy/ +for i in `ls`; do + ${GOPATH}/bin/github-release upload \ + -u ${CIRCLE_PROJECT_USERNAME} \ + -r ${CIRCLE_PROJECT_REPONAME} \ + -t ${CIRCLE_TAG} \ + -n $i -f $i + if [ $? -ne 0 ];then + exit 1 + fi +done + +# Publish Release +${GOPATH}/bin/github-release edit \ + -u ${CIRCLE_PROJECT_USERNAME} \ + -r ${CIRCLE_PROJECT_REPONAME} \ + -t ${CIRCLE_TAG} \ + -n "${CIRCLE_TAG}" \ No newline at end of file diff --git a/README.md b/README.md index b6cc0d4..7dbcadb 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,34 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## :hammer_and_pick: Installation -// TODO +* Install the plugin +* `gohttpserver` running somewhere, or refer to [Running gohttpserver locally](#electric_plug-running-gohttpserver-locally) + +```sh +gauge install reportserver +``` + +### Offline installation + +* Download the plugin from [Releases](../../releases) + +```sh +gauge install reportserver --file reportserver-${version}-darwin.x86_64.zip +``` + +### Using the plugin + +Add `reportserver` to your project's `manifest.json`. + +```json +{ + "Language": "java", + "Plugins": [ + "html-report", + "reportserver" + ] +} +``` ## :gear: Configuration @@ -23,7 +50,7 @@ You can set the following environment variables to override the configuration OR - `REPORTSERVER_PATH` - This is path where you want the report files to go. if this is not specified, then the environment directory name is used as the path. - `REPORTSERVER_TIMEOUT_IN_SECONDS` - This is how long to wait for html-report to be ready before sending. Default is 15 seconds. -Examples: +### Examples ```sh REPORTSERVER_HOST=http://myreportserver.com @@ -40,23 +67,29 @@ REPORTSERVER_PATH=test/test http://myreportserver.com/myproject/test/test/ ``` -### :bulb: Recommendation - -// TODO - - extend plugin kill timeout - ## :electric_plug: Running `gohttpserver` locally Note: Make sure you have `docker` installed. ```bash docker run -it --rm -p 8000:8000 -v $PWD:/app/public --name gohttpserver codeskyblue/gohttpserver +``` -# OR you can use `docker-compose` to bring up the service. +* You can also use `docker-compose` to bring up the service. Create a new file `docker-compose.yml` and add the following: -docker-compose up -d +```sh +version: '2' +services: + gohttpserver: + image: codeskyblue/gohttpserver + ports: + - '8000:8000' + volumes: + - '.:/app/public' ``` +Run `docker-compose up -d` to bring up the gohttpserver in background. + The above should bring up the httpserver on port `8000` at `http://127.0.0.1:8000` ## Building locally diff --git a/env/env.go b/env/env.go index e039ce2..6cd9cb3 100644 --- a/env/env.go +++ b/env/env.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/getgauge/common" "github.com/getgauge/gauge/env" - "github.com/haroon-sheikh/gauge-reportserver/logger" + "github.com/sitture/gauge-reportserver/logger" "log" "net/url" "os" diff --git a/genproto.sh b/genproto.sh index 1c3e2b7..efdab76 100755 --- a/genproto.sh +++ b/genproto.sh @@ -28,4 +28,4 @@ cd .. sed -i.backup '/import gauge_messages1 "spec.pb"/d' gauge_messages/messages.pb.go && sed -i.backup 's/gauge_messages1.//g' gauge_messages/messages.pb.go && rm gauge_messages/messages.pb.go.backup sed -i.backup '/import "."/d' gauge_messages/messages.pb.go && rm gauge_messages/messages.pb.go.backup -go fmt github.com/haroon-sheikh/gauge-reportserver/... \ No newline at end of file +go fmt github.com/sitture/gauge-reportserver/... \ No newline at end of file diff --git a/listener/listener.go b/listener/listener.go index b20c967..3766804 100644 --- a/listener/listener.go +++ b/listener/listener.go @@ -5,9 +5,9 @@ import ( "fmt" "github.com/getgauge/common" "github.com/golang/protobuf/proto" - "github.com/haroon-sheikh/gauge-reportserver/env" - "github.com/haroon-sheikh/gauge-reportserver/gauge_messages" - "github.com/haroon-sheikh/gauge-reportserver/logger" + "github.com/sitture/gauge-reportserver/env" + "github.com/sitture/gauge-reportserver/gauge_messages" + "github.com/sitture/gauge-reportserver/logger" "log" "net" "os" diff --git a/reportserver.go b/reportserver.go index ec29843..9ec6450 100644 --- a/reportserver.go +++ b/reportserver.go @@ -2,12 +2,12 @@ package main import ( "fmt" - "github.com/haroon-sheikh/gauge-reportserver/env" - "github.com/haroon-sheikh/gauge-reportserver/gauge_messages" - "github.com/haroon-sheikh/gauge-reportserver/listener" - "github.com/haroon-sheikh/gauge-reportserver/logger" - "github.com/haroon-sheikh/gauge-reportserver/sender" - "github.com/haroon-sheikh/gauge-reportserver/zipper" + "github.com/sitture/gauge-reportserver/env" + "github.com/sitture/gauge-reportserver/gauge_messages" + "github.com/sitture/gauge-reportserver/listener" + "github.com/sitture/gauge-reportserver/logger" + "github.com/sitture/gauge-reportserver/sender" + "github.com/sitture/gauge-reportserver/zipper" "os" "path" "strings" @@ -22,6 +22,10 @@ const ( GaugePortEnvVar = "plugin_connection_port" HtmlReportDir = "html-report" HtmlReportArchive = HtmlReportDir + ".zip" + // OldIndexFilePath is the name of index file + OldIndexFile = "index.html" + // NewIndexFilePath is the name of the new index file + NewIndexFile = "report.html" ) var currentReportTimestamp = time.Now() @@ -97,6 +101,14 @@ func SendReport(stop chan bool) { logger.Debug("Origin report directory is '%s'", orig) dest := path.Join(env.GetReportsDir(), HtmlReportArchive) logger.Debug("Archive destination is '%s'", dest) + // Rename index.html to report.html + if err := RenameIndexFile(orig, OldIndexFile, NewIndexFile); err != nil { + logger.Printf("Could not rename file from '%s' to '%s'.", OldIndexFile, NewIndexFile) + } + // Check and delete existing archive + if err := RemoveExistingArchive(dest); err != nil { + logger.Printf("Could not remove archive '%s'.", dest) + } if err := zipper.ZipDir(orig, dest); err != nil { return } @@ -104,6 +116,25 @@ func SendReport(stop chan bool) { err := sender.SendArchive(reportPath, dest) if err != nil { logger.Printf(fmt.Sprintf("Could not send the archive from '%s' to '%s'\n %s", dest, reportPath, err)) + } else { + fmt.Printf("Successfully sent html-report to reportserver => %s", reportPath+"/report.html\n") + } + // Check and delete existing archive + if err := RemoveExistingArchive(dest); err != nil { + logger.Printf("Could not remove archive '%s'.", dest) + } +} + +func RenameIndexFile(dir, from, to string) (err error) { + logger.Debug("renaming index file to '%s'", to) + err = os.Rename(path.Join(dir, from), path.Join(dir, to)) + return +} + +func RemoveExistingArchive(archivePath string) (err error) { + logger.Debug("removing archive '%s'", archivePath) + if _, err := os.Stat(archivePath); err == nil { + err = os.Remove(archivePath) } - fmt.Printf("Successfully sent html-report to reportserver => %s", reportPath+"/report.html\n") + return } diff --git a/zipper/zipper.go b/zipper/zipper.go index 9eaa9bd..530380e 100644 --- a/zipper/zipper.go +++ b/zipper/zipper.go @@ -8,11 +8,6 @@ import ( "strings" ) -const ( - OldIndexFilePath = "/index.html" - NewIndexFilePath = "/report.html" -) - func ZipDir(source, target string) error { // check if sourceDir exists @@ -59,20 +54,13 @@ func ZipDir(source, target string) error { if info.IsDir() { return nil } - // TODO move this out - // rename file before and after zipping. - //if path == source + OldIndexFilePath { - // err := os.Rename(source + OldIndexFilePath, source + NewIndexFilePath) - // if err != nil { - // return err - // } - //} file, err := os.Open(path) defer file.Close() if err != nil { return err } + _, err = io.Copy(writer, file) return err