Skip to content

Commit

Permalink
Merge pull request #169 from GeoNet/reusableWorkflow
Browse files Browse the repository at this point in the history
ci: use reusable-go-apps workflow
  • Loading branch information
sue-h-gns authored May 21, 2024
2 parents 1a968ac + 510ebdf commit 0885288
Show file tree
Hide file tree
Showing 24 changed files with 97 additions and 111 deletions.
52 changes: 15 additions & 37 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,19 @@ permissions:
contents: write
pull-requests: write
id-token: write
env:
IMAGE_LOCALSTACK: docker.io/localstack/localstack:3.2.0
jobs:
go-build:
if: ${{ contains(fromJSON('["workflow_call", "push", "pull_request"]'), github.event_name) && startsWith(github.repository, 'GeoNet/') != false }}
uses: GeoNet/Actions/.github/workflows/reusable-go-build-smoke-test.yml@main
gofmt:
if: ${{ contains(fromJSON('["workflow_call", "push", "pull_request"]'), github.event_name) && startsWith(github.repository, 'GeoNet/') != false }}
uses: GeoNet/Actions/.github/workflows/reusable-gofmt.yml@main
golangci-lint:
if: ${{ contains(fromJSON('["workflow_call", "push", "pull_request"]'), github.event_name) && startsWith(github.repository, 'GeoNet/') != false }}
uses: GeoNet/Actions/.github/workflows/reusable-golangci-lint.yml@main
go-vet:
if: ${{ contains(fromJSON('["workflow_call", "push", "pull_request"]'), github.event_name) && startsWith(github.repository, 'GeoNet/') != false }}
uses: GeoNet/Actions/.github/workflows/reusable-go-vet.yml@main
go-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
with:
go-version-file: go.mod
cache-dependency-path: go.sum
check-latest: true
- name: setup
run: |
docker run --name localstack -d --rm -p 4566:4566 -p 4510-4559:4510-4559 "$IMAGE_LOCALSTACK"
echo "waiting for localstack to be ready"
until curl -v localhost:4566; do
sleep 1s
done
echo "waiting for localstack service status to be ready"
until docker exec localstack /opt/code/localstack/bin/localstack status services; do
sleep 1s
done
- name: test
run: |
go test -v ./... --tags localstack
build-app:
uses: GeoNet/Actions/.github/workflows/reusable-go-apps.yml@main
with:
testSetup: |
docker run --name localstack -d --rm -p 4566:4566 -p 4510-4559:4510-4559 docker.io/localstack/localstack:3.2.0
echo "waiting for localstack to be ready"
until curl -v localhost:4566; do
sleep 1s
done
echo "waiting for localstack service status to be ready"
until docker exec localstack /opt/code/localstack/bin/localstack status services; do
sleep 1s
done
goTestExtraArgs: --tags localstack

3 changes: 2 additions & 1 deletion cfg/cfg_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package cfg_test

import (
"github.com/GeoNet/kit/cfg"
"os"
"strings"
"testing"

"github.com/GeoNet/kit/cfg"
)

