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

chore: reusable workflow #251

Merged
merged 1 commit into from
Jul 4, 2024
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
79 changes: 29 additions & 50 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,35 @@ jobs:
- name: check output
run: |
jq . <<< '${{ steps.set.outputs.matrix }}'
build-app:
uses: GeoNet/Actions/.github/workflows/reusable-go-apps.yml@main
with:
buildSetup: |
sudo apt-get -yq update
sudo apt-get install -y xsltproc
testSetup: |
sudo apt-get -yq update
sudo apt-get install -y xsltproc
docker \
run -d \
-p 5432:5432 \
-e POSTGRES_PASSWORD=test \
-e POSTGRES_USER=fdsn_w \
-e POSTGRES_DB=fdsn \
--name postgres \
docker.io/postgis/postgis:15-3.3-alpine
echo "Waiting until Postgres is ready..."
until nc -zv -w 1 127.0.0.1 5432; do
sleep 1s
done
sleep 5s
docker logs postgres
echo "Postgres is ready"
psql postgresql://fdsn_w:[email protected]/fdsn --file=./etc/ddl/drop-create.ddl
psql postgresql://fdsn_w:[email protected]/fdsn --file=./etc/ddl/create-users.ddl
goTestExtraArgs: -p 1
build:
needs: prepare
needs: [prepare, build-app]
strategy:
matrix: ${{ fromJSON(needs.prepare.outputs.matrix) }}
uses: GeoNet/Actions/.github/workflows/reusable-docker-build.yml@main
Expand Down Expand Up @@ -66,52 +93,4 @@ jobs:
aws-region: ap-southeast-2
aws-role-arn-to-assume: arn:aws:iam::862640294325:role/github-actions-geonet-ecr-push
aws-role-duration-seconds: "3600"
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
with:
paths: ${{ inputs.paths }}
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
env:
AWS_REGION: ap-southeast-2
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: |
sudo apt-get -yq update
sudo apt-get install -y xsltproc
docker \
run -d \
-p 5432:5432 \
-e POSTGRES_PASSWORD=test \
-e POSTGRES_USER=fdsn_w \
-e POSTGRES_DB=fdsn \
--name postgres \
docker.io/postgis/postgis:15-3.3-alpine
echo "Waiting until Postgres is ready..."
until nc -zv -w 1 127.0.0.1 5432; do
sleep 1s
done
sleep 5s
docker logs postgres
echo "Postgres is ready"
psql postgresql://fdsn_w:[email protected]/fdsn --file=./etc/ddl/drop-create.ddl
psql postgresql://fdsn_w:[email protected]/fdsn --file=./etc/ddl/create-users.ddl
- name: test
run: |
./all.sh

3 changes: 2 additions & 1 deletion cmd/fdsn-holdings-consumer/data_holdings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package main

import (
"database/sql"
"github.com/GeoNet/fdsn/internal/holdings"
"testing"
"time"

"github.com/GeoNet/fdsn/internal/holdings"
)

