diff --git a/build-all.go b/build-all.go index 684f3dbcb..1bf3b7d2e 100755 --- a/build-all.go +++ b/build-all.go @@ -87,52 +87,74 @@ func generateDummyStripeEndpointSecretIfNotSet() { func main() { - cleanPtr := flag.Bool("clean", false, "If set, run a './gradlew clean' before building and testing.") - stayUpPtr := flag.Bool("stay-up", false, "If set, keep test environment up after running tests.") + clean := flag.Bool("clean", false, "If set, run a './gradlew clean' and 'go clean' before building and testing.") + stayUp := flag.Bool("stay-up", false, "If set, keep test environment up in docker after running tests.") + doJvm := flag.Bool("build-jvm-components", true, "If set, then compile and test JVM based components.") + doGo := flag.Bool("build-golang-components", true, "If set, then compile and test GO based components.") + flag.Parse() log.Printf("About to get started\n") - if *cleanPtr { + if *clean { log.Printf(" ... will clean.") } - if *stayUpPtr { - log.Printf(" ... will keep environment up after acceptance tests have run.") + if *stayUp { + log.Printf(" ... will keep environment up after acceptance tests have run (if any).") } - // - // Ensure that all preconditions for building and testing are met, if not - // fail and terminate execution. - // + log.Printf("Starting building.") + + + if !*doGo { + log.Printf(" ... Not building/testing GO code") + } else { + log.Printf(" ... Building and testing go code.") + goscript.AssertThatScriptCommandsAreAvailable("go", "~/go/bin/staticcheck") - goscript.AssertThatScriptCommandsAreAvailable("docker-compose", "./gradlew", "docker", "cmp") + goscript.AssertSuccesfulRun("go build ./...") + goscript.AssertSuccesfulRun("go test ./...") + goscript.AssertSuccesfulRun("~/go/bin/staticcheck ./...") + } + + if !*doJvm { + log.Printf(" ... Not building/testing JVM based code.") + } else { + log.Printf(" ... Building/testing JVM based code.") + // + // Ensure that all preconditions for building and testing are met, if not + // fail and terminate execution. + // - projectProfile := parseServiceAccountFile("prime-service-account.json") + goscript.AssertThatScriptCommandsAreAvailable("docker-compose", "./gradlew", "docker", "cmp") - gcpProjectId := projectProfile.ProjectId - - os.Setenv("GCP_PROJECT_ID", gcpProjectId) + projectProfile := parseServiceAccountFile("prime-service-account.json") - goscript.AssertThatEnvironmentVariableaAreSet("STRIPE_API_KEY", "GCP_PROJECT_ID") - goscript.AssertDockerIsRunning() - generateDummyStripeEndpointSecretIfNotSet() - distributeServiceAccountConfigs( - "prime-service-account.json", - "c54b903790340dd9365fa59fce3ad8e2", - "acceptance-tests/config", - "dataflow-pipelines/config", - "ocsgw/config", - "auth-server/config prime/config") - generateEspEndpointCertificates( - "certs/ocs.dev.ostelco.org/nginx.crt", - "ocsgw/cert/metrics.crt", - "ocs.dev.ostelco.org") + gcpProjectId := projectProfile.ProjectId - buildUsingGradlew(cleanPtr) + os.Setenv("GCP_PROJECT_ID", gcpProjectId) - runIntegrationTestsViaDocker(stayUpPtr) + goscript.AssertThatEnvironmentVariableaAreSet("STRIPE_API_KEY", "GCP_PROJECT_ID") + goscript.AssertDockerIsRunning() + generateDummyStripeEndpointSecretIfNotSet() + distributeServiceAccountConfigs( + "prime-service-account.json", + "c54b903790340dd9365fa59fce3ad8e2", + "acceptance-tests/config", + "dataflow-pipelines/config", + "ocsgw/config", + "auth-server/config prime/config") + generateEspEndpointCertificates( + "certs/ocs.dev.ostelco.org/nginx.crt", + "ocsgw/cert/metrics.crt", + "ocs.dev.ostelco.org") - log.Printf("Build and integration tests succeeded\n") + buildUsingGradlew(*clean) + + runIntegrationTestsViaDocker(*stayUp) + + log.Printf("Build and integration tests succeeded\n") + } } type GcpProjectProfile struct { @@ -169,13 +191,13 @@ func parseServiceAccountFile(filename string) (GcpProjectProfile) { return profile } -func runIntegrationTestsViaDocker(stayUpPtr *bool) { +func runIntegrationTestsViaDocker(stayUpPtr bool) { - // First take down any lingering docker jobs that may interfer with + // First take down any lingering docker jobs that may interfere with // the current run. goscript.AssertSuccesfulRun("docker-compose down") - if *stayUpPtr { + if stayUpPtr { // If ctrl-c is pushed during stay-up, then take the whole thing down using docker-compose down c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt) @@ -190,12 +212,12 @@ func runIntegrationTestsViaDocker(stayUpPtr *bool) { } } -func buildUsingGradlew(cleanPtr *bool) { +func buildUsingGradlew(clean bool) { // // All preconditions are now satisfied, now run the actual build/test commands // and terminate the build process if any of them fails. // - if *cleanPtr { + if clean { goscript.AssertSuccesfulRun("./gradlew build") } goscript.AssertSuccesfulRun("./gradlew build") diff --git a/github.com/ostelco-core/goscript/goscript.go b/github.com/ostelco-core/goscript/goscript.go index c0ec2fc1d..f22369089 100644 --- a/github.com/ostelco-core/goscript/goscript.go +++ b/github.com/ostelco-core/goscript/goscript.go @@ -260,7 +260,7 @@ func checkIfDockerIsRunning() bool { out, err := exec.Command("bash", "-c", cmd).Output() ostring := string(out) - if "Docker not running" == ostring && err == nil { + if ostring == "Docker not running" && err == nil { return false } diff --git a/sim-administration/sim-batch-management/README.md b/sim-administration/sim-batch-management/README.md index 0335ff988..f6a86bc16 100644 --- a/sim-administration/sim-batch-management/README.md +++ b/sim-administration/sim-batch-management/README.md @@ -111,3 +111,16 @@ that justifies adding these checks). 10. Declare prime instances (should make sense to have both prod and dev defined with different constraints on them). + +11. Read through [parser options in kingpin](https://github.com/alecthomas/kingpin/blob/master/parsers.go) and + amend the command line reader to read existing files, proper DNS etc. + as appropriate. + +12. Refactor the main program. It's way to big now. + +13. Rewrite the top-evel build-all.go to also compile go-code (which it + paradoxically doesn't do now). + +14. Make goland less confused with respect to imports than it is now. + +15. Fix all suggestions by goland. diff --git a/sim-administration/sim-batch-management/store/store.go b/sim-administration/sim-batch-management/store/store.go index 1f9981269..1c2344d34 100644 --- a/sim-administration/sim-batch-management/store/store.go +++ b/sim-administration/sim-batch-management/store/store.go @@ -257,9 +257,8 @@ func (sdb SimBatchDB) GetProfileVendorByID(id int64) (*model.ProfileVendor, erro if len(result) == 0 { return nil, nil - } else { - return &result[0], nil } + return &result[0], nil } // GetProfileVendorByName find a profile vendor in the database by looking it up by name.