Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tmc): add support for bitbucket pipelines. #2010

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions bitbucket-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2024 Terramate GmbH
# SPDX-License-Identifier: MPL-2.0

image: golang

clone:
enabled: true
depth: full

pipelines:
pull-requests:
'**':
- step:
name: 'build Terramate'
script:
- make build
- go install github.com/hashicorp/hc-install/cmd/hc-install@latest
- hc-install install -version 1.6.0 terraform
- cp ./terraform /usr/local/bin/terraform
- ./bin/terramate run --changed -- terraform init
- export TMC_API_DEBUG=1
- ./bin/terramate run --changed --sync-preview --terraform-plan-file=out.tfplan --target linux-go-packages --parallel 12 -- terraform plan -detailed-exitcode -out=out.tfplan
branches:
main:
- step:
name: 'build Terramate'
script:
- make build
- go install github.com/hashicorp/hc-install/cmd/hc-install@latest
- hc-install install -version 1.6.0 terraform
- cp ./terraform /usr/local/bin/terraform
- ./bin/terramate run --changed -- terraform init
- export TMC_API_DEBUG=1
- ./bin/terramate run --changed --sync-deployment --terraform-plan-file=out.tfplan --target linux-go-packages --parallel 12 -- terraform plan -out=out.tfplan
- ./bin/terramate run --changed --sync-drift-status --target linux-go-packages --terraform-plan-file=out.tfplan -- terraform plan -detailed-exitcode -out=out.tfplan
45 changes: 45 additions & 0 deletions ci/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,51 @@ func DetectPlatformFromEnv() PlatformType {
return typ
}

func (plat PlatformType) String() string {
switch plat {
case PlatformLocal:
return "local"
case PlatformGithub:
return "github"
case PlatformGitlab:
return "gitlab"
case PlatformGenericCI:
return "generic"
case PlatformAppVeyor:
return "appveyor"
case PlatformAzureDevops:
return "azuredevops"
case PlatformBamboo:
return "bamboo"
case PlatformBitBucket:
return "bitbucket"
case PlatformBuddyWorks:
return "buddyworks"
case PlatformBuildKite:
return "buildkite"
case PlatformCircleCI:
return "circleci"
case PlatformCirrus:
return "cirrus"
case PlatformCodeBuild:
return "codebuild"
case PlatformHeroku:
return "heroku"
case PlatformHudson:
return "hudson"
case PlatformJenkins:
return "jenkins"
case PlatformMyGet:
return "myget"
case PlatformTeamCity:
return "teamcity"
case PlatformTravis:
return "travis"
default:
return "unknown"
}
}

func isEnvVarSet(key string) bool {
val := os.Getenv(key)
return val != "" && val != "0" && val != "false"
Expand Down
26 changes: 25 additions & 1 deletion cloud/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ type (
GitMetadata
GithubMetadata
GitlabMetadata
BitbucketMetadata
}

// GitMetadata are the git related metadata.
Expand Down Expand Up @@ -277,6 +278,29 @@ type (
GitlabCICDMergeRequestApproved *bool `json:"gitlab_cicd_merge_request_approved,omitempty"` // CI_MERGE_REQUEST_APPROVED
}

// BitbucketMetadata holds the Bitbucket specific metadata.
BitbucketMetadata struct {
BitbucketPipelinesBuildNumber string `json:"bitbucket_pipelines_build_number,omitempty"`
BitbucketPipelinesPipelineUUID string `json:"bitbucket_pipelines_pipeline_uuid,omitempty"`
BitbucketPipelinesCommit string `json:"bitbucket_pipelines_commit,omitempty"`
BitbucketPipelinesWorkspace string `json:"bitbucket_pipelines_workspace,omitempty"`
BitbucketPipelinesRepoSlug string `json:"bitbucket_pipelines_repo_slug,omitempty"`
BitbucketPipelinesRepoUUID string `json:"bitbucket_pipelines_repo_uuid,omitempty"`
BitbucketPipelinesRepoFullName string `json:"bitbucket_pipelines_repo_full_name,omitempty"`
BitbucketPipelinesBranch string `json:"bitbucket_pipelines_branch,omitempty"`
BitbucketPipelinesDestinationBranch string `json:"bitbucket_pipelines_destination_branch,omitempty"`
BitbucketPipelinesTag string `json:"bitbucket_pipelines_tag,omitempty"` // only available in tag events.
BitbucketPipelinesStepTriggererUUID string `json:"bitbucket_pipelines_step_triggerer_uuid,omitempty"`
BitbucketPipelinesParallelStep string `json:"bitbucket_pipelines_parallel_step,omitempty"`
BitbucketPipelinesParallelStepCount string `json:"bitbucket_pipelines_parallel_step_count,omitempty"`
BitbucketPipelinesPRID string `json:"bitbucket_pipelines_pr_id,omitempty"` // only available in PR events.
BitbucketPipelinesStepUUID string `json:"bitbucket_pipelines_step_uuid,omitempty"`
sixstone-qq marked this conversation as resolved.
Show resolved Hide resolved
BitbucketPipelinesDeploymentEnvironment string `json:"bitbucket_pipelines_deployment_environment,omitempty"`
BitbucketPipelinesDeploymentEnvironmentUUID string `json:"bitbucket_pipelines_deployment_environment_uuid,omitempty"`
BitbucketPipelinesProjectKey string `json:"bitbucket_pipelines_project_key,omitempty"`
BitbucketPipelinesProjectUUID string `json:"bitbucket_pipelines_project_uuid,omitempty"`
}

// ReviewRequest is the review_request object.
ReviewRequest struct {
Platform string `json:"platform"`
Expand All @@ -299,7 +323,7 @@ type (
ChecksSuccessCount int `json:"checks_success_count"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
PushedAt *time.Time `json:"pushed_at,omitempty"`
PushedAt *int64 `json:"pushed_at,omitempty"`
Branch string `json:"branch"`
BaseBranch string `json:"base_branch"`
}
Expand Down
23 changes: 23 additions & 0 deletions cmd/terramate/cli/bitbucket/_test_mock.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT

resource "local_file" "bitbucket" {
content = <<-EOT
package bitbucket // import "github.com/terramate-io/terramate/cmd/terramate/cli/bitbucket"

Package bitbucket implements the client for Bitbucket Cloud.

type Actor struct{ ... }
type Branch struct{ ... }
type Client struct{ ... }
type Commit struct{ ... }
type PR struct{ ... }
type PRs []PR
type PullRequestResponse struct{ ... }
type Rendered struct{ ... }
type RenderedContent struct{ ... }
type Summary RenderedContent
type TargetBranch struct{ ... }
EOT

filename = "${path.module}/mock-bitbucket.ignore"
}
Loading
Loading