Skip to content

Commit

Permalink
Support git HTTP credentials when cloning repo (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborszakacs authored Jun 19, 2023
1 parent b84f61e commit 80f841d
Show file tree
Hide file tree
Showing 21 changed files with 544 additions and 121 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ The Step scans for:
* **Flutter** projects, the Step checks for the `pubspec.yaml` files.

### Configuring the Step
To successfully run the Step, you need:
1. An SSH key

To successfully run the Step, you need:
1. An SSH key or Git HTTP credentials
1. A repository

To configure the Step:

1. **POST url to send the scan results to**: You can send your app's scan results to an URL as a POST request.
1. **URL to get app icon candidates upload URLs**: You can upload your app's icons using this input.
1. **URL to get app icon candidates upload URLs**: You can upload your app's icons using this input.
1. **Verbose log option**: You can set this input to `yes` to produce more informative logs.
1. **Activate SSH key and clone git repo inside the Step**: You can set this input to `true` to activate an SSH key and clone the git repository of your app.

Expand Down Expand Up @@ -61,6 +61,8 @@ You can also run this step directly with [Bitrise CLI](https://github.com/bitris
| `verbose_log` | You can enable the verbose log for easier debugging. | | `false` |
| `enable_repo_clone` | If set to yes then it will setup the ssh key and will clone the repo with the provided url and branch name. | | `no` |
| `ssh_rsa_private_key` | SSH key to be used for the git clone. | sensitive | `$SSH_RSA_PRIVATE_KEY` |
| `git_http_username` | Username for establishing an HTTP(S) connection to the repository | sensitive | `$GIT_HTTP_USERNAME` |
| `git_http_password` | Personal access token (or password) for establishing an HTTP(S) connection to the repository | sensitive | `$GIT_HTTP_PASSWORD` |
| `repository_url` | Url to be used for the git clone. | | `$GIT_REPOSITORY_URL` |
| `branch` | Branch to be used for the git clone. | | `$BITRISE_GIT_BRANCH` |
</details>
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ go 1.17

require (
github.com/bitrise-io/bitrise-init v0.0.0-20230615082523-d68c1dbf7b63
github.com/bitrise-io/go-steputils v1.0.2
github.com/bitrise-io/go-steputils v1.0.5
github.com/bitrise-io/go-utils v1.0.1
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.18
github.com/bitrise-steplib/steps-activate-ssh-key v0.0.0-20210518131750-a0d69ff2d203
github.com/bitrise-steplib/steps-git-clone v0.0.0-20230130163124-2237d7df95a9
github.com/bitrise-steplib/steps-git-clone v0.0.0-20230619101604-67b0d018398a
)

require (
Expand All @@ -22,6 +22,7 @@ require (
github.com/bitrise-io/go-xcode v1.0.6 // indirect
github.com/bitrise-io/goinp v0.0.0-20211005113137-305e91b481f4 // indirect
github.com/bitrise-io/stepman v0.0.0-20220107162322-d37bb82e8983 // indirect
github.com/bitrise-steplib/steps-authenticate-host-with-netrc v0.0.0-20230216105320-8cb845d52e28 // indirect
github.com/gofrs/uuid v4.3.1+incompatible // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.1 // indirect
Expand Down
13 changes: 9 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ github.com/bitrise-io/bitrise-init v0.0.0-20210518121553-1e678625c45d/go.mod h1:
github.com/bitrise-io/bitrise-init v0.0.0-20230615082523-d68c1dbf7b63 h1:/VyhHlqnd1c6+LjBS4hEq4+MllASrELQNW3R0UAdwAw=
github.com/bitrise-io/bitrise-init v0.0.0-20230615082523-d68c1dbf7b63/go.mod h1:dfGAIaFZCssxdiogcGFQnAmcwOMsyId7dT3FMR7Ik1Y=
github.com/bitrise-io/colorstring v0.0.0-20180614154802-a8cd70115192/go.mod h1:CIHVcxZUvsG99XUJV6JlR7okNsMMGY81jMvPC20W+O0=
github.com/bitrise-io/depman v0.0.0-20160708153333-4c59bc31f02a/go.mod h1:jeK3Koe+wXMSwfl8t6M7kovGgXsayUJ5ybqo3gDJgts=
github.com/bitrise-io/envman v0.0.0-20200512105748-919e33f391ee/go.mod h1:m8pTp1o3Sw9uzDxb1WRm5IBRnMau2iOvPMSnRCAhQNI=
github.com/bitrise-io/envman v0.0.0-20210517135508-b2b4fe89eac5/go.mod h1:m8pTp1o3Sw9uzDxb1WRm5IBRnMau2iOvPMSnRCAhQNI=
github.com/bitrise-io/envman v0.0.0-20211026063720-03283f9c3f32 h1:obUCcqTUMTvk9ajXaJHjxE3MGA07btE0AUQGJi3OSG4=
Expand All @@ -22,10 +23,11 @@ github.com/bitrise-io/go-plist v0.0.0-20210301100253-4b1a112ccd10/go.mod h1:pARu
github.com/bitrise-io/go-steputils v0.0.0-20210507072936-92fde382fb33/go.mod h1:YCtb1VETn/rF9tCt9oInhd/cwbt1ETPm+dTlDIfyD+A=
github.com/bitrise-io/go-steputils v0.0.0-20210514150206-5b6261447e77/go.mod h1:H0iZjgsAR5NA6pnlD/zKB6AbxEsskq55pwJ9klVmP8w=
github.com/bitrise-io/go-steputils v1.0.1/go.mod h1:YIUaQnIAyK4pCvQG0hYHVkSzKNT9uL2FWmkFNW4mfNI=
github.com/bitrise-io/go-steputils v1.0.2 h1:BEFG87r7uA/Yabk4SmuxP2yOgjjO+YGsDOYXtUH8IJ0=
github.com/bitrise-io/go-steputils v1.0.2/go.mod h1:YIUaQnIAyK4pCvQG0hYHVkSzKNT9uL2FWmkFNW4mfNI=
github.com/bitrise-io/go-steputils v1.0.5 h1:OBH7CPXeqIWFWJw6BOUMQnUb8guspwKr2RhYBhM9tfc=
github.com/bitrise-io/go-steputils v1.0.5/go.mod h1:YIUaQnIAyK4pCvQG0hYHVkSzKNT9uL2FWmkFNW4mfNI=
github.com/bitrise-io/go-steputils/v2 v2.0.0-alpha.15 h1:wG037NV+pS8cEwtalE5K58bmKLyUkU0+4m4IuXjTzmo=
github.com/bitrise-io/go-steputils/v2 v2.0.0-alpha.15/go.mod h1:M09BbxYoh6B7KJnXk/yvtuU5nZPh7RQBJGKc1dp+0hQ=
github.com/bitrise-io/go-utils v0.0.0-20170404153453-c8163959178a/go.mod h1:Pp48eQd8BSNEzWWTBxdFUd/ufS5b5Bgkmt9D5NedjWg=
github.com/bitrise-io/go-utils v0.0.0-20200224122728-e212188d99b4/go.mod h1:tTEsKvbz1LbzuN/KpVFHXnLtcAPdEgIdM41s0lL407s=
github.com/bitrise-io/go-utils v0.0.0-20201019131314-6cc2aa4d248a/go.mod h1:tTEsKvbz1LbzuN/KpVFHXnLtcAPdEgIdM41s0lL407s=
github.com/bitrise-io/go-utils v0.0.0-20210505091801-98b7dc39ee61/go.mod h1:nhdaDQFvaMny1CugVV6KjK92/q97ENo0RuKSW5I4fbA=
Expand Down Expand Up @@ -58,8 +60,10 @@ github.com/bitrise-io/xcode-project v0.0.0-20201203153351-7ad13a1dd021/go.mod h1
github.com/bitrise-io/xcode-project v0.0.0-20210302080829-f3e0bfbcd5cb/go.mod h1:t9Gj5Pe/FBDTUrkFmw2lK6PbzESB6o27eE97ukZj8Rs=
github.com/bitrise-steplib/steps-activate-ssh-key v0.0.0-20210518131750-a0d69ff2d203 h1:4dsq0dBxobriC7Q31g1EV5gaHiR5fv6nlnwtDunVPGk=
github.com/bitrise-steplib/steps-activate-ssh-key v0.0.0-20210518131750-a0d69ff2d203/go.mod h1:zrkn07He4SgP2HP9GgJQgbC6SOKW3h6W7I08mgDlGbE=
github.com/bitrise-steplib/steps-git-clone v0.0.0-20230130163124-2237d7df95a9 h1:Q1Q4NTq7vEJJFBLYpt4YWXnesJbb0arGezb9+/okz0c=
github.com/bitrise-steplib/steps-git-clone v0.0.0-20230130163124-2237d7df95a9/go.mod h1:YL7euI4AOzCl5ytxtmD9KbaA0jQEeBcbWI86onfV6aQ=
github.com/bitrise-steplib/steps-authenticate-host-with-netrc v0.0.0-20230216105320-8cb845d52e28 h1:Xwe7VK9RT9QhfQ689qD2tFBK3OxeUqgeaiErOybZXGE=
github.com/bitrise-steplib/steps-authenticate-host-with-netrc v0.0.0-20230216105320-8cb845d52e28/go.mod h1:X1+WYJT3/vJpfeU5gbQwNdAq5Me0TD0ysWpAcXs01Uw=
github.com/bitrise-steplib/steps-git-clone v0.0.0-20230619101604-67b0d018398a h1:JUkKvD3gkqWrkL7dULDpPPxMCr7cpafLHjB2iZLzdOw=
github.com/bitrise-steplib/steps-git-clone v0.0.0-20230619101604-67b0d018398a/go.mod h1:ohFvSG8CMRMiWJQggcmM1vI+CNCbfYOCBaiDXucmKHk=
github.com/bmatcuk/doublestar/v4 v4.2.0/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
Expand Down Expand Up @@ -118,6 +122,7 @@ github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoH
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.1.5-0.20170130113145-4d4bfba8f1d1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
Expand Down
32 changes: 26 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ import (
"github.com/bitrise-io/go-utils/command"
"github.com/bitrise-io/go-utils/log"
"github.com/bitrise-io/go-utils/pathutil"
"github.com/bitrise-io/go-utils/retry"
cmdv2 "github.com/bitrise-io/go-utils/v2/command"
"github.com/bitrise-io/go-utils/v2/env"
logv2 "github.com/bitrise-io/go-utils/v2/log"
"github.com/bitrise-steplib/steps-activate-ssh-key/activatesshkey"
"github.com/bitrise-steplib/steps-git-clone/gitclone"
"github.com/bitrise-steplib/steps-git-clone/gitclone/bitriseapi"
"github.com/bitrise-steplib/steps-git-clone/gitclone/tracker"
"github.com/bitrise-steplib/steps-git-clone/transport"
)

type config struct {
Expand All @@ -34,6 +38,10 @@ type config struct {
// Activate SSH Key step
SSHRsaPrivateKey stepconf.Secret `env:"ssh_rsa_private_key"`

// Git HTTP credentials
GitHTTPUsername stepconf.Secret `env:"git_http_username"`
GitHTTPPassword stepconf.Secret `env:"git_http_password"`

// Git clone step
RepositoryURL string `env:"repository_url"`
Branch string `env:"branch"`
Expand Down Expand Up @@ -63,6 +71,8 @@ type repoConfig struct {
CloneIntoDir string
RepositoryURL string
SSHRsaPrivateKey stepconf.Secret
GitHTTPUsername stepconf.Secret
GitHTTPPassword stepconf.Secret
Branch string
}

Expand Down Expand Up @@ -95,21 +105,31 @@ func cloneRepo(cfg repoConfig) error {
}
}

// Activate Git HTTP credentials
if err := transport.Setup(transport.Config{
URL: cfg.RepositoryURL,
HTTPUsername: string(cfg.GitHTTPUsername),
HTTPPassword: string(cfg.GitHTTPPassword),
}); err != nil {
return err
}

// Git clone
logger := logv2.NewLogger()
envRepo := env.NewRepository()
tracker := gitclone.NewStepTracker(envRepo, logger)

tracker := tracker.NewStepTracker(envRepo, logger)
cmdFactory := cmdv2.NewFactory(envRepo)
gitcloner := gitclone.NewGitCloner(logger, tracker, cmdFactory)
// patchSource and mergeRefChecker used for merging only
// build URL and build api token doesn't apply here
patchSource := bitriseapi.NewPatchSource("", "")
mergeRefChecker := bitriseapi.NewMergeRefChecker("", "", retry.NewHTTPClient(), logger, tracker)
gitcloner := gitclone.NewGitCloner(logger, tracker, cmdFactory, patchSource, mergeRefChecker)
config := gitclone.Config{
RepositoryURL: cfg.RepositoryURL,
CloneIntoDir: cfg.CloneIntoDir, // Using same directory later to run scan
Branch: cfg.Branch,

// BuildURL and BuildAPIToken used for merging only
BuildURL: "",
BuildAPIToken: "",

UpdateSubmodules: true,
}
if _, err := gitcloner.CheckoutState(config); err != nil {
Expand Down
22 changes: 17 additions & 5 deletions step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ description: |-
* **Flutter** projects, the Step checks for the `pubspec.yaml` files.
### Configuring the Step
To successfully run the Step, you need:
To successfully run the Step, you need:
1. An SSH key
1. A repository
To configure the Step:
1. **POST url to send the scan results to**: You can send your app's scan results to an URL as a POST request.
1. **URL to get app icon candidates upload URLs**: You can upload your app's icons using this input.
1. **URL to get app icon candidates upload URLs**: You can upload your app's icons using this input.
1. **Verbose log option**: You can set this input to `yes` to produce more informative logs.
1. **Activate SSH key and clone git repo inside the Step**: You can set this input to `true` to activate an SSH key and clone the git repository of your app.
Expand Down Expand Up @@ -84,7 +84,7 @@ inputs:
opts:
title: "Activate SSH key and clone git repo inside the Step"
description: |
If set to yes then it will setup the ssh key and will clone the repo with the provided url and branch name.
If set to yes then it will setup the SSH key (or HTTP credentials) and will clone the repo with the provided url and branch name.
value_options:
- "yes"
- "no"
Expand All @@ -95,6 +95,18 @@ inputs:
is_expand: true
is_dont_change_value: true
is_sensitive: true
- git_http_username: $GIT_HTTP_USERNAME
opts:
title: Username for establishing an HTTP(S) connection to the repository
is_dont_change_value: true
is_sensitive: true

- git_http_password: $GIT_HTTP_PASSWORD
opts:
title: Personal access token (or password) for establishing an HTTP(S) connection to the repository
is_dont_change_value: true
is_sensitive: true

- repository_url: "$GIT_REPOSITORY_URL"
opts:
title: "Git repository URL"
Expand Down
10 changes: 10 additions & 0 deletions vendor/github.com/bitrise-io/go-steputils/step/steperror.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 80f841d

Please sign in to comment.