func TestSaveHoldings(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion cmd/fdsn-holdings-consumer/log.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package main

import (
"github.com/GeoNet/kit/metrics"
"log"
"os"

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

var Prefix string
Expand Down
3 changes: 2 additions & 1 deletion cmd/fdsn-quake-consumer/log.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package main

import (
"github.com/GeoNet/kit/metrics"
"log"
"os"

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

var Prefix string
Expand Down
3 changes: 2 additions & 1 deletion cmd/fdsn-ws/data_holdings.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package main

import (
"database/sql"
"github.com/GeoNet/fdsn/internal/fdsn"
"time"

"github.com/GeoNet/fdsn/internal/fdsn"
)

type metric struct {
Expand Down
7 changes: 4 additions & 3 deletions cmd/fdsn-ws/data_holdings_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package main

import (
"github.com/GeoNet/fdsn/internal/fdsn"
"github.com/GeoNet/fdsn/internal/holdings"
"github.com/lib/pq"
"log"
"testing"
"time"

"github.com/GeoNet/fdsn/internal/fdsn"
"github.com/GeoNet/fdsn/internal/holdings"
"github.com/lib/pq"
)

// http://www.postgresql.org/docs/9.4/static/errcodes-appendix.html
Expand Down
9 changes: 1 addition & 8 deletions cmd/fdsn-ws/fdsn_dataselect.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import (
"log"
"net/http"
"os"
"reflect"
"regexp"
"strings"
"text/template"
"time"

Expand Down Expand Up @@ -41,12 +39,7 @@ type dataSelect struct {
keys []string
}

func init() {
// Handle comma separated parameters (eg: net, sta, loc, cha, etc)
decoder.RegisterConverter([]string{}, func(input string) reflect.Value {
return reflect.ValueOf(strings.Split(input, ","))
})

func initDataselectTemplate() {
var err error
var b bytes.Buffer

Expand Down
2 changes: 1 addition & 1 deletion cmd/fdsn-ws/fdsn_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ var validEventTypes = strings.Split(
", ", ","),
",") // remove spaces after comma

func init() {
func initEventTemplate() {
var err error
var b bytes.Buffer

Expand Down
41 changes: 21 additions & 20 deletions cmd/fdsn-ws/fdsn_station.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ var (
fdsnStationWadlFile []byte
fdsnStationIndex []byte
fdsnStations fdsnStationObj
emptyDateTime time.Time
emptyDateTime = time.Date(9999, 1, 1, 0, 0, 0, 0, time.UTC)
errNotModified = fmt.Errorf("Not modified.")
s3Bucket string
s3Meta string
)

func init() {
func initStationTemplate() {
var err error
var b bytes.Buffer

Expand All @@ -130,9 +130,10 @@ func init() {
if err != nil {
log.Printf("error reading assets/fdsn-ws-station.html: %s", err.Error())
}
}

emptyDateTime = time.Date(9999, 1, 1, 0, 0, 0, 0, time.UTC)

func initStationXML() {
var err error
s3Bucket = os.Getenv("STATION_XML_BUCKET")
s3Meta = os.Getenv("STATION_XML_META_KEY")

Expand Down Expand Up @@ -193,7 +194,7 @@ func parseStationV1Post(body string) ([]fdsnStationV1Search, error) {
case "format":
format = strings.TrimSpace(tokens[1])
if format != "xml" && format != "text" {
return ret, errors.New("Invalid format")
return ret, errors.New("invalid format")
}
}
} else if tokens := strings.Fields(line); len(tokens) == 6 {
Expand All @@ -220,12 +221,12 @@ func parseStationV1Post(body string) ([]fdsnStationV1Search, error) {
}
ret = append(ret, p)
} else {
return ret, fmt.Errorf("Invalid query format (POST).")
return ret, fmt.Errorf("invalid query format (POST)")
}
}

if level == "response" && format == "text" {
return []fdsnStationV1Search{}, fmt.Errorf("Text formats are only supported when level is net|sta|cha.")
return []fdsnStationV1Search{}, fmt.Errorf("text formats are only supported when level is net|sta|cha")
}

return ret, nil
Expand Down Expand Up @@ -269,7 +270,7 @@ func parseStationV1(v url.Values) (fdsnStationV1Search, error) {

for key, val := range v {
if len(val[0]) == 0 {
return fdsnStationV1Search{}, fmt.Errorf("Invalid %s value", key)
return fdsnStationV1Search{}, fmt.Errorf("invalid %s value", key)
}
}

Expand All @@ -280,11 +281,11 @@ func parseStationV1(v url.Values) (fdsnStationV1Search, error) {

// Only xml and text is allowed.
if p.Format != "xml" && p.Format != "text" {
return fdsnStationV1Search{}, fmt.Errorf("Invalid format.")
return fdsnStationV1Search{}, fmt.Errorf("invalid format")
}

if p.Level == "response" && p.Format == "text" {
return fdsnStationV1Search{}, fmt.Errorf("Text formats are only supported when level is net|sta|cha.")
return fdsnStationV1Search{}, fmt.Errorf("text formats are only supported when level is net|sta|cha")
}

count := 0
Expand All @@ -303,7 +304,7 @@ func parseStationV1(v url.Values) (fdsnStationV1Search, error) {
p.StartTime = p.StartBefore
}
if count > 1 {
return fdsnStationV1Search{}, fmt.Errorf("Only one of 'starttime', 'startafter', and 'startbefore' is allowed.")
return fdsnStationV1Search{}, fmt.Errorf("only one of 'starttime', 'startafter', and 'startbefore' is allowed")
}

count = 0
Expand All @@ -325,23 +326,23 @@ func parseStationV1(v url.Values) (fdsnStationV1Search, error) {
}

if count > 1 {
return fdsnStationV1Search{}, fmt.Errorf("Only one of 'endtime', 'endafter', and 'endbefore' is allowed.")
return fdsnStationV1Search{}, fmt.Errorf("only one of 'endtime', 'endafter', and 'endbefore' is allowed")
}

if p.IncludeAvailability {
return fdsnStationV1Search{}, errors.New("include availability is not supported.")
return fdsnStationV1Search{}, errors.New("include availability is not supported")
}

if !p.IncludeRestricted {
return fdsnStationV1Search{}, errors.New("exclude restricted is not supported.")
return fdsnStationV1Search{}, errors.New("exclude restricted is not supported")
}

if p.MatchTimeSeries {
return fdsnStationV1Search{}, errors.New("match time series is not supported.")
return fdsnStationV1Search{}, errors.New("match time series is not supported")
}

if p.NoData != 204 && p.NoData != 404 {
return fdsnStationV1Search{}, errors.New("nodata must be 204 or 404.")
return fdsnStationV1Search{}, errors.New("nodata must be 204 or 404")
}

ne, err := fdsn.GenRegex(p.Network, false, false)
Expand Down Expand Up @@ -397,7 +398,7 @@ func parseStationV1(v url.Values) (fdsnStationV1Search, error) {
// Now validate longitude, latitude, and radius
if p.Longitude != math.MaxFloat64 || p.Latitude != math.MaxFloat64 {
if p.Longitude == math.MaxFloat64 || p.Latitude == math.MaxFloat64 {
err = fmt.Errorf("parameter latitude and longitude must both present.")
err = fmt.Errorf("parameter latitude and longitude must both present")
return s, err
}

Expand All @@ -412,17 +413,17 @@ func parseStationV1(v url.Values) (fdsnStationV1Search, error) {
}

if p.MaxRadius < 0 || p.MaxRadius > 180.0 {
err = fmt.Errorf("invalid maxradius value.")
err = fmt.Errorf("invalid maxradius value")
return s, err
}

if p.MinRadius < 0 || p.MinRadius > 180.0 {
err = fmt.Errorf("invalid minradius value.")
err = fmt.Errorf("invalid minradius value")
return s, err
}

if p.MinRadius > p.MaxRadius {
err = fmt.Errorf("minradius or maxradius range error.")
err = fmt.Errorf("minradius or maxradius range error")
return s, err
}
}
Expand Down
Loading
Loading