func TestPostgresEnv(t *testing.T) {
Expand Down
7 changes: 4 additions & 3 deletions datalogger_pb/datalogger.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions fmp_pb/fmp.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions gloria_pb/gloria.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions haz_pb/haz.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions map180/bbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ type bbox struct {

/*
ValidBbox returns a nil error for a valid boundingBox. Valid options are one of:
* an empty string: ""
* a string definition of a bounding box using ',' separated
longitude latitude (float) on EPSG4327. This should be lower
- an empty string: ""
- a string definition of a bounding box using ',' separated
longitude latitude (float) on EPSG4327. This should be lower
left and upper right corners. It may cross 180. Longitude can be -180 to 180
or 0 to 360. Latitude must be <= 85.0 && >= -85.0 Examples:
"165,-48,179,-34" // New Zealand
Expand Down
55 changes: 27 additions & 28 deletions map180/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import (
"context"
"database/sql"
"fmt"
"github.com/golang/groupcache"
"log"
"regexp"
"strconv"
"strings"

"github.com/golang/groupcache"
)

const (
Expand Down Expand Up @@ -76,7 +77,7 @@ for land and lake layers. region must be a valid Region.
Example:
wm, err = map180.Init(db, map180.Region(`newzealand`), 256000000)
wm, err = map180.Init(db, map180.Region(`newzealand`), 256000000)
*/
func Init(d *sql.DB, region Region, cacheBytes int64) (*Map180, error) {
w := &Map180{}
Expand Down Expand Up @@ -331,38 +332,36 @@ func (w *Map180) Map(boundingBox string, width int, pts Points, insetBbox string
/*
MapRaw returns a Raw struct which can be used for drawing SVG maps e.g.,
raw, err := wm.MapRaw(bbox, width)
b := bytes.Buffer
b.WriteString(`<?xml version="1.0"?>`)
b.WriteString(fmt.Sprintf("<svg viewBox=\"0 0 %d %d\" xmlns=\"http://www.w3.org/2000/svg\">",
raw.Width, raw.Height))
b.WriteString(fmt.Sprintf("<rect x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" style=\"fill: azure\"/>", raw.Width, raw.Height))
b.WriteString(fmt.Sprintf("<path style=\"fill: wheat; stroke-width: 1; stroke-linejoin: round; stroke: lightslategrey\" d=\"%s\"/>", raw.Land))
b.WriteString(fmt.Sprintf("<path style=\"fill: azure; stroke-width: 1; stroke-linejoin: round; stroke: lightslategrey\" d=\"%s\"/>", raw.Lakes))
b.WriteString("</svg>")
raw, err := wm.MapRaw(bbox, width)
b := bytes.Buffer
b.WriteString(`<?xml version="1.0"?>`)
b.WriteString(fmt.Sprintf("<svg viewBox=\"0 0 %d %d\" xmlns=\"http://www.w3.org/2000/svg\">",
raw.Width, raw.Height))
b.WriteString(fmt.Sprintf("<rect x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" style=\"fill: azure\"/>", raw.Width, raw.Height))
b.WriteString(fmt.Sprintf("<path style=\"fill: wheat; stroke-width: 1; stroke-linejoin: round; stroke: lightslategrey\" d=\"%s\"/>", raw.Land))
b.WriteString(fmt.Sprintf("<path style=\"fill: azure; stroke-width: 1; stroke-linejoin: round; stroke: lightslategrey\" d=\"%s\"/>", raw.Lakes))
b.WriteString("</svg>")
The other properties can be used to scale and translate for drawing on the map e.g.,
type point struct {
latitude, longitude float64
x, y float64
}
// create pts []point with x,y, set to EPSG3857 and latitude longitude EPSG4326
// range of pts ...
switch raw.CrossesCentral && p.longitude > -180.0 && p.longitude < 0.0 {
case true:
p.x = (p.x + map180.Width3857 - raw.LLX) * raw.DX
p.y = (p.y - math.Abs(raw.YShift)) * raw.DX
case false:
p.x = (p.x - math.Abs(raw.XShift)) * raw.DX
p.y = (p.y - math.Abs(raw.YShift)) * raw.DX
}
type point struct {
latitude, longitude float64
x, y float64
}
// draw p on SVG.
// create pts []point with x,y, set to EPSG3857 and latitude longitude EPSG4326
// range of pts ...
switch raw.CrossesCentral && p.longitude > -180.0 && p.longitude < 0.0 {
case true:
p.x = (p.x + map180.Width3857 - raw.LLX) * raw.DX
p.y = (p.y - math.Abs(raw.YShift)) * raw.DX
case false:
p.x = (p.x - math.Abs(raw.XShift)) * raw.DX
p.y = (p.y - math.Abs(raw.YShift)) * raw.DX
}
// draw p on SVG.
*/
func (w *Map180) MapRaw(boundingBox string, width int) (mr Raw, err error) {
var b bbox
Expand Down
19 changes: 9 additions & 10 deletions map180/nzmap/nzmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ There are no external dependencies.
Calling code can draw markers on the maps as required. The closing </svg> tag must also be added.
var b bytes.Buffer
var pts nzmap.Points
var b bytes.Buffer
var pts nzmap.Points
pts.Medium(b)
pts.Medium(b)
for _, p := range pts {
if p.Visible() {
b.WriteString(fmt.Sprintf("<path d=\"M%d %d l5 0 l-5 -8 l-5 8 Z\" stroke-width=\"0\" fill=\"blue\" opacity=\"0.7\"></path>",
p.X(), p.Y()))
for _, p := range pts {
if p.Visible() {
b.WriteString(fmt.Sprintf("<path d=\"M%d %d l5 0 l-5 -8 l-5 8 Z\" stroke-width=\"0\" fill=\"blue\" opacity=\"0.7\"></path>",
p.X(), p.Y()))
}
}
}
b.WriteString("</svg>")
b.WriteString("</svg>")
*/
package nzmap

Expand Down
3 changes: 2 additions & 1 deletion metrics/counters_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package metrics_test

import (
"github.com/GeoNet/kit/metrics"
"runtime"
"strconv"
"testing"

"github.com/GeoNet/kit/metrics"
)

func TestMsgCounters(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion metrics/timers_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package metrics_test

import (
"github.com/GeoNet/kit/metrics"
"testing"
"time"

"github.com/GeoNet/kit/metrics"
)

func TestTimers(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion sc3ml/sc3ml_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// under /work/seismcompml07-test and make sure basic quake facts
// are not zero values. Run using:
//
// go test -tags=integration
// go test -tags=integration
func TestUnmarshalIntegration(t *testing.T) {
var s sc3ml.Seiscomp
var err error
Expand Down
1 change: 0 additions & 1 deletion seis/dl/doc.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// The dl module has been writen as a lightweight replacement for the C libdali library.
// It is aimed at clients that need to connect to a datalink server, either requesting inforamtion
// or for uploading most likely miniseed records.
//
package dl
1 change: 0 additions & 1 deletion seis/ms/doc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
// The ms module has been writen as a lightweight replacement for some parts of the libmseed C library.
//
package ms
1 change: 1 addition & 0 deletions seis/ms/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ms
import (
"encoding/binary"
"fmt"

//TODO: needs v 1.15 "hash/maphash"
"strconv"
"strings"
Expand Down
2 changes: 1 addition & 1 deletion seis/ms/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Record struct {
}

// NewMSRecord decodes and unpacks the record samples from a byte slice and returns a Record pointer,
//or an empty pointer and an error if it could not be decoded.
// or an empty pointer and an error if it could not be decoded.
func NewRecord(buf []byte) (*Record, error) {

var r Record
Expand Down
4 changes: 2 additions & 2 deletions seis/ms/steim.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func getNibble(word []byte, index int) uint8 {
return res
}

//value must be 0, 1, 2 or 3, the nibble must not have been previously set
// value must be 0, 1, 2 or 3, the nibble must not have been previously set
func writeNibble(word []byte, index int, value uint8) {
b := word[index/4]
i := index % 4
Expand All @@ -23,7 +23,7 @@ func writeNibble(word []byte, index int, value uint8) {
}

/*
Takes v: an integer where only the first numbits bits are used to represent the number and returns an int32
Takes v: an integer where only the first numbits bits are used to represent the number and returns an int32
*/
func uintVarToInt32(v uint32, numbits uint8) int32 {
neg := (v & (0x1 << (numbits - 1))) != 0 //check positive/negative
Expand Down
1 change: 1 addition & 0 deletions seis/sl/conn_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build link
// +build link

package sl
Expand Down
13 changes: 6 additions & 7 deletions seis/sl/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
//
// An example Seedlink application can be as simple as:
//
// if err := sl.NewSLink().Collect(func(seq string, data []byte) (bool, error) {
// //... process miniseed data
// if err := sl.NewSLink().Collect(func(seq string, data []byte) (bool, error) {
// //... process miniseed data
//
// return false, nil
// }); err != nil {
// log.Fatal(err)
// }
// return false, nil
// }); err != nil {
// log.Fatal(err)
// }
//
// A state mechanism is available for the initial connection, although it is the clients responsibility to
// periodically maintain its content.
//
package sl
1 change: 1 addition & 0 deletions seis/sl/slink_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build link
// +build link

package sl
Expand Down
3 changes: 2 additions & 1 deletion weft/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package weft_test
import (
"bytes"
"errors"
"github.com/GeoNet/kit/weft"
"net/http"
"net/http/httptest"
"testing"

"github.com/GeoNet/kit/weft"
)

func TestMakeHandler(t *testing.T) {
Expand Down
Loading

0 comments on commit 0885288

Please sign in to comment.