From 9394d7bb4465e101fc6088994485381e0dc30f04 Mon Sep 17 00:00:00 2001 From: Yi Hu Date: Wed, 28 Aug 2024 21:10:45 -0400 Subject: [PATCH 1/2] split java-pr --- .github/workflows/java-pr.yml | 1 + cicd/internal/flags/common-flags.go | 32 +++++++++++++++++++++--- cicd/internal/flags/common-flags_test.go | 21 ++++++++++++++++ 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/.github/workflows/java-pr.yml b/.github/workflows/java-pr.yml index 189a902c7a..6a0ebe94c7 100644 --- a/.github/workflows/java-pr.yml +++ b/.github/workflows/java-pr.yml @@ -165,6 +165,7 @@ jobs: - name: Run Integration Tests run: | ./cicd/run-it-tests \ + --modules-to-build="DEFAULT" \ --it-region="us-central1" \ --it-project="cloud-teleport-testing" \ --it-artifact-bucket="cloud-teleport-testing-it-gitactions" \ diff --git a/cicd/internal/flags/common-flags.go b/cicd/internal/flags/common-flags.go index 56a6f2568e..fab3276ba1 100644 --- a/cicd/internal/flags/common-flags.go +++ b/cicd/internal/flags/common-flags.go @@ -22,14 +22,25 @@ import ( ) const ( - ALL = "ALL" + ALL = "ALL" // All modules + DEFAULT = "DEFAULT" // Modules other than those excluded SPANNER = "SPANNER" ) // Avoid making these vars public. var ( modulesToBuild string - moduleMap = map[string]string{ALL: "", SPANNER: "v2/datastream-to-spanner/,v2/spanner-change-streams-to-sharded-file-sink/,v2/gcs-to-sourcedb/,v2/sourcedb-to-spanner/,v2/spanner-to-sourcedb/,v2/spanner-custom-shard,plugins/templates-maven-plugin"} + moduleMap = map[string][]string{ + ALL: {}, + DEFAULT: {}, + SPANNER: {"v2/datastream-to-spanner/", + "v2/spanner-change-streams-to-sharded-file-sink/", + "v2/gcs-to-sourcedb/", + "v2/sourcedb-to-spanner/", + "v2/spanner-to-sourcedb/", + "v2/spanner-custom-shard", + "plugins/templates-maven-plugin"}, + } ) // Registers all common flags. Must be called before flag.Parse(). @@ -40,8 +51,21 @@ func RegisterCommonFlags() { // Returns all modules to build. func ModulesToBuild() []string { m := modulesToBuild - if val, ok := moduleMap[modulesToBuild]; ok { - m = val + if m == "DEFAULT" { + // "DEFAULT" is "ALL" minus other modules defined in moduleMap + var s []string + for k, v := range moduleMap { + if k != "ALL" && k != "DEFAULT" { + for _, n := range v { + if !strings.HasPrefix(n, "plugins/") { + s = append(s, "!"+n) + } + } + } + } + return s + } else if val, ok := moduleMap[modulesToBuild]; ok { + return val } if len(m) == 0 { return make([]string, 0) diff --git a/cicd/internal/flags/common-flags_test.go b/cicd/internal/flags/common-flags_test.go index 444b258a98..91df69626f 100644 --- a/cicd/internal/flags/common-flags_test.go +++ b/cicd/internal/flags/common-flags_test.go @@ -18,6 +18,7 @@ package flags import ( "reflect" + "strings" "testing" ) @@ -52,3 +53,23 @@ func TestModulesToBuild(t *testing.T) { } } } + +func TestDefaultExcludedSubModules(t *testing.T) { + // common modules won't excluded + modulesToBuild = "DEFAULT" + defaults := ModulesToBuild() + mods := []string{"SPANNER"} + var s []string + for _, m := range mods { + modulesToBuild = m + ms := ModulesToBuild() + for _, n := range ms { + if !strings.HasPrefix(n, "plugins/") { + s = append(s, "!"+n) + } + } + } + if !reflect.DeepEqual(defaults, s) { + t.Errorf("Returned modules are not equal. Expected %v. Got %v.", s, defaults) + } +} From 11daeb1a56e519d4a8a65ee33369d3a080dea376 Mon Sep 17 00:00:00 2001 From: Yi Hu Date: Tue, 3 Sep 2024 13:24:18 -0400 Subject: [PATCH 2/2] add common paths to spanner-pr trigger path --- .github/workflows/spanner-pr.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/spanner-pr.yml b/.github/workflows/spanner-pr.yml index 8bc34916a9..d9df005f2a 100644 --- a/.github/workflows/spanner-pr.yml +++ b/.github/workflows/spanner-pr.yml @@ -21,14 +21,20 @@ on: branches: - 'main' paths: - # Include spanner paths only + # Template wide common modules + - 'v2/common/**' + - 'v2/datastream-common/**' + - 'it/google-cloud-platform/**' + - 'it/conditions/**' + # Component common modules + - 'v2/spanner-common/**' + - 'v2/spanner-migrations-sdk/**' + - 'v2/spanner-custom-shard/**' + # Include spanner paths - '.github/workflows/spanner-pr.yml' - 'v2/datastream-to-spanner/**' - - 'v2/spanner-common/**' - 'v2/spanner-change-streams-to-sharded-file-sink/**' - 'v2/gcs-to-sourcedb/**' - - 'v2/spanner-migrations-sdk/**' - - 'v2/spanner-custom-shard/**' - 'v2/sourcedb-to-spanner/**' - 'v2/spanner-to-sourcedb/**' schedule: