From e9f98670fe5b89dd5ca560d4db4869d6c7cc9c7b Mon Sep 17 00:00:00 2001 From: Falk Scheerschmidt Date: Mon, 24 Apr 2023 13:48:29 +0200 Subject: [PATCH] feat: Add build_type to github_repository (pages) --- github/resource_github_repository.go | 13 +++++- github/resource_github_repository_test.go | 48 ++++++++++++++++++++++- website/docs/r/repository.html.markdown | 4 +- 3 files changed, 62 insertions(+), 3 deletions(-) diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index ada5dfbff9..9c17d482a0 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -247,7 +247,7 @@ func resourceGithubRepository() *schema.Resource { "source": { Type: schema.TypeList, MaxItems: 1, - Required: true, + Optional: true, Description: "The source branch and directory for the rendered Pages site.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -265,6 +265,13 @@ func resourceGithubRepository() *schema.Resource { }, }, }, + "build_type": { + Type: schema.TypeString, + Optional: true, + Default: "legacy", + Description: "The type the page should be sourced.", + ValidateFunc: validateValueFunc([]string{"legacy", "workflow"}), + }, "cname": { Type: schema.TypeString, Optional: true, @@ -860,6 +867,9 @@ func expandPagesUpdate(input []interface{}) *github.PagesUpdate { } update.Source = &github.PagesSource{Branch: &sourceBranch, Path: &sourcePath} + pagesBuildType := pages["build_type"].(string) + update.BuildType = &pagesBuildType + return update } @@ -874,6 +884,7 @@ func flattenPages(pages *github.Pages) []interface{} { pagesMap := make(map[string]interface{}) pagesMap["source"] = []interface{}{sourceMap} + pagesMap["build_type"] = pages.GetBuildType() pagesMap["url"] = pages.GetURL() pagesMap["status"] = pages.GetStatus() pagesMap["cname"] = pages.GetCNAME() diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index 106e1c776e..0e72d06b9a 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -765,7 +765,7 @@ func TestAccGithubRepositoryPages(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - t.Run("manages the pages feature for a repository", func(t *testing.T) { + t.Run("manages the legacy pages feature for a repository", func(t *testing.T) { config := fmt.Sprintf(` resource "github_repository" "test" { @@ -813,6 +813,52 @@ func TestAccGithubRepositoryPages(t *testing.T) { }) + t.Run("manages the pages from workflow feature for a repository", func(t *testing.T) { + + config := fmt.Sprintf(` + resource "github_repository" "test" { + name = "tf-acc-%s" + auto_init = true + pages { + build_type = "workflow" + } + } + `, randomID) + + check := resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "github_repository.test", "pages.0.source.0.branch", + "main", + ), + ) + + testCase := func(t *testing.T, mode string) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { skipUnlessMode(t, mode) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: config, + Check: check, + }, + }, + }) + } + + t.Run("with an anonymous account", func(t *testing.T) { + t.Skip("anonymous account not supported for this operation") + }) + + t.Run("with an individual account", func(t *testing.T) { + testCase(t, individual) + }) + + t.Run("with an organization account", func(t *testing.T) { + testCase(t, organization) + }) + + }) + } func TestAccGithubRepositorySecurity(t *testing.T) { diff --git a/website/docs/r/repository.html.markdown b/website/docs/r/repository.html.markdown index 18641f90ae..75dae6503a 100644 --- a/website/docs/r/repository.html.markdown +++ b/website/docs/r/repository.html.markdown @@ -124,7 +124,9 @@ initial repository creation and create the target branch inside of the repositor The `pages` block supports the following: -* `source` - (Required) The source branch and directory for the rendered Pages site. See [GitHub Pages Source](#github-pages-source) below for details. +* `source` - (Optional) The source branch and directory for the rendered Pages site. See [GitHub Pages Source](#github-pages-source) below for details. + +* `build_type` - (Optional) The type of GitHub Pages site to build. Can be `legacy` or `workflow`. * `cname` - (Optional) The custom domain for the repository. This can only be set after the repository has been created.