Skip to content

Commit

Permalink
feat: Add build_type to github_repository (pages)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x46616c6b committed Apr 24, 2023
1 parent e9bb788 commit e9f9867
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
13 changes: 12 additions & 1 deletion github/resource_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
Expand Down Expand Up @@ -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
}

Expand All @@ -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()
Expand Down
48 changes: 47 additions & 1 deletion github/resource_github_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/repository.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit e9f9867

Please sign in to comment.