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

Set up CI with Azure Pipelines #123

Merged
merged 2 commits into from
Oct 16, 2020
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
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# TileDB Go Bindings

[![GoDoc](https://godoc.org/github.com/TileDB-Inc/TileDB-Go?status.svg)](http://godoc.org/github.com/TileDB-Inc/TileDB-Go)
[![Build Status](https://travis-ci.org/TileDB-Inc/TileDB-Go.svg?branch=master)](https://travis-ci.org/TileDB-Inc/TileDB-Go)
[![Build Status](https://dev.azure.com/TileDB-Inc/CI/_apis/build/status/TileDB-Inc.TileDB-Go?branchName=refs%2Fpull%2F123%2Fmerge)](https://dev.azure.com/TileDB-Inc/CI/_build/latest?definitionId=25&branchName=refs%2Fpull%2F123%2Fmerge)

This package provides [TileDB](https://github.com/TileDB-Inc/TileDB) golang bindings via cgo. The bindings have been
designed to be idomatic Go. `runtime.set_finalizer` is used to ensure proper
Expand Down
45 changes: 45 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Go
# Build your Go project.
# Add steps that test, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/go

trigger:
batch: true
branches:
include:
- master
paths:
exclude:
- README.md
- LICENSE
- .gitignore

pr:
autoCancel: true
branches:
include:
- master
paths:
exclude:
- README.md
- LICENSE
- .gitignore

variables:
GOPATH: '$(Pipeline.Workspace)/go'

stages:
- stage: Linux_Test
jobs:
- template: templates/azure/jobs/test.yml
parameters:
pool:
vmImage: 'ubuntu-18.04'
os: 'linux'
- stage: Mac_Test
jobs:
- template: templates/azure/jobs/test.yml
parameters:
pool:
vmImage: 'macos-10.14'
os: 'macos'
3 changes: 2 additions & 1 deletion config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ func TestFileConfig(t *testing.T) {
os.Remove(tmpPath)
}

config.SaveToFile(tmpPath)
err = config.SaveToFile(tmpPath)
assert.Nil(t, err)

config2, err := LoadConfig(tmpPath)
assert.Nil(t, err)
Expand Down
5 changes: 4 additions & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ func NewContext(config *Config) (*Context, error) {
context.Free()
})

context.setDefaultTags()
err1 := context.setDefaultTags()
if err != nil {
return nil, fmt.Errorf("Error creating tiledb context: %s", err1.Error())
}

return &context, nil
}
Expand Down
3 changes: 2 additions & 1 deletion context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func ExampleNewContext() {
// handle error
return
}
// Output: false
// Output: true
fmt.Println(isS3Supported)
}

Expand All @@ -56,6 +56,7 @@ func TestNewContext(t *testing.T) {
// Test context with config
context, err = NewContext(config)
assert.Nil(t, err)
assert.NotNil(t, context)
}

// TestGetContextConfig tests setting a new context
Expand Down
9 changes: 6 additions & 3 deletions enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,13 @@ func (d *Datatype) FromString(s string) error {
}

// DatatypeFromString converts from a datatype string to enum
func DatatypeFromString(s string) Datatype {
func DatatypeFromString(s string) (Datatype, error) {
var d Datatype
d.FromString(s)
return d
err := d.FromString(s)
if err != nil {
return TILEDB_ANY, err
}
return d, nil
}

// ReflectKind returns the reflect kind given a datatype
Expand Down
27 changes: 15 additions & 12 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type Query struct {
tiledbQuery *C.tiledb_query_t
array *Array
context *Context
uri string
buffers []interface{}
bufferMutex sync.Mutex
resultBufferElements map[string][2]*uint64
Expand All @@ -36,7 +35,7 @@ type RangeLimits struct {

// MarshalJSON implements the Marshaler interface for RangeLimits
func (r RangeLimits) MarshalJSON() ([]byte, error) {
rangeLimitMap := make(map[string]interface{}, 0)
rangeLimitMap := make(map[string]interface{})
rangeLimitMap["end"] = r.end
rangeLimitMap["start"] = r.start

Expand Down Expand Up @@ -75,7 +74,7 @@ func NewQuery(ctx *Context, array *Array) (*Query, error) {
query.Free()
})

query.resultBufferElements = make(map[string][2]*uint64, 0)
query.resultBufferElements = make(map[string][2]*uint64)

return &query, nil
}
Expand Down Expand Up @@ -1209,7 +1208,7 @@ func (q *Query) SetBufferVar(attributeOrDimension string, offset []uint64, buffe
// second is number of elements in the data buffer. For fixed sized attributes
// (and coordinates), the first is always 0.
func (q *Query) ResultBufferElements() (map[string][2]uint64, error) {
elements := make(map[string][2]uint64, 0)
elements := make(map[string][2]uint64)

// Will need the schema to infer data type size for attributes
schema, err := q.array.Schema()
Expand Down Expand Up @@ -1756,40 +1755,44 @@ is the maximum number of elements for that attribute in the given subarray.
*/
func (q *Query) EstimateBufferElements() (map[string][2]uint64, error) {
// Build map
ret := make(map[string][2]uint64, 0)
ret := make(map[string][2]uint64)
// Get schema
schema, err := q.array.Schema()
if err != nil {
return nil, fmt.Errorf("Error getting MaxBufferElements for array: %s", err)
return nil, fmt.Errorf("Error getting EstimateBufferElements for array: %s", err)
}

attributes, err := schema.Attributes()
if err != nil {
return nil, fmt.Errorf("Error getting MaxBufferElements for array: %s", err)
return nil, fmt.Errorf("Error getting EstimateBufferElements for array: %s", err)
}
// Loop through each attribute
for _, attribute := range attributes {

// Check if attribute is variable attribute or not
cellValNum, err := attribute.CellValNum()
if err != nil {
return nil, fmt.Errorf("Error getting MaxBufferElements for array: %s", err)
return nil, fmt.Errorf("Error getting EstimateBufferElements for array: %s", err)
}

// Get datatype size to convert byte lengths to needed buffer sizes
dataType, err := attribute.Type()
if err != nil {
return nil, fmt.Errorf("Error getting EstimateBufferElements for array: %s", err)
}

dataTypeSize := dataType.Size()

// Get attribute name
name, err := attribute.Name()
if err != nil {
return nil, fmt.Errorf("Error getting MaxBufferElements for array: %s", err)
return nil, fmt.Errorf("Error getting EstimateBufferElements for array: %s", err)
}

if cellValNum == TILEDB_VAR_NUM {
bufferOffsetSize, bufferValSize, err := q.EstResultSizeVar(name)
if err != nil {
return nil, fmt.Errorf("Error getting MaxBufferElements for array: %s", err)
return nil, fmt.Errorf("Error getting EstimateBufferElements for array: %s", err)
}
// Set sizes for attribute in return map
ret[name] = [2]uint64{
Expand All @@ -1798,7 +1801,7 @@ func (q *Query) EstimateBufferElements() (map[string][2]uint64, error) {
} else {
bufferValSize, err := q.EstResultSize(name)
if err != nil {
return nil, fmt.Errorf("Error getting MaxBufferElements for array: %s", err)
return nil, fmt.Errorf("Error getting EstimateBufferElements for array: %s", err)
}
ret[name] = [2]uint64{0, *bufferValSize / dataTypeSize}
}
Expand All @@ -1807,7 +1810,7 @@ func (q *Query) EstimateBufferElements() (map[string][2]uint64, error) {
// Handle coordinates
domain, err := schema.Domain()
if err != nil {
return nil, fmt.Errorf("Could not get domain for MaxBufferElements: %s", err)
return nil, fmt.Errorf("Could not get domain for EstimateBufferElements: %s", err)
}

ndims, err := domain.NDim()
Expand Down
2 changes: 0 additions & 2 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1289,8 +1289,6 @@ func TestQueryWrite(t *testing.T) {
assert.Equal(t, len(bufferA4), elementsCopied)

_, _, err = query.SetBufferVar("a4", offsetBufferA4, bufferA4)
// Immediately set bufferA4 to nil to validate underlying array is not GC'ed
bufferA4 = nil
assert.Nil(t, err)

bufferA5 := "hello" + "world"
Expand Down
21 changes: 0 additions & 21 deletions scripts/ci_install_tiledb.sh

This file was deleted.

8 changes: 0 additions & 8 deletions scripts/travis.gofmt.sh

This file was deleted.

64 changes: 64 additions & 0 deletions templates/azure/jobs/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
jobs:
- job: RunTests
strategy:
matrix:
GoVersion_1_13:
go.version: '1.13'
GoVersion_1_14:
go.version: '1.14'

pool:
vmImage: 'ubuntu-18.04'

steps:
- script: echo ${{ parameters.os }}

- template: ../steps/setup_go.yml
parameters:
goVersion: '$(go.version)'

- template: ../steps/format_go.yml

- ${{ if eq(parameters.os, 'linux') }}:
- template: ../steps/install_tiledb_linux.yml

- ${{ if eq(parameters.os, 'macos') }}:
- template: ../steps/install_tiledb_macos.yml

- script: |
set -e -x
go version
go get -u github.com/jstemmer/go-junit-report
go get github.com/axw/gocov/gocov
go get github.com/AlekSi/gocov-xml
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.24.0
curl https://cdn.shiftleft.io/download/sl > $(go env GOPATH)/bin/sl && chmod a+rx $(go env GOPATH)/bin/sl
displayName: 'Install Dependencies'

- ${{ if eq(parameters.os, 'linux') }}:
- script: |
set -e -x
golangci-lint run
displayName: 'Run Code Quality Checks'

- script: |
set -v -x
go test -v -coverprofile=coverage.txt -covermode count ./... > test_results.txt
go-junit-report < test_results.txt > report.xml
displayName: 'Run Unit Tests'
- task: PublishTestResults@2
displayName: 'Publish Test Results'
inputs:
testRunner: JUnit
testResultsFiles: $(System.DefaultWorkingDirectory)/**/report.xml

- script: |
set -e -x
gocov convert coverage.txt > coverage.json
gocov-xml < coverage.json > coverage.xml
displayName: 'Run Code Coverage Tests'
- task: PublishCodeCoverageResults@1
displayName: 'Publish Code Coverage'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(System.DefaultWorkingDirectory)/**/coverage.xml
11 changes: 11 additions & 0 deletions templates/azure/steps/format_go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
steps:
- script: |
ls -al
if [[ -n "$(gofmt -l .)" ]]; then
echo "TileDB-Go code is not formatted:"
gofmt -d .
exit 1
else
echo "TileDB-Go code is well formatted."
fi
displayName: 'Checks formatting of Go code'
8 changes: 8 additions & 0 deletions templates/azure/steps/install_tiledb_linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Install TileDB in a system location
steps:
- script: |
set -e -x
curl --location -o tiledb.tar.gz https://github.com/TileDB-Inc/TileDB/releases/download/2.0.8/tiledb-linux-2.0.8-db41376-full.tar.gz \
&& sudo tar -C /usr/local -xf tiledb.tar.gz
sudo ldconfig /usr/local/lib
displayName: 'Install TileDB'
7 changes: 7 additions & 0 deletions templates/azure/steps/install_tiledb_macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Install TileDB in a system location
steps:
- script: |
set -e -x
curl --location -o tiledb.tar.gz https://github.com/TileDB-Inc/TileDB/releases/download/2.0.8/tiledb-macos-2.0.8-db41376-full.tar.gz \
&& sudo tar -C /usr/local -xf tiledb.tar.gz
displayName: 'Install TileDB'
Loading