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

Make golang build on Github #266

Merged
merged 7 commits into from
Dec 9, 2021
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
55 changes: 37 additions & 18 deletions .github/workflows/build-golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,13 @@ on:
- ".github/workflows/*golang*"

jobs:
test_go:
name: Test
build-and-test-golang:
name: Build, Test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
artifact_name: linux
- os: windows-latest
artifact_name: windows-gnu
- os: macos-latest
artifact_name: macos
os: [ ubuntu-latest, windows-latest] # , 'macos-latest' ] disabled due to macos issues
steps:
- uses: actions/checkout@v2
- name: Download workflow artifact
Expand All @@ -41,16 +36,23 @@ jobs:
uses: actions/setup-go@v2
with:
go-version: ^1.16
- name: Display Golang version
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Build and Test Golang
run: |
go version
go install golang.org/x/lint/golint@latest
go install github.com/jstemmer/go-junit-report@latest
- name: Build, Test, Pack
run: |
./devops/BuildGolang.ps1 -GitTag ${{ github.ref }} -TestOutput "test_output_${{ matrix.os }}.xml" -ArtifactName "${{ matrix.artifact_name }}"
python ../../devops/build_sdks.py
go build
golint
go test -v | go-junit-report > test_output.xml
shell: pwsh
working-directory: go/services
env:
API_GITHUB_TOKEN: ${{ secrets.API_GITHUB_TOKEN }}
LD_LIBRARY_PATH: "${{ github.workspace }}/go/services"
DYLD_FALLBACK_LIBRARY_PATH: "${{ github.workspace }}/go/services"
DYLD_LIBRARY_PATH: "${{ github.workspace }}/go/services"
Expand All @@ -59,9 +61,26 @@ jobs:
TEST_SERVER_ENDPOINT: staging-internal.trinsic.cloud
TEST_SERVER_PORT: 443
TEST_SERVER_USE_TLS: true
- name: Publish Test Report
uses: mikepenz/action-junit-report@v2
if: always() # always run even if the previous step fails
- name: Upload Unit Test Results - Golang
if: always()
uses: actions/upload-artifact@v2
with:
name: Golang Unit Test Results (${{ matrix.os }})
path: 'go/services/test_output*.xml'

publish-test-results-golang:
name: Publish Test Results
needs: build-and-test-golang
runs-on: ubuntu-latest
if: always()

steps:
- name: Download Artifacts
uses: actions/download-artifact@v2
with:
path: golang_artifacts
- name: Publish Test Report - Golang
uses: EnricoMi/publish-unit-test-result-action@v1.23
with:
report_paths: ./go/services/test_output*.xml
fail_on_failure: true
files: 'golang_artifacts/**/*.xml'
check_name: Golang Test Report
50 changes: 0 additions & 50 deletions devops/BuildGolang.ps1

This file was deleted.

2 changes: 1 addition & 1 deletion devops/build_sdks.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def build_ruby(args) -> None:

def build_golang(args) -> None:
# Update version in setup.cfg
golang_dir = abspath(join(dirname(__file__), '..', 'go', 'okapi'))
golang_dir = abspath(join(dirname(__file__), '..', 'go', 'services'))
# Copy in the binaries
copy_okapi_libs(golang_dir, 'windows-gnu')

Expand Down
11 changes: 11 additions & 0 deletions go/services/loadcerts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build !windows
// +build !windows

package services

import "crypto/x509"

func loadWindowsCerts() []*x509.Certificate {
var certs []*x509.Certificate
return certs
}
46 changes: 46 additions & 0 deletions go/services/loadcerts_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//go:build windows
// +build windows

package services

import (
"crypto/x509"
"fmt"
"syscall"
"unsafe"
)

func loadWindowsCerts() []*x509.Certificate {
const CRYPT_E_NOT_FOUND = 0x80092004
// Copied from: https://github.com/golang/go/issues/16736#issuecomment-540373689
// Because golang team apparently doesn't believe that Windows deserves security.
storeHandle, err := syscall.CertOpenSystemStore(0, syscall.StringToUTF16Ptr("Root"))
if err != nil {
fmt.Println(syscall.GetLastError())
}

var certs []*x509.Certificate
var cert *syscall.CertContext
for {
cert, err = syscall.CertEnumCertificatesInStore(storeHandle, cert)
if err != nil {
if errno, ok := err.(syscall.Errno); ok {
if errno == CRYPT_E_NOT_FOUND {
break
}
}
fmt.Println(syscall.GetLastError())
}
if cert == nil {
break
}
// Copy the buf, since ParseCertificate does not create its own copy.
buf := (*[1 << 20]byte)(unsafe.Pointer(cert.EncodedCert))[:]
buf2 := make([]byte, cert.Length)
copy(buf2, buf)
if c, err := x509.ParseCertificate(buf2); err == nil {
certs = append(certs, c)
}
}
return certs
}
25 changes: 15 additions & 10 deletions go/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import (
"fmt"
"github.com/trinsic-id/okapi/go/okapi"
"github.com/trinsic-id/okapi/go/okapiproto"
"google.golang.org/grpc/credentials"
"net/url"
"os"
"strconv"
"time"

sdk "github.com/trinsic-id/sdk/go/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/proto"
_ "google.golang.org/protobuf/types/known/structpb"
"net/url"
"os"
"runtime"
"strconv"
"time"
)

type Document map[string]interface{}
Expand Down Expand Up @@ -138,12 +138,17 @@ func CreateChannel(serviceAddress string, blockOnOpen bool) (*grpc.ClientConn, e
if serviceUrl.Scheme == "http" {
dialOptions = append(dialOptions, grpc.WithInsecure())
} else {
// TODO - Get the credentials bundle
pool, err := x509.SystemCertPool()
if err != nil {
rootCAs, err := x509.SystemCertPool()
if err != nil && runtime.GOOS == "windows" {
rootCAs = x509.NewCertPool()
windowsCerts := loadWindowsCerts()
for _, cert := range windowsCerts {
rootCAs.AddCert(cert)
}
} else if err != nil {
return nil, err
}
creds := credentials.NewClientTLSFromCert(pool, "")
creds := credentials.NewClientTLSFromCert(rootCAs, "")
dialOptions = append(dialOptions, grpc.WithTransportCredentials(creds))
}
channel, err := grpc.Dial(dialUrl, dialOptions...)
Expand Down