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

Build Dunner and run tests with Github Actions #165

Open
wants to merge 77 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
ef16236
Merge branch 'release-2.1.0'
agentmilindu May 26, 2019
1d72b29
Merge pull request #81 from leopardslab/release-2.1.2
agentmilindu May 26, 2019
3038429
Merge pull request #95 from leopardslab/develop
agentmilindu Jul 6, 2019
7e07e4b
Added initial GitHub Workflow
agentmilindu Aug 24, 2019
78b91ed
Merge pull request #163 from leopardslab/initial-github-workflow
agentmilindu Aug 24, 2019
3d59b65
Install bash
agentmilindu Aug 24, 2019
ab405fe
Remove unswanted mountes from .dunner.yaml
agentmilindu Aug 24, 2019
b7d9fa2
Change GitHub Actions Dunner command
agentmilindu Aug 24, 2019
3161143
Add missing image prop
agentmilindu Aug 24, 2019
4a5025c
Add OS matrix
agentmilindu Aug 24, 2019
8e9be84
Merge pull request #164 from leopardslab/agentmilindu-patch-2
agentmilindu Aug 24, 2019
f820bb1
Build Dunner and run a test
agentmilindu Aug 24, 2019
81a458d
Install dependencies using Dep
agentmilindu Aug 24, 2019
8295d0b
Add Dep installing steps
agentmilindu Aug 24, 2019
87335a2
Different steps for different OS
agentmilindu Aug 24, 2019
56a21dc
[#172] Use github actions to build and test dunner on multi-OS
apoorvam Aug 27, 2019
77d79d6
test: debug go path set
apoorvam Aug 27, 2019
25a6ae9
test: debug gobin
apoorvam Aug 27, 2019
cb50caf
test: debug gobin
apoorvam Aug 27, 2019
e1e30d5
test: create gobin if not exist
apoorvam Aug 27, 2019
20ed2f0
test: add gobin to path
apoorvam Aug 27, 2019
bcbcdad
test: use exp
apoorvam Aug 27, 2019
6e6b01d
test: fix expression
apoorvam Aug 27, 2019
64c8c4c
test: use single quote exp
apoorvam Aug 27, 2019
93be52c
test: set install directory for dep
apoorvam Aug 27, 2019
d8c0b99
test: use binaries from gopath
apoorvam Aug 27, 2019
24071ac
test: add debug statements
apoorvam Aug 27, 2019
6275ad6
test: use external github action
apoorvam Aug 27, 2019
7815b7c
test: change order
apoorvam Aug 27, 2019
7293172
test: fix flag to dep
apoorvam Aug 27, 2019
63df2dc
test: set gopath as workspace
apoorvam Aug 27, 2019
7fce475
test: set checkout path in github action
apoorvam Aug 30, 2019
a018486
test: remove workspace env
apoorvam Aug 30, 2019
ecfb9eb
test: add debug step
apoorvam Aug 30, 2019
9358ff9
test: Run only on ubuntu for now
apoorvam Aug 30, 2019
355e4d9
test: set gopath
apoorvam Aug 30, 2019
2a5d919
test: Set dep to be used from go env
apoorvam Aug 30, 2019
327825b
test: Use dep directly in makefile
apoorvam Aug 30, 2019
7010652
test: Use shell cmd to evaluate value of dep
apoorvam Aug 30, 2019
f9a5e35
Use gopath from go env
apoorvam Aug 30, 2019
460e0b4
test: enable mac os test
apoorvam Aug 30, 2019
d08b93b
test: remove cmd to create go bin dir
apoorvam Aug 30, 2019
b6af6e4
test: use dep and golint from go env | if not you can override it | e…
apoorvam Aug 30, 2019
0ffc8cf
test: remove debug statements
apoorvam Aug 30, 2019
2a5fa3b
test: add windows config
apoorvam Aug 31, 2019
5f66845
test: enable windows
apoorvam Aug 31, 2019
750eb34
test: setup mac gopath
apoorvam Aug 31, 2019
eb33b8e
test: set gopath in mac build
apoorvam Aug 31, 2019
6e29ec3
test: set gopath
apoorvam Aug 31, 2019
1028d02
test: try with docker on macos
apoorvam Aug 31, 2019
29fbaa9
test: install docker on mac
apoorvam Aug 31, 2019
99c07c8
test: add install virtualbox
apoorvam Aug 31, 2019
3956c2b
test: not run on mac since it has no docker support
apoorvam Aug 31, 2019
0960161
test: update debug statements
apoorvam Aug 31, 2019
169f198
test: update gopath in windows
apoorvam Aug 31, 2019
17e5404
test: update gopath
apoorvam Aug 31, 2019
56bd262
test: update gopath
apoorvam Aug 31, 2019
bb804f9
test: windows gopath
apoorvam Aug 31, 2019
faaa0ff
Get User home dir from go to make OS friendly | Fix some windows test…
apoorvam Aug 31, 2019
b1f7c95
Merge remote-tracking branch 'origin/develop' into github-actions-dun…
apoorvam Aug 31, 2019
611cd9c
test: not in test-setup in windows
apoorvam Sep 1, 2019
fe01e8d
test: fix some tests in windows
apoorvam Sep 1, 2019
ccf5fed
test: fix path in windows in unit tests
apoorvam Sep 1, 2019
f909f3a
test: convert path to quasi linux format when its windows path style
apoorvam Sep 1, 2019
8177567
test: check docker version
apoorvam Sep 1, 2019
a255c46
test: enable all OS | Skip two tests in windows since its not supported
apoorvam Sep 1, 2019
9acd574
test: retrigger build
apoorvam Sep 4, 2019
0b27215
test: Add os specific debug steps
apoorvam Sep 4, 2019
f2c2e51
test: update runner version
apoorvam Sep 4, 2019
28d22e1
Merge branch 'develop' into github-actions-dunner-test
apoorvam Sep 4, 2019
79c4e78
test: update dep
apoorvam Sep 4, 2019
1bd441c
test: Make changes since dep is removed
apoorvam Sep 4, 2019
3289070
test: add reason for win not using make ci
apoorvam Sep 4, 2019
55c36f9
test: retrigger build
apoorvam Sep 5, 2019
c812f2a
test: fix compile error
apoorvam Sep 5, 2019
c268097
test: fix unit test
apoorvam Sep 5, 2019
ea96b8b
test: update debug statements
apoorvam Sep 5, 2019
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
63 changes: 63 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Dunner CI

on: [push]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- name: Setup Go
uses: actions/setup-go@v1
with:
go-version: '1.11.x'

- name: Checkout Dunner
uses: actions/checkout@v1
with:
fetch-depth: 1

- name: Debug
if: matrix.os == 'windows-latest'
run: |
pwd
echo gopath: %GOPATH%
go env GOPATH
ls %GOPATH%

- name: Debug
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macOS-latest'
run: |
pwd
echo $GOPATH
go env GOPATH
ls $GOPATH

- name: Build Dunner and run unit tests
if: matrix.os == 'ubuntu-latest'
run: |
make setup
make ci
$(go env GOPATH)/bin/dunner version
$(go env GOPATH)/bin/dunner do show

- name: Build Dunner and run unit tests
if: matrix.os == 'macOS-latest'
# Not running unit tests in mac since there is no docker support via github actions
run: |
make setup
make fmt lint vet install
$(go env GOPATH)/bin/dunner version
$(go env GOPATH)/bin/dunner do show

# Not using make ci in windows because test-image is not working for windows as busybox image is not available
- name: Build Dunner and run unit tests
if: matrix.os == 'windows-latest'
run: |
make setup
make fmt lint vet
go test -v ./...
%GOPATH%bin\dunner version
%GOPATH%bin\dunner do show
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ GO_FILES=$(ALL_PACKAGES)

#Hooks
PRECOMMIT_HOOK="./resources/git-hooks/pre-commit"

TEST_IMAGE_DIR="./resources/test-image/"

#Go parameters
GOCMD=go
GOINSTALL=$(GOCMD) install
GOTEST=$(GOCMD) test
GOPATH=$(shell go env GOPATH)
DEP=$(GOPATH)/bin/dep
GOLINT=$(GOPATH)/bin/golint
.PHONY : all install vet fmt test lint build

all: build test fmt lint vet
Expand Down Expand Up @@ -49,7 +51,7 @@ fmt:
@go fmt $(ALL_PACKAGES)

lint:
@golint -set_exit_status $(GO_FILES)
@$(GOLINT) -set_exit_status $(GO_FILES)

precommit: build test fmt lint vet

Expand Down
13 changes: 11 additions & 2 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,26 @@ import (
"net/http"
"os"
"os/exec"
"os/user"
"path"
"strings"
"time"

"github.com/leopardslab/dunner/internal/logger"
)

var log = logger.Log
func init() {
user, err := user.Current()
if err != nil {
panic(err)
}
HomeDir = user.HomeDir
}

// HomeDir is the environment variable HOME
var HomeDir = os.Getenv("HOME")
var HomeDir string
var log = logger.Log

var userDir = os.Getenv("user")

// progressReader is for indicating the download / upload progress on the console
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func ValidateMountDir(ctx context.Context, fl validator.FieldLevel) bool {
}
validPerm := false
for _, perm := range validDirPermissionModes {
if mountValues[2] == perm {
if mountValues[len(mountValues)-1] == perm {
validPerm = true
}
}
Expand Down
61 changes: 30 additions & 31 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -207,27 +209,14 @@ func TestConfigs_ValidateWithInvalidMountFormat(t *testing.T) {
}
}

// FIXME: Skipped in Windows. Since paths with colon is not incorporated in Dunner, this will not possible for now.
func TestConfigs_ValidateWithValidMountDirectory(t *testing.T) {
step := getSampleStep()
wd, _ := os.Getwd()
step.Mounts = []string{fmt.Sprintf("%s:%s:w", wd, wd)}
var tasks = make(map[string]Task)
tasks["stats"] = Task{Steps: []Step{step}}
var configs = &Configs{
Tasks: tasks,
if runtime.GOOS == "windows" {
return
}

errs := configs.Validate()

if errs != nil {
t.Fatalf("expected no errors, got %s", errs)
}
}

func TestConfigs_ValidateWithMountDirFromEnv(t *testing.T) {
step := getSampleStep()
wd, _ := os.Getwd()
step.Mounts = []string{fmt.Sprintf("%s:%s:w", wd, wd)}
step.Mounts = []string{fmt.Sprintf("%s:/app:w", wd)}
var tasks = make(map[string]Task)
tasks["stats"] = Task{Steps: []Step{step}}
var configs = &Configs{
Expand All @@ -241,10 +230,14 @@ func TestConfigs_ValidateWithMountDirFromEnv(t *testing.T) {
}
}

// FIXME: Skipped in Windows. Since paths with colon is not incorporated in Dunner, this will not possible for now.
func TestConfigs_ValidateWithNoModeGiven(t *testing.T) {
if runtime.GOOS == "windows" {
return
}
step := getSampleStep()
wd, _ := os.Getwd()
step.Mounts = []string{fmt.Sprintf("%s:%s", wd, wd)}
step.Mounts = []string{fmt.Sprintf("%s:/app", wd)}
var tasks = make(map[string]Task)
tasks["stats"] = Task{Steps: []Step{step}}
var configs = &Configs{
Expand Down Expand Up @@ -388,6 +381,9 @@ func TestInitValidatorForEmptyTag(t *testing.T) {
}
}

var dummyEnvName = "DUNNER_TEST_ENV"
var dummyEnvValue = "DUNNER_TEST_ENV_VALUE"

var lookupEnvtests = []struct {
in string
out string
Expand All @@ -397,14 +393,14 @@ var lookupEnvtests = []struct {
{"foo", "foo", nil},
{"/foo/bar", "/foo/bar", nil},
{"/foo/`$bar", "/foo/`$bar", nil},
{util.HomeDir, util.HomeDir, nil},
{"`$HOME`", util.HomeDir, nil},
{"`$HOME`/foo", util.HomeDir + "/foo", nil},
{"`$HOME`/foo/`$HOME`", util.HomeDir + "/foo/" + util.HomeDir, nil},
{"`$DUNNER_TEST_ENV`", dummyEnvValue, nil},
{"`$DUNNER_TEST_ENV`/foo", fmt.Sprintf("%s/foo", dummyEnvValue), nil},
{"`$DUNNER_TEST_ENV`/foo/`$DUNNER_TEST_ENV`", fmt.Sprintf("%s/foo/%s", dummyEnvValue, dummyEnvValue), nil},
{"`$INVALID_TEST`/foo", "`$INVALID_TEST`/foo", fmt.Errorf("could not find environment variable 'INVALID_TEST'")},
}

func TestLookUpDirectory(t *testing.T) {
os.Setenv(dummyEnvName, dummyEnvValue)
for _, tt := range lookupEnvtests {
t.Run(tt.in, func(t *testing.T) {
parsedDir, err := lookupDirectory(tt.in)
Expand All @@ -420,7 +416,9 @@ func TestLookUpDirectory(t *testing.T) {

func TestDecodeMount(t *testing.T) {
step := &docker.Step{}
mounts := []string{fmt.Sprintf("%s:/app:r", util.HomeDir)}
currentDirName := "test_dir"
mounts := []string{fmt.Sprintf("%s:/app:r", currentDirName)}
absEnv, _ := filepath.Abs(currentDirName)

err := DecodeMount(mounts, step)

Expand All @@ -433,14 +431,15 @@ func TestDecodeMount(t *testing.T) {
if len((*step).ExtMounts) != 1 {
t.Fatalf("expected ExtMounts to be of length 1, got %d", len((*step).ExtMounts))
}
if (*step).ExtMounts[0].Source != util.HomeDir {
t.Fatalf("expected ExtMounts to be %s, got %s", util.HomeDir, (*step).ExtMounts[0].Source)
if (*step).ExtMounts[0].Source != absEnv {
t.Fatalf("expected ExtMounts Source to be %s, got %s", absEnv, (*step).ExtMounts[0].Source)
}
}

func TestDecodeMountWithEnvironmentVariable(t *testing.T) {
func TestDecodeMountWithRelativeSource(t *testing.T) {
absEnv, _ := filepath.Abs(dummyEnvValue)
step := &docker.Step{}
mounts := []string{"/tmp:/app"}
mounts := []string{fmt.Sprintf("%s:%s", dummyEnvValue, dummyEnvValue)}

err := DecodeMount(mounts, step)

Expand All @@ -453,11 +452,11 @@ func TestDecodeMountWithEnvironmentVariable(t *testing.T) {
if len((*step).ExtMounts) != 1 {
t.Fatalf("expected ExtMounts to be of length 1, got %d", len((*step).ExtMounts))
}
if (*step).ExtMounts[0].Source != "/tmp" {
t.Fatalf("expected ExtMounts Source to be '/tmp', got %s", (*step).ExtMounts[0].Source)
if (*step).ExtMounts[0].Source != absEnv {
t.Fatalf("expected ExtMounts Source to be %s, got %s", absEnv, (*step).ExtMounts[0].Source)
}
if (*step).ExtMounts[0].Target != "/app" {
t.Fatalf("expected ExtMounts Source to be '/app', got %s", (*step).ExtMounts[0].Target)
if (*step).ExtMounts[0].Target != dummyEnvValue {
t.Fatalf("expected ExtMounts Source to be %s, got %s", dummyEnvValue, (*step).ExtMounts[0].Target)
}
}

Expand Down
9 changes: 5 additions & 4 deletions pkg/initialize/initialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"

"github.com/leopardslab/dunner/internal"
Expand Down Expand Up @@ -81,13 +82,13 @@ func TestInitializeFilenameIsInvalid(t *testing.T) {
defer revert()
var filename = "#Q$EJL_doesntexist/.test_dunner.yml"

expected := fmt.Sprintf("open %s: no such file or directory", filename)
expected := fmt.Sprintf("open %s: ", filename)
err := InitProject(filename, nil)
if err == nil {
t.Errorf("expected: %s, got nil", expected)
t.Errorf("expected error prefix: %s, got nil", expected)
}
if expected != err.Error() {
t.Errorf("expected: %s, got: %s", expected, err.Error())
if !strings.HasPrefix(err.Error(), expected) {
t.Errorf("expected prefix: %s, got: %s", expected, err.Error())
}
}

Expand Down