Skip to content

Commit

Permalink
Add github action build and release workflows for synse modbus ip plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
erik-east committed Sep 11, 2023
1 parent 63712e9 commit 446637c
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 19 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: build
on:
push:
branches:
- '*'
pull_request: {}

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
- run: "go vet ./..."
- name: Lint
uses: dominikh/[email protected]
with:
version: "2022.1.3"
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
- run: "make test"
snapshot-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
- name: Set GOLANG_VERSION
run: |
echo "GOLANG_VERSION=$(go version | awk '{ print $3 }')" >> $GITHUB_ENV
- name: Snapshot Build
uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --snapshot --skip-publish --clean
33 changes: 33 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: release
on:
push:
tags:
- 'v*'

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
- name: Set GOLANG_VERSION
run: |
echo "GOLANG_VERSION=$(go version | awk '{ print $3 }')" >> $GITHUB_ENV
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Tagged Release
uses: goreleaser/goreleaser-action@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
distribution: goreleaser
version: latest
args: release --clean
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ builds:
- -X github.com/vapor-ware/synse-sdk/sdk.BuildDate={{ .Date }}
- -X github.com/vapor-ware/synse-sdk/sdk.GitCommit={{ .ShortCommit }}
- -X github.com/vapor-ware/synse-sdk/sdk.GitTag={{ .Tag }}
- -X github.com/vapor-ware/synse-sdk/sdk.GoVersion={{ .Env.GOVERSION }}
- -X github.com/vapor-ware/synse-sdk/sdk.GoVersion={{ .Env.GOLANG_VERSION }}
- -X github.com/vapor-ware/synse-sdk/sdk.PluginVersion={{ .Version }}
goos:
- linux
Expand Down
14 changes: 7 additions & 7 deletions pkg/devices/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,11 @@ func MapBulkReadData(bulkReadMap map[ModbusBulkReadKey][]*ModbusBulkRead, keyOrd

if int(endDataOffset) > len(readResults) {
if k.FailOnError {
return nil, fmt.Errorf("Bounds check failure. startDataOffset: %v, endDataOffset: %v, readResultsLength: %v",
return nil, fmt.Errorf("bounds check failure. startDataOffset: %v, endDataOffset: %v, readResultsLength: %v",
startDataOffset, endDataOffset, readResultsLength)
}
// nil reading.
log.Errorf("No data. Attempt to read beyond bounds. startDataOffset: %v, endDataOffset: %v, readResultsLength: %v",
log.Errorf("no data. Attempt to read beyond bounds. startDataOffset: %v, endDataOffset: %v, readResultsLength: %v",
startDataOffset, endDataOffset, readResultsLength)
// Make a reading with a nil Reading.Value.
reading, err = theOutput.MakeReading(nil)
Expand All @@ -446,7 +446,7 @@ func MapBulkReadData(bulkReadMap map[ModbusBulkReadKey][]*ModbusBulkRead, keyOrd
return nil, err
}
}
log.Debugf("Appending reading: %#v, device: %v, output: %#v", reading, device, theOutput)
log.Debugf("appending reading: %#v, device: %v, output: %#v", reading, device, theOutput)
readings = append(readings, reading)

// Add to accounted for.
Expand All @@ -456,9 +456,9 @@ func MapBulkReadData(bulkReadMap map[ModbusBulkReadKey][]*ModbusBulkRead, keyOrd
if len(readings) > 0 {
readContext := sdk.NewReadContext(device, readings)
readContexts = append(readContexts, readContext)
log.Debugf("Appending readContext: %#v, device: %v", readContext, device)
log.Debugf("appending readContext: %#v, device: %v", readContext, device)
} else {
log.Debugf("No readings to append. Not creating read context")
log.Debugf("no readings to append. Not creating read context")
}
} // End for each device.
} // End for each read.
Expand Down Expand Up @@ -558,7 +558,7 @@ func (brm *bulkReadManager) addModbusDevice(d *sdk.Device) (err error) {
return
}

return fmt.Errorf("Unknown device handler %s", d.Handler)
return fmt.Errorf("unknown device handler %s", d.Handler)
}

// bulkReadSetupMutex puts a critical section around bulkReadManager.setup() so
Expand Down Expand Up @@ -638,7 +638,7 @@ func (brm *bulkReadManager) GetBulkReadMap(mapID string) (
return brm.inputBulkReadMap, brm.inputKeyOrder, nil
}

err = fmt.Errorf("Unknown mapId %s", mapID)
err = fmt.Errorf("unknown mapId %s", mapID)
return
}

Expand Down
11 changes: 5 additions & 6 deletions pkg/devices/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,11 @@ func dumpReadContexts(t *testing.T, readContexts []*sdk.ReadContext) {

// dumpReadings dumps out the given readings to the test log.
// func dumpReadings(t *testing.T, readings []*output.Reading) {
func dumpReadings(t *testing.T, readings []*output.Reading) {
for i := 0; i < len(readings); i++ {
t.Logf("reading[%v]: %#v", i, readings[i])
t.Logf("reading.Value: 0x%04x, type %T", readings[i].Value, readings[i].Value)
}
}
// for i := 0; i < len(readings); i++ {
// t.Logf("reading[%v]: %#v", i, readings[i])
// t.Logf("reading.Value: 0x%04x, type %T", readings[i].Value, readings[i].Value)
// }
// }

// populateBulkReadMap populates a bulk read map with raw modbus data.
func populateBulkReadMap(t *testing.T, bulkReadMap map[ModbusBulkReadKey][]*ModbusBulkRead, keyOrder []ModbusBulkReadKey) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/devices/holding_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func writeHoldingRegister(device *sdk.Device, data *sdk.WriteData) (err error) {
dataString := string(modbusData)
register64, err := strconv.ParseUint(dataString, 16, 16)
if err != nil {
return fmt.Errorf("Unable to parse uint16 %v", dataString)
return fmt.Errorf("unable to parse uint16 %v", dataString)
}
registerData := uint16(register64)

Expand Down
6 changes: 3 additions & 3 deletions pkg/devices/input_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func bulkReadInputRegisters(devices []*sdk.Device) (readContexts []*sdk.ReadCont
var client modbus.Client
var handler *modbus.TCPClientHandler
var deviceData *config.ModbusDeviceData
client, handler, deviceData, err = GetBulkReadClient(k)
if err != nil {
return nil, err
client, handler, deviceData, error = GetBulkReadClient(k)
if error != nil {
return nil, error
}

// For read in v, perform each read.
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (b Bytes) Int64() (out int64, err error) {

// Bool converts the byte slice to a bool.
func (b Bytes) Bool() bool {
if b == nil || len(b) == 0 {
if len(b) == 0 {
return false
}
return !(b[0] == 0)
Expand Down

0 comments on commit 446637c

Please sign in to comment.