diff --git a/.ci/magician/cmd/generate_downstream.go b/.ci/magician/cmd/generate_downstream.go index a58269e396f0..3159e5745d6e 100644 --- a/.ci/magician/cmd/generate_downstream.go +++ b/.ci/magician/cmd/generate_downstream.go @@ -335,6 +335,14 @@ func createCommit(scratchRepo *source.Repo, commitMessage string, rnr exec.ExecR commitSha = strings.TrimSpace(commitSha) fmt.Printf("Commit sha on the branch is: `%s`\n", commitSha) + variablePath := fmt.Sprintf("/workspace/commitSHA_modular-magician_%s.txt", scratchRepo.Name) + fmt.Println("variablePath: ", variablePath) + + err = rnr.WriteFile(variablePath, commitSha) + if err != nil { + fmt.Println("Error:", err) + } + return commitSha, err } diff --git a/.ci/magician/cmd/test_tgc.go b/.ci/magician/cmd/test_tgc.go index bbf746a975a2..be65ad1b20c3 100644 --- a/.ci/magician/cmd/test_tgc.go +++ b/.ci/magician/cmd/test_tgc.go @@ -47,11 +47,39 @@ var testTGCCmd = &cobra.Command{ } func execTestTGC(commit, pr string, gh ttGithub) error { + contentTPGB, err := os.ReadFile("/workspace/commitSHA_modular-magician_terraform-provider-google-beta.txt") + if err != nil { + fmt.Println("Error:", err) + } + + contentTGC, err := os.ReadFile("/workspace/commitSHA_modular-magician_terraform-google-conversion.txt") + if err != nil { + fmt.Println("Error:", err) + } + + commitShaOrBranchUpstreamTPGB := string(contentTPGB) + commitShaOrBranchUpstreamTGC := string(contentTGC) + + if commitShaOrBranchUpstreamTPGB == "" { + // fall back to branch if commit SHA can't be found + commitShaOrBranchUpstreamTPGB = "auto-pr-" + pr + } + + if commitShaOrBranchUpstreamTGC == "" { + // fall back to branch if commit SHA can't be found + commitShaOrBranchUpstreamTGC = "auto-pr-" + pr + } + + fmt.Println("commitShaOrBranchUpstreamTPGB: ", commitShaOrBranchUpstreamTPGB) + fmt.Println("commitShaOrBranchUpstreamTGC: ", commitShaOrBranchUpstreamTGC) + if err := gh.CreateWorkflowDispatchEvent("test-tgc.yml", map[string]any{ - "owner": "modular-magician", - "repo": "terraform-google-conversion", - "branch": "auto-pr-" + pr, - "sha": commit, + "owner": "modular-magician", + "repo": "terraform-google-conversion", + "tpgb-branch": commitShaOrBranchUpstreamTPGB, + "tgc-branch": commitShaOrBranchUpstreamTGC, + "pr-number": pr, + "sha": commit, }); err != nil { return fmt.Errorf("error creating workflow dispatch event: %w", err) } diff --git a/.ci/magician/cmd/test_tgc_test.go b/.ci/magician/cmd/test_tgc_test.go index daf4b94409fe..5e67dcca8e59 100644 --- a/.ci/magician/cmd/test_tgc_test.go +++ b/.ci/magician/cmd/test_tgc_test.go @@ -28,7 +28,7 @@ func TestExecTestTGC(t *testing.T) { execTestTGC("sha1", "pr1", gh) method := "CreateWorkflowDispatchEvent" - expected := [][]any{{"test-tgc.yml", map[string]any{"branch": "auto-pr-pr1", "owner": "modular-magician", "repo": "terraform-google-conversion", "sha": "sha1"}}} + expected := [][]any{{"test-tgc.yml", map[string]any{"tpgb-branch": "auto-pr-pr1", "tgc-branch": "auto-pr-pr1", "pr-number":"pr1", "owner": "modular-magician", "repo": "terraform-google-conversion", "sha": "sha1"}}} if calls, ok := gh.calledMethods[method]; !ok { t.Fatal("Workflow dispatch event not created") } else if !reflect.DeepEqual(calls, expected) { diff --git a/.ci/magician/cmd/test_tpg.go b/.ci/magician/cmd/test_tpg.go index 181644dbfcf9..12c0b12c441c 100644 --- a/.ci/magician/cmd/test_tpg.go +++ b/.ci/magician/cmd/test_tpg.go @@ -19,7 +19,6 @@ import ( "fmt" "magician/github" "os" - "github.com/spf13/cobra" ) @@ -54,19 +53,39 @@ var testTPGCmd = &cobra.Command{ func execTestTPG(version, commit, pr string, gh ttGithub) error { var repo string + var content []byte + var err error if version == "ga" { repo = "terraform-provider-google" + content, err = os.ReadFile("/workspace/commitSHA_modular-magician_terraform-provider-google.txt") + if err != nil { + fmt.Println("Error:", err) + } } else if version == "beta" { repo = "terraform-provider-google-beta" + content, err = os.ReadFile("/workspace/commitSHA_modular-magician_terraform-provider-google-beta.txt") + if err != nil { + fmt.Println("Error:", err) + } } else { return fmt.Errorf("invalid version specified") } + commitShaOrBranchUpstream := string(content) + + if commitShaOrBranchUpstream == ""{ + // fall back to branch if commit SHA can't be found + commitShaOrBranchUpstream = "auto-pr-" + pr + } + + fmt.Println("commitShaOrBranchUpstream: ", commitShaOrBranchUpstream) + if err := gh.CreateWorkflowDispatchEvent("test-tpg.yml", map[string]any{ - "owner": "modular-magician", - "repo": repo, - "branch": "auto-pr-" + pr, - "sha": commit, + "owner": "modular-magician", + "repo": repo, + "branch": commitShaOrBranchUpstream, + "pr-number": pr, + "sha": commit, }); err != nil { return fmt.Errorf("error creating workflow dispatch event: %w", err) } diff --git a/.ci/magician/cmd/test_tpg_test.go b/.ci/magician/cmd/test_tpg_test.go index d1ca8882471d..a79d22dc618a 100644 --- a/.ci/magician/cmd/test_tpg_test.go +++ b/.ci/magician/cmd/test_tpg_test.go @@ -28,7 +28,7 @@ func TestExecTestTPG(t *testing.T) { execTestTPG("beta", "sha1", "pr1", gh) method := "CreateWorkflowDispatchEvent" - expected := [][]any{{"test-tpg.yml", map[string]any{"branch": "auto-pr-pr1", "owner": "modular-magician", "repo": "terraform-provider-google-beta", "sha": "sha1"}}} + expected := [][]any{{"test-tpg.yml", map[string]any{"branch": "auto-pr-pr1", "pr-number": "pr1", "owner": "modular-magician", "repo": "terraform-provider-google-beta", "sha": "sha1"}}} if calls, ok := gh.calledMethods[method]; !ok { t.Fatal("Workflow dispatch event not created") } else if !reflect.DeepEqual(calls, expected) { @@ -40,7 +40,7 @@ func TestExecTestTPG(t *testing.T) { execTestTPG("ga", "sha1", "pr1", gh) method = "CreateWorkflowDispatchEvent" - expected = [][]any{{"test-tpg.yml", map[string]any{"branch": "auto-pr-pr1", "owner": "modular-magician", "repo": "terraform-provider-google", "sha": "sha1"}}} + expected = [][]any{{"test-tpg.yml", map[string]any{"branch": "auto-pr-pr1", "pr-number": "pr1", "owner": "modular-magician", "repo": "terraform-provider-google", "sha": "sha1"}}} if calls, ok := gh.calledMethods[method]; !ok { t.Fatal("Workflow dispatch event not created") } else if !reflect.DeepEqual(calls, expected) { diff --git a/.github/workflows/test-tgc.yml b/.github/workflows/test-tgc.yml index ab69a8459bc4..91274728e35a 100644 --- a/.github/workflows/test-tgc.yml +++ b/.github/workflows/test-tgc.yml @@ -16,15 +16,21 @@ on: description: 'The Base Repository to pull from' required: false default: 'terraform-google-conversion' - branch: + tpgb-branch: + description: 'The branch or sha of the tpgb execute against' + required: true + tgc-branch: description: 'The branch or sha of the tgc execute against' required: true + pr-number: + description: 'The pull request number in magic-modules repository' + required: true sha: description: "The commit SHA in magic-modules repository where the status result will be posted" required: true concurrency: - group: test-tgc-${{ github.event.inputs.owner }}-${{ github.event.inputs.repo }}-${{ github.event.inputs.branch }} + group: test-tgc-${{ github.event.inputs.owner }}-${{ github.event.inputs.repo }}-${{ github.event.inputs.pr-number }} cancel-in-progress: true jobs: @@ -56,7 +62,7 @@ jobs: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.2 with: repository: ${{ github.event.inputs.owner }}/${{ github.event.inputs.repo }} - ref: ${{ github.event.inputs.branch }} + ref: ${{ github.event.inputs.tgc-branch }} fetch-depth: 2 - name: Check for Code Changes id: pull_request @@ -75,7 +81,7 @@ jobs: - name: Build Terraform Google Conversion if: ${{ !failure() && steps.pull_request.outputs.has_changes == 'true' }} run: | - go mod edit -replace github.com/hashicorp/terraform-provider-google-beta=github.com/${{ github.event.inputs.owner }}/terraform-provider-google-beta@${{ github.event.inputs.branch }} + go mod edit -replace github.com/hashicorp/terraform-provider-google-beta=github.com/${{ github.event.inputs.owner }}/terraform-provider-google-beta@${{ github.event.inputs.tpgb-branch }} go mod tidy make build - name: Run Unit Tests diff --git a/.github/workflows/test-tpg.yml b/.github/workflows/test-tpg.yml index e5b534729e7d..9d7fd572b3bc 100644 --- a/.github/workflows/test-tpg.yml +++ b/.github/workflows/test-tpg.yml @@ -19,12 +19,15 @@ on: branch: description: 'The branch or sha of the provider execute against' required: true + pr-number: + description: 'The pull request number in magic-modules repository' + required: true sha: description: "The commit SHA in magic-modules repository where the status result will be posted" required: true concurrency: - group: test-tpg-${{ github.event.inputs.owner }}-${{ github.event.inputs.repo }}-${{ github.event.inputs.branch }} + group: test-tpg-${{ github.event.inputs.owner }}-${{ github.event.inputs.repo }}-${{ github.event.inputs.pr-number }} cancel-in-progress: true jobs: