Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates the module references #3

Merged
merged 5 commits into from
Jul 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
31 changes: 31 additions & 0 deletions .circleci/release.sh
Original file line number Diff line number Diff line change
@@ -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}"
51 changes: 42 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion genproto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/...
go fmt github.com/sitture/gauge-reportserver/...
6 changes: 3 additions & 3 deletions listener/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
45 changes: 38 additions & 7 deletions reportserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()
Expand Down Expand Up @@ -97,13 +101,40 @@ 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
}
reportPath := env.GetReportServerUrl()
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
}
14 changes: 1 addition & 13 deletions zipper/zipper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import (
"strings"
)

const (
OldIndexFilePath = "/index.html"
NewIndexFilePath = "/report.html"
)

func ZipDir(source, target string) error {

// check if sourceDir exists
Expand Down Expand Up @@ -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
Expand Down