diff --git a/cache.go b/cache.go index 76c5b89..2661fb1 100644 --- a/cache.go +++ b/cache.go @@ -6,12 +6,12 @@ import ( "strings" "github.com/bitrise-io/bitrise-init/scanners/android" - androidCache "github.com/bitrise-io/go-android/cache" + androidCache "github.com/bitrise-io/go-android/v2/cache" "github.com/bitrise-io/go-steputils/cache" - "github.com/bitrise-io/go-utils/command" - "github.com/bitrise-io/go-utils/env" "github.com/bitrise-io/go-utils/log" "github.com/bitrise-io/go-utils/pathutil" + "github.com/bitrise-io/go-utils/v2/command" + "github.com/bitrise-io/go-utils/v2/env" ) type depsFunc func(dir string) ([]string, []string, error) @@ -80,8 +80,8 @@ func androidDeps(dir string) ([]string, []string, error) { var include []string var exclude []string - for _, dir := range scanner.ProjectRoots { - i, e, err := androidCache.NewAndroidGradleCacheItemCollector(command.NewFactory(env.NewRepository())).Collect(dir, cache.LevelDeps) + for _, project := range scanner.Projects { + i, e, err := androidCache.NewAndroidGradleCacheItemCollector(command.NewFactory(env.NewRepository())).Collect(project.RelPath, cache.LevelDeps) if err != nil { return nil, nil, err } diff --git a/go.mod b/go.mod index 6f3d354..3dd8726 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,26 @@ module github.com/bitrise-io/steps-fastlane -go 1.12 +go 1.18 require ( - github.com/bitrise-io/bitrise-init v0.0.0-20210520122036-d213de321eb8 - github.com/bitrise-io/go-android v0.0.0-20210913151943-e1ea0b4df36d - github.com/bitrise-io/go-steputils v0.0.0-20210924114124-851d30b88892 - github.com/bitrise-io/go-utils v0.0.0-20210924090918-3e7a04d0da9d - github.com/bitrise-io/go-xcode v0.0.0-20210521101355-fb6a1eb6e05b + github.com/bitrise-io/bitrise-init v0.0.0-20220504131857-f00a24c7c8ba + github.com/bitrise-io/go-android/v2 v2.0.0-alpha.3 + github.com/bitrise-io/go-steputils v1.0.2 + github.com/bitrise-io/go-steputils/v2 v2.0.0-alpha.8 + github.com/bitrise-io/go-utils v1.0.2 + github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.8 + github.com/bitrise-io/go-xcode v1.0.9 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 ) + +require ( + github.com/beevik/etree v1.1.0 // indirect + github.com/bitrise-io/bitrise v0.0.0-20220719135434-7f794d69d858 // indirect + github.com/bitrise-io/envman v0.0.0-20220512153504-166d59151b78 // indirect + github.com/bitrise-io/stepman v0.0.0-20220718172049-e5ae0a09c2f2 // indirect + github.com/hashicorp/go-cleanhttp v0.5.2 // indirect + github.com/hashicorp/go-retryablehttp v0.7.1 // indirect + github.com/hashicorp/go-version v1.6.0 // indirect + github.com/ryanuber/go-glob v1.0.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect +) diff --git a/go.sum b/go.sum index 3cad58d..e37be31 100644 --- a/go.sum +++ b/go.sum @@ -1,71 +1,86 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/beevik/etree v1.1.0 h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs= github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A= -github.com/bitrise-io/bitrise v0.0.0-20210519130014-380842fb41c1 h1:PERqeGZZkMrGYSSN/Stk+YkhErgdk37aVqc5UgnIEoo= github.com/bitrise-io/bitrise v0.0.0-20210519130014-380842fb41c1/go.mod h1:Jqf2PLwOKL1bYdbQIhVkNd55YyYKJBXyY0EtlRg5uw4= -github.com/bitrise-io/bitrise-init v0.0.0-20210520122036-d213de321eb8 h1:1EvmLZfb7z6zRrq3RoRufEtRXbnB1v0rrxEuEb70jDE= -github.com/bitrise-io/bitrise-init v0.0.0-20210520122036-d213de321eb8/go.mod h1:I9KSWJm177/IOBMQHzn6BLgymVLQ0xlv/gMwDCYkWYU= +github.com/bitrise-io/bitrise v0.0.0-20220719135434-7f794d69d858 h1:07+it7fY4jvBF7VW8Wxkfvba1KvYo7qhJPDtISz72To= +github.com/bitrise-io/bitrise v0.0.0-20220719135434-7f794d69d858/go.mod h1:tg665QKdaTciGYlv0TwVJW0GGqx4vS2/jAE8sahPRnY= +github.com/bitrise-io/bitrise-init v0.0.0-20220504131857-f00a24c7c8ba h1:uxnQ4A9MKeEAJFaHindNgHiMJTMgNN6MwzcfdU3+quU= +github.com/bitrise-io/bitrise-init v0.0.0-20220504131857-f00a24c7c8ba/go.mod h1:DN4SKPWki1kLKXtWWaKLqPOm8Yv9RQCoylkleqhApDc= github.com/bitrise-io/colorstring v0.0.0-20180614154802-a8cd70115192/go.mod h1:CIHVcxZUvsG99XUJV6JlR7okNsMMGY81jMvPC20W+O0= github.com/bitrise-io/envman v0.0.0-20200512105748-919e33f391ee/go.mod h1:m8pTp1o3Sw9uzDxb1WRm5IBRnMau2iOvPMSnRCAhQNI= -github.com/bitrise-io/envman v0.0.0-20210517135508-b2b4fe89eac5 h1:3jVXjsejV+1EW9Sp7ef+sMinD0J3HFsPgh4Du6ctqZc= github.com/bitrise-io/envman v0.0.0-20210517135508-b2b4fe89eac5/go.mod h1:m8pTp1o3Sw9uzDxb1WRm5IBRnMau2iOvPMSnRCAhQNI= -github.com/bitrise-io/go-android v0.0.0-20210913151943-e1ea0b4df36d h1:F4VCaMk4hZZSwI5MiyBwVnkxmgmvkOz4+uXAacEaRC0= -github.com/bitrise-io/go-android v0.0.0-20210913151943-e1ea0b4df36d/go.mod h1:yTe4i6RfahvAmOChFrS9uCPmJiH0eBEV4jya30v2tTc= +github.com/bitrise-io/envman v0.0.0-20211026063720-03283f9c3f32/go.mod h1:L4WQyg88d87Z4dxNwrYEa0Cwd9/W0gSfXsibw30r8Vw= +github.com/bitrise-io/envman v0.0.0-20220401145857-d11e00a5dc55/go.mod h1:L4WQyg88d87Z4dxNwrYEa0Cwd9/W0gSfXsibw30r8Vw= +github.com/bitrise-io/envman v0.0.0-20220512153504-166d59151b78 h1:l+gCaGlS1yWYX9ualuzu0jlD3WZsJjqvMSE9KCynK5Q= +github.com/bitrise-io/envman v0.0.0-20220512153504-166d59151b78/go.mod h1:L4WQyg88d87Z4dxNwrYEa0Cwd9/W0gSfXsibw30r8Vw= +github.com/bitrise-io/go-android/v2 v2.0.0-alpha.3 h1:tCKogs4CmxEuiR2k330SFkiqQ9qX6Qz4viVGTMAGMPk= +github.com/bitrise-io/go-android/v2 v2.0.0-alpha.3/go.mod h1:pkrTuGB9KAgVTWsMJ8UjqKjSInaNcdp8En9Fxqg2krc= github.com/bitrise-io/go-plist v0.0.0-20210301100253-4b1a112ccd10/go.mod h1:pARutiL3kEuRLV3JvswidvfCj+9Y3qMZtji2BDqLFsA= -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 v0.0.0-20210819160244-b3962254d553/go.mod h1:gPr5wQVOi3wZCY1RkMzk/Ij0rmdgEIP0Og84YgHmVSU= -github.com/bitrise-io/go-steputils v0.0.0-20210924114124-851d30b88892 h1:aD5jTvdf5zIngQ5HeR7Idteae4yaXLqJGn8PE4k2xtI= -github.com/bitrise-io/go-steputils v0.0.0-20210924114124-851d30b88892/go.mod h1:6Y7Dl40gwgW9YG1RAWcjFBk1u9uotuix8g2IkVTXK34= +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/v2 v2.0.0-alpha.8 h1:h8HbopQDZrBzlu4swGNfuIeVNchHwtK64AaibfUkY8o= +github.com/bitrise-io/go-steputils/v2 v2.0.0-alpha.8/go.mod h1:5ES6ToS2nIMou3poXmtYj+aRyjyi6hVE7KBNGnPkaso= +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-20210505091801-98b7dc39ee61/go.mod h1:nhdaDQFvaMny1CugVV6KjK92/q97ENo0RuKSW5I4fbA= github.com/bitrise-io/go-utils v0.0.0-20210505121718-07411d72e36e/go.mod h1:nhdaDQFvaMny1CugVV6KjK92/q97ENo0RuKSW5I4fbA= -github.com/bitrise-io/go-utils v0.0.0-20210506064210-b22e2b7b3ad3/go.mod h1:nhdaDQFvaMny1CugVV6KjK92/q97ENo0RuKSW5I4fbA= -github.com/bitrise-io/go-utils v0.0.0-20210507100250-37de47dfa6ce/go.mod h1:15EZZf02noI5nWFqXMZEoyb1CyqYRXTMz5Fyu4CWFzI= -github.com/bitrise-io/go-utils v0.0.0-20210514083430-4d1fb0330dfe/go.mod h1:DRx7oFuAqk0dbKpAKCqWl0TgrowfJUb/MqYPRscxJOQ= -github.com/bitrise-io/go-utils v0.0.0-20210520073355-367fa34178f5/go.mod h1:DRx7oFuAqk0dbKpAKCqWl0TgrowfJUb/MqYPRscxJOQ= -github.com/bitrise-io/go-utils v0.0.0-20210819105546-07a5bda18d68/go.mod h1:UprBoSn6HxcN9G7yGRSOoe9bSZLh7gLl4yA0/iqwYsI= -github.com/bitrise-io/go-utils v0.0.0-20210819143908-bbd923881fab/go.mod h1:UprBoSn6HxcN9G7yGRSOoe9bSZLh7gLl4yA0/iqwYsI= -github.com/bitrise-io/go-utils v0.0.0-20210924090918-3e7a04d0da9d h1:jU5wvShTLKSo2gYlIBoXONS2MRRL8UwiPOSqi88JF2k= -github.com/bitrise-io/go-utils v0.0.0-20210924090918-3e7a04d0da9d/go.mod h1:Vi4MHnaZVL3PVoPPA/Yp6g2pzntkDH8LGiRSY7qw6KQ= -github.com/bitrise-io/go-xcode v0.0.0-20210520114025-bdbec53ee59f/go.mod h1:a5IANtAnyazHgNjI6/kwQw5vU/WJo1zQ4Lja9WRUNmA= -github.com/bitrise-io/go-xcode v0.0.0-20210521101355-fb6a1eb6e05b h1:JyTlzvdOBOxtYZ7aZVCog2dZUv8LgA8UftT+TpVWtZY= -github.com/bitrise-io/go-xcode v0.0.0-20210521101355-fb6a1eb6e05b/go.mod h1:6Nv5RAsAVS745xN5IihUExVmCA9n9f7s/DSVow4hXrI= +github.com/bitrise-io/go-utils v1.0.1/go.mod h1:ZY1DI+fEpZuFpO9szgDeICM4QbqoWVt0RSY3tRI1heY= +github.com/bitrise-io/go-utils v1.0.2 h1:w4Mz2IvrgDzrFJECuHdvsK1LHO30cdtuy9bBa7Lw2c0= +github.com/bitrise-io/go-utils v1.0.2/go.mod h1:ZY1DI+fEpZuFpO9szgDeICM4QbqoWVt0RSY3tRI1heY= +github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.1/go.mod h1:sy+Ir1X8P3tAAx/qU/r+hqDjHDcrMjIzDEvId1wqNc4= +github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.6/go.mod h1:mysJdafur1ytXda0TeRsV+GxYCJFDU0QcCmYBgQf2Fc= +github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.7/go.mod h1:6i0Gt0JRIbXpsrFDJT1YWghFfdN8qF26/fnpc/6d/88= +github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.8 h1:IKTN+uFitj/CnjAEe3KPNn7qK9wLJBEaKb0ZJpUUfeY= +github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.8/go.mod h1:Ta/ards3Ih/3Q6X8tBtcj6zTHcNf1hRSXv1E8lPgIYk= +github.com/bitrise-io/go-xcode v1.0.6/go.mod h1:Y0Wu2dXm0MilJ/4D3+gPHaNMlUcP+1DjIPoLPykq7wY= +github.com/bitrise-io/go-xcode v1.0.9 h1:+sbqOYidQ+aiFfCTDpf2LdGSQEM5RfbtDsiG27zJG+s= +github.com/bitrise-io/go-xcode v1.0.9/go.mod h1:Y0Wu2dXm0MilJ/4D3+gPHaNMlUcP+1DjIPoLPykq7wY= github.com/bitrise-io/goinp v0.0.0-20210504152833-8559b0680ab1/go.mod h1:iRbd8zAXLeNy+0gic0eqNCxXvDGe8ZEY/uYX2CCeAoo= +github.com/bitrise-io/goinp v0.0.0-20211005113137-305e91b481f4/go.mod h1:iRbd8zAXLeNy+0gic0eqNCxXvDGe8ZEY/uYX2CCeAoo= github.com/bitrise-io/gows v0.0.0-20210505125306-dd92ff463938/go.mod h1:3Cp9ceJ8wHl1Av6oEE2ff1iWaYLliQuD+oaNdyM0NWQ= -github.com/bitrise-io/pkcs12 v0.0.0-20210430063833-0da06eb56630/go.mod h1:UiXKNs0essbC14a2TvGlnUKo9isP9m4guPrp8KJHJpU= +github.com/bitrise-io/gows v0.0.0-20211005113107-14f65e686b88/go.mod h1:3Cp9ceJ8wHl1Av6oEE2ff1iWaYLliQuD+oaNdyM0NWQ= +github.com/bitrise-io/pkcs12 v0.0.0-20211108084543-e52728e011c8/go.mod h1:UiXKNs0essbC14a2TvGlnUKo9isP9m4guPrp8KJHJpU= github.com/bitrise-io/stepman v0.0.0-20210505110307-5c2296bcc558/go.mod h1:WLh58JYBgbD1Z/yyw1AkFz/90F6oBL0HS/luBpUW9dI= -github.com/bitrise-io/stepman v0.0.0-20210517135458-203f7a48d37a h1:qsEFYqhVeo0mLrdl7nLTNbCz0AZ+8nOxQD+LPFw2Oq4= github.com/bitrise-io/stepman v0.0.0-20210517135458-203f7a48d37a/go.mod h1:WLh58JYBgbD1Z/yyw1AkFz/90F6oBL0HS/luBpUW9dI= +github.com/bitrise-io/stepman v0.0.0-20220718172049-e5ae0a09c2f2 h1:JOiFJlKNYKoK6a7d7GaSqOklBvQAogUvqZF8xvmGw90= +github.com/bitrise-io/stepman v0.0.0-20220718172049-e5ae0a09c2f2/go.mod h1:25vk5IaQiOpXLMcjyJjY6RmZe6JEOqMe8TJoTvKgyuw= +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= +github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa/go.mod h1:KnogPXtdwXqoenmZCw6S+25EAm2MkxbG0deNDu4cbSA= -github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM= +github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= +github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI= github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= -github.com/hashicorp/go-retryablehttp v0.6.6/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= -github.com/hashicorp/go-retryablehttp v0.7.0 h1:eu1EI/mbirUgP5C8hVsTNaGZreBDlYiwC1FZWkvQPQ4= github.com/hashicorp/go-retryablehttp v0.7.0/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= -github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/go-version v1.3.0 h1:McDWVJIU/y+u1BRV06dPaLfLCaT7fUTJLp5r04x7iNw= +github.com/hashicorp/go-retryablehttp v0.7.1 h1:sUiuQAnLlbvmExtFQs72iFW/HXeUn8Z1aJLQ4LJJbTQ= +github.com/hashicorp/go-retryablehttp v0.7.1/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/go-version v1.4.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/go-version v1.5.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= +github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= +github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -74,6 +89,7 @@ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk= github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -82,44 +98,57 @@ github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoH 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= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/urfave/cli v1.21.0/go.mod h1:lxDj6qX9Q6lWQxIrbrT0nwecwUtRnhVZAJjJZrVUZZQ= github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/whilp/git-urls v1.0.0/go.mod h1:J16SAmobsqc3Qcy98brfl5f5+e0clUvg1krgwk/qCfE= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210503195802-e9a32991a82e/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= -golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= -golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20211202192323-5770296d904e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210503173754-0981d6026fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210819072135-bce67f096156/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY= -golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200220224806-8a925fa4c0df/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/viktorbenei/cobra.v0 v0.0.0-20160704194906-5513220bc3d9/go.mod h1:ES58JZUprnB7l7btSIgwT2KtWLFz7nleq84TF6wsCjg= gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= @@ -127,4 +156,4 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -howett.net/plist v0.0.0-20201203080718-1454fab16a06/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0= +howett.net/plist v1.0.0/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g= diff --git a/main.go b/main.go index 457bc8a..85c50c5 100644 --- a/main.go +++ b/main.go @@ -13,15 +13,15 @@ import ( "github.com/bitrise-io/go-steputils/cache" "github.com/bitrise-io/go-steputils/command/gems" - "github.com/bitrise-io/go-steputils/ruby" "github.com/bitrise-io/go-steputils/stepconf" - "github.com/bitrise-io/go-utils/command" - "github.com/bitrise-io/go-utils/env" + "github.com/bitrise-io/go-steputils/v2/ruby" "github.com/bitrise-io/go-utils/errorutil" "github.com/bitrise-io/go-utils/fileutil" "github.com/bitrise-io/go-utils/log" "github.com/bitrise-io/go-utils/pathutil" "github.com/bitrise-io/go-utils/retry" + "github.com/bitrise-io/go-utils/v2/command" + "github.com/bitrise-io/go-utils/v2/env" "github.com/bitrise-io/go-xcode/appleauth" "github.com/bitrise-io/go-xcode/devportalservice" "github.com/kballard/go-shellquote" @@ -103,9 +103,9 @@ func fastlaneDebugInfo(workDir string, useBundler bool, bundlerVersion gems.Vers log.Debugf("$ %s", cmd.PrintableCommandArgs()) if err := cmd.Run(); err != nil { if errorutil.IsExitStatusError(err) { - return "", fmt.Errorf("Fastlane command (%s) failed, output: %s", cmd.PrintableCommandArgs(), outBuffer.String()) + return "", fmt.Errorf("fastlane command (%s) failed, output: %s", cmd.PrintableCommandArgs(), outBuffer.String()) } - return "", fmt.Errorf("Fastlane command (%s) failed: %v", cmd.PrintableCommandArgs(), err) + return "", fmt.Errorf("fastlane command (%s) failed: %v", cmd.PrintableCommandArgs(), err) } return outBuffer.String(), nil @@ -138,7 +138,7 @@ func handleSessionDataError(err error) { func main() { var config Config - parser := stepconf.NewInputParser(env.NewRepository()) + parser := stepconf.NewDefaultEnvParser() if err := parser.Parse(&config); err != nil { failf("Issue with input: %s", err) } @@ -208,7 +208,7 @@ func main() { } } - // Select and fetch Apple authenication source + // Select and fetch Apple authentication source var devportalConnectionProvider *devportalservice.BitriseClient if config.BuildURL != "" && config.BuildAPIToken != "" { devportalConnectionProvider = devportalservice.NewBitriseClient(retry.NewHTTPClient().StandardClient(), config.BuildURL, string(config.BuildAPIToken)) diff --git a/vendor/github.com/bitrise-io/bitrise-init/models/configbuilder.go b/vendor/github.com/bitrise-io/bitrise-init/models/configbuilder.go index fcb5ab0..af85ee5 100644 --- a/vendor/github.com/bitrise-io/bitrise-init/models/configbuilder.go +++ b/vendor/github.com/bitrise-io/bitrise-init/models/configbuilder.go @@ -68,17 +68,7 @@ func (builder *ConfigBuilderModel) Generate(projectType string, appEnvs ...envma workflows[string(workflowID)] = workflowBuilder.generate() } - triggerMap := []bitriseModels.TriggerMapItemModel{ - bitriseModels.TriggerMapItemModel{ - PushBranch: "*", - WorkflowID: string(PrimaryWorkflowID), - }, - bitriseModels.TriggerMapItemModel{ - PullRequestSourceBranch: "*", - WorkflowID: string(PrimaryWorkflowID), - }, - } - + triggerMap := []bitriseModels.TriggerMapItemModel{} app := bitriseModels.AppModel{ Environments: appEnvs, } diff --git a/vendor/github.com/bitrise-io/bitrise-init/scanners/android/android.go b/vendor/github.com/bitrise-io/bitrise-init/scanners/android/android.go index 44ec3e7..7f7d6ff 100644 --- a/vendor/github.com/bitrise-io/bitrise-init/scanners/android/android.go +++ b/vendor/github.com/bitrise-io/bitrise-init/scanners/android/android.go @@ -8,14 +8,12 @@ import ( "github.com/bitrise-io/bitrise-init/analytics" "github.com/bitrise-io/bitrise-init/models" + "github.com/bitrise-io/go-utils/log" ) // Scanner ... type Scanner struct { - SearchDir string - ProjectRoots []string - ExcludeTest bool - ExcludeAppIcon bool + Projects []Project } // NewScanner ... @@ -35,58 +33,114 @@ func (*Scanner) ExcludedScannerNames() []string { // DetectPlatform ... func (scanner *Scanner) DetectPlatform(searchDir string) (_ bool, err error) { - scanner.SearchDir = searchDir + projects, err := detect(searchDir) + scanner.Projects = projects + detected := len(projects) > 0 + return detected, err +} + +func detect(searchDir string) ([]Project, error) { projectFiles := fileGroups{ {"build.gradle", "build.gradle.kts"}, {"settings.gradle", "settings.gradle.kts"}, } skipDirs := []string{".git", "CordovaLib", "node_modules"} - scanner.ProjectRoots, err = walkMultipleFileGroups(searchDir, projectFiles, skipDirs) + + log.TInfof("Searching for android files") + + projectRoots, err := walkMultipleFileGroups(searchDir, projectFiles, skipDirs) + if err != nil { + return nil, fmt.Errorf("failed to search for build.gradle files, error: %s", err) + } + + log.TPrintf("%d android files detected", len(projectRoots)) + for _, file := range projectRoots { + log.TPrintf("- %s", file) + } + + if len(projectRoots) == 0 { + return nil, nil + } + log.TSuccessf("Platform detected") + + projects, err := parseProjects(searchDir, projectRoots) if err != nil { - return false, fmt.Errorf("failed to search for build.gradle files, error: %s", err) + return nil, err } - return len(scanner.ProjectRoots) > 0, err + return projects, nil } -// Options ... -func (scanner *Scanner) Options() (models.OptionNode, models.Warnings, models.Icons, error) { - projectLocationOption := models.NewOption(ProjectLocationInputTitle, ProjectLocationInputSummary, ProjectLocationInputEnvKey, models.TypeSelector) - warnings := models.Warnings{} - appIconsAllProjects := models.Icons{} +func parseProjects(searchDir string, projectRoots []string) ([]Project, error) { + var ( + lastErr error + projects []Project + ) + + for _, projectRoot := range projectRoots { + var warnings models.Warnings + + log.TInfof("Investigating Android project: %s", projectRoot) - foundOptions := false - var lastErr error = nil - for _, projectRoot := range scanner.ProjectRoots { exists, err := containsLocalProperties(projectRoot) if err != nil { lastErr = err + log.TWarnf("%s", err) + continue } if exists { containsLocalPropertiesWarning := fmt.Sprintf("the local.properties file should NOT be checked into Version Control Systems, as it contains information specific to your local configuration, the location of the file is: %s", filepath.Join(projectRoot, "local.properties")) - warnings = append(warnings, containsLocalPropertiesWarning) + warnings = []string{containsLocalPropertiesWarning} } if err := checkGradlew(projectRoot); err != nil { lastErr = err + log.TWarnf("%s", err) + continue } - relProjectRoot, err := filepath.Rel(scanner.SearchDir, projectRoot) + relProjectRoot, err := filepath.Rel(searchDir, projectRoot) if err != nil { lastErr = err + log.TWarnf("%s", err) + continue } - icons, err := LookupIcons(projectRoot, scanner.SearchDir) + icons, err := LookupIcons(projectRoot, searchDir) if err != nil { analytics.LogInfo("android-icon-lookup", analytics.DetectorErrorData("android", err), "Failed to lookup android icon") } - appIconsAllProjects = append(appIconsAllProjects, icons...) - iconIDs := make([]string, len(icons)) - for i, icon := range icons { + + projects = append(projects, Project{ + RelPath: relProjectRoot, + Icons: icons, + Warnings: warnings, + }) + } + + if len(projects) == 0 { + return []Project{}, lastErr + } + + return projects, nil +} + +// Options ... +func (scanner *Scanner) Options() (models.OptionNode, models.Warnings, models.Icons, error) { + projectLocationOption := models.NewOption(ProjectLocationInputTitle, ProjectLocationInputSummary, ProjectLocationInputEnvKey, models.TypeSelector) + warnings := models.Warnings{} + appIconsAllProjects := models.Icons{} + + for _, project := range scanner.Projects { + warnings = append(warnings, project.Warnings...) + appIconsAllProjects = append(appIconsAllProjects, project.Icons...) + + iconIDs := make([]string, len(project.Icons)) + for i, icon := range project.Icons { iconIDs[i] = icon.Filename } @@ -94,13 +148,9 @@ func (scanner *Scanner) Options() (models.OptionNode, models.Warnings, models.Ic moduleOption := models.NewOption(ModuleInputTitle, ModuleInputSummary, ModuleInputEnvKey, models.TypeUserInput) variantOption := models.NewOption(VariantInputTitle, VariantInputSummary, VariantInputEnvKey, models.TypeOptionalUserInput) - projectLocationOption.AddOption(relProjectRoot, moduleOption) + projectLocationOption.AddOption(project.RelPath, moduleOption) moduleOption.AddOption("app", variantOption) variantOption.AddConfig("", configOption) - foundOptions = true - } - if !foundOptions && lastErr != nil { - return models.OptionNode{}, warnings, nil, lastErr } return *projectLocationOption, warnings, appIconsAllProjects, nil @@ -121,8 +171,8 @@ func (scanner *Scanner) DefaultOptions() models.OptionNode { } // Configs ... -func (scanner *Scanner) Configs() (models.BitriseConfigMap, error) { - configBuilder := scanner.generateConfigBuilder() +func (scanner *Scanner) Configs(isPrivateRepository bool) (models.BitriseConfigMap, error) { + configBuilder := scanner.generateConfigBuilder(isPrivateRepository) config, err := configBuilder.Generate(ScannerName) if err != nil { @@ -141,7 +191,7 @@ func (scanner *Scanner) Configs() (models.BitriseConfigMap, error) { // DefaultConfigs ... func (scanner *Scanner) DefaultConfigs() (models.BitriseConfigMap, error) { - configBuilder := scanner.generateConfigBuilder() + configBuilder := scanner.generateConfigBuilder(true) config, err := configBuilder.Generate(ScannerName) if err != nil { diff --git a/vendor/github.com/bitrise-io/bitrise-init/scanners/android/const.go b/vendor/github.com/bitrise-io/bitrise-init/scanners/android/const.go index f5df5ae..0cc8df5 100644 --- a/vendor/github.com/bitrise-io/bitrise-init/scanners/android/const.go +++ b/vendor/github.com/bitrise-io/bitrise-init/scanners/android/const.go @@ -1,34 +1,16 @@ package android -const deployWorkflowDescription = `## How to get a signed APK +const ( + primaryWorkflowDescription = `Runs tests. -This workflow contains the **Sign APK** step. To sign your APK all you have to do is to: - -1. Click on **Code Signing** tab -1. Find the **ANDROID KEYSTORE FILE** section -1. Click or drop your file on the upload file field -1. Fill the displayed 3 input fields: - 1. **Keystore password** - 1. **Keystore alias** - 1. **Private key password** -1. Click on **[Save metadata]** button - -That's it! From now on, **Sign APK** step will receive your uploaded files. - -## To run this workflow - -If you want to run this workflow manually: - -1. Open the app's build list page -2. Click on **[Start/Schedule a Build]** button -3. Select **deploy** in **Workflow** dropdown input -4. Click **[Start Build]** button - -Or if you need this workflow to be started by a GIT event: +Next steps: +- Check out [Getting started with Android apps](https://devcenter.bitrise.io/en/getting-started/getting-started-with-android-apps.html). +` -1. Click on **Triggers** tab -2. Setup your desired event (push/tag/pull) and select **deploy** workflow -3. Click on **[Done]** and then **[Save]** buttons + deployWorkflowDescription = `Deploys app using [Deploy to bitrise.io Step](https://devcenter.bitrise.io/en/getting-started/getting-started-with-android-apps.html#deploying-an-android-app-to-bitrise-io-53056). -The next change in your repository that matches any of your trigger map event will start **deploy** workflow. +Next steps: +- Check out [Getting started with Android apps](https://devcenter.bitrise.io/en/getting-started/getting-started-with-android-apps.html) for signing and deployment options. +- [Set up code signing with *Android Sign* Step](https://devcenter.bitrise.io/en/code-signing/android-code-signing/android-code-signing-using-the-android-sign-step.html). ` +) diff --git a/vendor/github.com/bitrise-io/bitrise-init/scanners/android/utility.go b/vendor/github.com/bitrise-io/bitrise-init/scanners/android/utility.go index d7f86d6..b53a5bf 100644 --- a/vendor/github.com/bitrise-io/bitrise-init/scanners/android/utility.go +++ b/vendor/github.com/bitrise-io/bitrise-init/scanners/android/utility.go @@ -39,11 +39,16 @@ const ( ModuleInputTitle = "Module" ModuleInputSummary = "Modules provide a container for your Android project's source code, resource files, and app level settings, such as the module-level build file and Android manifest file. Each module can be independently built, tested, and debugged. You can add new modules to your Bitrise builds at any time." - GradlewPathInputKey = "gradlew_path" - GradlewPathInputEnvKey = "GRADLEW_PATH" - GradlewPathInputTitle = "Gradlew file path" + GradlewPathInputKey = "gradlew_path" ) +// Project is an Android project on the filesystem +type Project struct { + RelPath string + Icons models.Icons + Warnings models.Warnings +} + func walk(src string, fn func(path string, info os.FileInfo) error) error { return filePathWalk(src, func(path string, info os.FileInfo, err error) error { if err != nil { @@ -133,42 +138,35 @@ that the right Gradle version is installed and used for the build. More info/gui return nil } -func (scanner *Scanner) generateConfigBuilder() models.ConfigBuilderModel { +func (scanner *Scanner) generateConfigBuilder(isPrivateRepository bool) models.ConfigBuilderModel { configBuilder := models.NewDefaultConfigBuilder() projectLocationEnv, gradlewPath, moduleEnv, variantEnv := "$"+ProjectLocationInputEnvKey, "$"+ProjectLocationInputEnvKey+"/gradlew", "$"+ModuleInputEnvKey, "$"+VariantInputEnvKey //-- primary - configBuilder.AppendStepListItemsTo(models.PrimaryWorkflowID, steps.DefaultPrepareStepList(true)...) + configBuilder.AppendStepListItemsTo(models.PrimaryWorkflowID, steps.DefaultPrepareStepListV2(steps.PrepareListParams{ + ShouldIncludeCache: true, + ShouldIncludeActivateSSH: isPrivateRepository, + })...) configBuilder.AppendStepListItemsTo(models.PrimaryWorkflowID, steps.InstallMissingAndroidToolsStepListItem( envmanModels.EnvironmentItemModel{GradlewPathInputKey: gradlewPath}, )) - configBuilder.AppendStepListItemsTo(models.PrimaryWorkflowID, steps.AndroidLintStepListItem( - envmanModels.EnvironmentItemModel{ - ProjectLocationInputKey: projectLocationEnv, - }, - envmanModels.EnvironmentItemModel{ - ModuleInputKey: moduleEnv, - }, - envmanModels.EnvironmentItemModel{ - VariantInputKey: variantEnv, - }, - )) configBuilder.AppendStepListItemsTo(models.PrimaryWorkflowID, steps.AndroidUnitTestStepListItem( envmanModels.EnvironmentItemModel{ ProjectLocationInputKey: projectLocationEnv, }, - envmanModels.EnvironmentItemModel{ - ModuleInputKey: moduleEnv, - }, envmanModels.EnvironmentItemModel{ VariantInputKey: variantEnv, }, )) - configBuilder.AppendStepListItemsTo(models.PrimaryWorkflowID, steps.DefaultDeployStepList(true)...) + configBuilder.AppendStepListItemsTo(models.PrimaryWorkflowID, steps.DefaultDeployStepListV2(true)...) + configBuilder.SetWorkflowDescriptionTo(models.PrimaryWorkflowID, primaryWorkflowDescription) //-- deploy - configBuilder.AppendStepListItemsTo(models.DeployWorkflowID, steps.DefaultPrepareStepList(true)...) + configBuilder.AppendStepListItemsTo(models.DeployWorkflowID, steps.DefaultPrepareStepListV2(steps.PrepareListParams{ + ShouldIncludeCache: true, + ShouldIncludeActivateSSH: isPrivateRepository, + })...) configBuilder.AppendStepListItemsTo(models.DeployWorkflowID, steps.InstallMissingAndroidToolsStepListItem( envmanModels.EnvironmentItemModel{GradlewPathInputKey: gradlewPath}, )) @@ -181,9 +179,6 @@ func (scanner *Scanner) generateConfigBuilder() models.ConfigBuilderModel { envmanModels.EnvironmentItemModel{ ProjectLocationInputKey: projectLocationEnv, }, - envmanModels.EnvironmentItemModel{ - ModuleInputKey: moduleEnv, - }, envmanModels.EnvironmentItemModel{ VariantInputKey: variantEnv, }, @@ -192,9 +187,6 @@ func (scanner *Scanner) generateConfigBuilder() models.ConfigBuilderModel { envmanModels.EnvironmentItemModel{ ProjectLocationInputKey: projectLocationEnv, }, - envmanModels.EnvironmentItemModel{ - ModuleInputKey: moduleEnv, - }, envmanModels.EnvironmentItemModel{ VariantInputKey: variantEnv, }, @@ -212,7 +204,7 @@ func (scanner *Scanner) generateConfigBuilder() models.ConfigBuilderModel { }, )) configBuilder.AppendStepListItemsTo(models.DeployWorkflowID, steps.SignAPKStepListItem()) - configBuilder.AppendStepListItemsTo(models.DeployWorkflowID, steps.DefaultDeployStepList(true)...) + configBuilder.AppendStepListItemsTo(models.DeployWorkflowID, steps.DefaultDeployStepListV2(true)...) configBuilder.SetWorkflowDescriptionTo(models.DeployWorkflowID, deployWorkflowDescription) diff --git a/vendor/github.com/bitrise-io/bitrise-init/steps/const.go b/vendor/github.com/bitrise-io/bitrise-init/steps/const.go index 01f52c9..dc806be 100644 --- a/vendor/github.com/bitrise-io/bitrise-init/steps/const.go +++ b/vendor/github.com/bitrise-io/bitrise-init/steps/const.go @@ -25,7 +25,7 @@ const ( // AndroidBuildID ... AndroidBuildID = "android-build" // AndroidBuildVersion ... - AndroidBuildVersion = "0" + AndroidBuildVersion = "1" ) const ( @@ -67,7 +67,7 @@ const ( // DeployToBitriseIoID ... DeployToBitriseIoID = "deploy-to-bitrise-io" // DeployToBitriseIoVersion ... - DeployToBitriseIoVersion = "1" + DeployToBitriseIoVersion = "2" ) const ( @@ -90,7 +90,7 @@ const ( // InstallMissingAndroidToolsID ... InstallMissingAndroidToolsID = "install-missing-android-tools" // InstallMissingAndroidToolsVersion ... - InstallMissingAndroidToolsVersion = "2" + InstallMissingAndroidToolsVersion = "3" ) const ( @@ -125,42 +125,21 @@ const ( // XcodeArchiveID ... XcodeArchiveID = "xcode-archive" // XcodeArchiveVersion ... - XcodeArchiveVersion = "3" + XcodeArchiveVersion = "4" ) const ( // XcodeTestID ... XcodeTestID = "xcode-test" // XcodeTestVersion ... - XcodeTestVersion = "2" + XcodeTestVersion = "4" ) const ( - // XamarinUserManagementID ... - XamarinUserManagementID = "xamarin-user-management" - // XamarinUserManagementVersion ... - XamarinUserManagementVersion = "1" -) - -const ( - // NugetRestoreID ... - NugetRestoreID = "nuget-restore" - // NugetRestoreVersion ... - NugetRestoreVersion = "1" -) - -const ( - // XamarinComponentsRestoreID ... - XamarinComponentsRestoreID = "xamarin-components-restore" - // XamarinComponentsRestoreVersion ... - XamarinComponentsRestoreVersion = "0" -) - -const ( - // XamarinArchiveID ... - XamarinArchiveID = "xamarin-archive" - // XamarinArchiveVersion ... - XamarinArchiveVersion = "1" + // XcodeBuildForTestID ... + XcodeBuildForTestID = "xcode-build-for-test" + // XcodeBuildForTestVersion ... + XcodeBuildForTestVersion = "1" ) const ( @@ -174,7 +153,7 @@ const ( // ExportXCArchiveID ... ExportXCArchiveID = "export-xcarchive" // ExportXCArchiveVersion ... - ExportXCArchiveVersion = "3" + ExportXCArchiveVersion = "4" ) const ( @@ -188,7 +167,7 @@ const ( // CordovaArchiveID ... CordovaArchiveID = "cordova-archive" // CordovaArchiveVersion ... - CordovaArchiveVersion = "2" + CordovaArchiveVersion = "3" ) const ( @@ -233,6 +212,16 @@ const ( ExpoDetachVersion = "1" ) +const ( + // RunEASBuildID ... + RunEASBuildID = "run-eas-build" + // RunEASBuildVersion ... + RunEASBuildVersion = "0" +) + +// RunEASBuildPlatforms ... +var RunEASBuildPlatforms = []string{"all", "android", "ios"} + const ( // YarnID ... YarnID = "yarn" diff --git a/vendor/github.com/bitrise-io/bitrise-init/steps/steps.go b/vendor/github.com/bitrise-io/bitrise-init/steps/steps.go index 8e2bd8e..3ddb3cf 100644 --- a/vendor/github.com/bitrise-io/bitrise-init/steps/steps.go +++ b/vendor/github.com/bitrise-io/bitrise-init/steps/steps.go @@ -7,6 +7,12 @@ import ( stepmanModels "github.com/bitrise-io/stepman/models" ) +// PrepareListParams describes the default prepare Step options. +type PrepareListParams struct { + ShouldIncludeCache bool + ShouldIncludeActivateSSH bool +} + func stepIDComposite(ID, version string) string { if version != "" { return ID + "@" + version @@ -33,8 +39,9 @@ func stepListItem(stepIDComposite, title, runIf string, inputs ...envmanModels.E // DefaultPrepareStepList ... func DefaultPrepareStepList(isIncludeCache bool) []bitriseModels.StepListItemModel { + runIfCondition := `{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}` stepList := []bitriseModels.StepListItemModel{ - ActivateSSHKeyStepListItem(), + ActivateSSHKeyStepListItem(runIfCondition), GitCloneStepListItem(), } @@ -45,6 +52,23 @@ func DefaultPrepareStepList(isIncludeCache bool) []bitriseModels.StepListItemMod return append(stepList, ScriptSteplistItem(ScriptDefaultTitle)) } +// DefaultPrepareStepListV2 ... +func DefaultPrepareStepListV2(params PrepareListParams) []bitriseModels.StepListItemModel { + stepList := []bitriseModels.StepListItemModel{} + + if params.ShouldIncludeActivateSSH { + stepList = append(stepList, ActivateSSHKeyStepListItem("")) + } + + stepList = append(stepList, GitCloneStepListItem()) + + if params.ShouldIncludeCache { + stepList = append(stepList, CachePullStepListItem()) + } + + return stepList +} + // DefaultDeployStepList ... func DefaultDeployStepList(isIncludeCache bool) []bitriseModels.StepListItemModel { stepList := []bitriseModels.StepListItemModel{ @@ -58,11 +82,23 @@ func DefaultDeployStepList(isIncludeCache bool) []bitriseModels.StepListItemMode return stepList } +// DefaultDeployStepListV2 ... +func DefaultDeployStepListV2(shouldIncludeCache bool) []bitriseModels.StepListItemModel { + stepList := []bitriseModels.StepListItemModel{} + + if shouldIncludeCache { + stepList = append(stepList, CachePushStepListItem()) + } + + stepList = append(stepList, DeployToBitriseIoStepListItem()) + + return stepList +} + // ActivateSSHKeyStepListItem ... -func ActivateSSHKeyStepListItem() bitriseModels.StepListItemModel { +func ActivateSSHKeyStepListItem(runIfCondition string) bitriseModels.StepListItemModel { stepIDComposite := stepIDComposite(ActivateSSHKeyID, ActivateSSHKeyVersion) - runIf := `{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}` - return stepListItem(stepIDComposite, "", runIf) + return stepListItem(stepIDComposite, "", runIfCondition) } // AndroidLintStepListItem ... @@ -167,34 +203,15 @@ func XcodeArchiveStepListItem(inputs ...envmanModels.EnvironmentItemModel) bitri return stepListItem(stepIDComposite, "", "", inputs...) } -// XcodeTestStepListItem ... -func XcodeTestStepListItem(inputs ...envmanModels.EnvironmentItemModel) bitriseModels.StepListItemModel { - stepIDComposite := stepIDComposite(XcodeTestID, XcodeTestVersion) +// XcodeBuildForTestStepListItem ... +func XcodeBuildForTestStepListItem(inputs ...envmanModels.EnvironmentItemModel) bitriseModels.StepListItemModel { + stepIDComposite := stepIDComposite(XcodeBuildForTestID, XcodeBuildForTestVersion) return stepListItem(stepIDComposite, "", "", inputs...) } -// XamarinUserManagementStepListItem ... -func XamarinUserManagementStepListItem(inputs ...envmanModels.EnvironmentItemModel) bitriseModels.StepListItemModel { - stepIDComposite := stepIDComposite(XamarinUserManagementID, XamarinUserManagementVersion) - runIf := ".IsCI" - return stepListItem(stepIDComposite, "", runIf, inputs...) -} - -// NugetRestoreStepListItem ... -func NugetRestoreStepListItem() bitriseModels.StepListItemModel { - stepIDComposite := stepIDComposite(NugetRestoreID, NugetRestoreVersion) - return stepListItem(stepIDComposite, "", "") -} - -// XamarinComponentsRestoreStepListItem ... -func XamarinComponentsRestoreStepListItem() bitriseModels.StepListItemModel { - stepIDComposite := stepIDComposite(XamarinComponentsRestoreID, XamarinComponentsRestoreVersion) - return stepListItem(stepIDComposite, "", "") -} - -// XamarinArchiveStepListItem ... -func XamarinArchiveStepListItem(inputs ...envmanModels.EnvironmentItemModel) bitriseModels.StepListItemModel { - stepIDComposite := stepIDComposite(XamarinArchiveID, XamarinArchiveVersion) +// XcodeTestStepListItem ... +func XcodeTestStepListItem(inputs ...envmanModels.EnvironmentItemModel) bitriseModels.StepListItemModel { + stepIDComposite := stepIDComposite(XcodeTestID, XcodeTestVersion) return stepListItem(stepIDComposite, "", "", inputs...) } @@ -247,19 +264,42 @@ func KarmaJasmineTestRunnerStepListItem(inputs ...envmanModels.EnvironmentItemMo } // NpmStepListItem ... -func NpmStepListItem(inputs ...envmanModels.EnvironmentItemModel) bitriseModels.StepListItemModel { +func NpmStepListItem(command, workdir string) bitriseModels.StepListItemModel { + var inputs []envmanModels.EnvironmentItemModel + if workdir != "" { + inputs = append(inputs, envmanModels.EnvironmentItemModel{"workdir": workdir}) + } + if command != "" { + inputs = append(inputs, envmanModels.EnvironmentItemModel{"command": command}) + } + stepIDComposite := stepIDComposite(NpmID, NpmVersion) return stepListItem(stepIDComposite, "", "", inputs...) } -// ExpoDetachStepListItem ... -func ExpoDetachStepListItem(inputs ...envmanModels.EnvironmentItemModel) bitriseModels.StepListItemModel { - stepIDComposite := stepIDComposite(ExpoDetachID, ExpoDetachVersion) +// RunEASBuildStepListItem ... +func RunEASBuildStepListItem(workdir, platform string) bitriseModels.StepListItemModel { + var inputs []envmanModels.EnvironmentItemModel + if platform != "" { + inputs = append(inputs, envmanModels.EnvironmentItemModel{"platform": platform}) + } + if workdir != "" { + inputs = append(inputs, envmanModels.EnvironmentItemModel{"work_dir": workdir}) + } + stepIDComposite := stepIDComposite(RunEASBuildID, RunEASBuildVersion) return stepListItem(stepIDComposite, "", "", inputs...) } // YarnStepListItem ... -func YarnStepListItem(inputs ...envmanModels.EnvironmentItemModel) bitriseModels.StepListItemModel { +func YarnStepListItem(command, workdir string) bitriseModels.StepListItemModel { + var inputs []envmanModels.EnvironmentItemModel + if workdir != "" { + inputs = append(inputs, envmanModels.EnvironmentItemModel{"workdir": workdir}) + } + if command != "" { + inputs = append(inputs, envmanModels.EnvironmentItemModel{"command": command}) + } + stepIDComposite := stepIDComposite(YarnID, YarnVersion) return stepListItem(stepIDComposite, "", "", inputs...) } diff --git a/vendor/github.com/bitrise-io/bitrise/models/models.go b/vendor/github.com/bitrise-io/bitrise/models/models.go index b222e2f..f4eb4fe 100644 --- a/vendor/github.com/bitrise-io/bitrise/models/models.go +++ b/vendor/github.com/bitrise-io/bitrise/models/models.go @@ -18,6 +18,8 @@ const ( StepRunStatusCodeSkipped = 3 // StepRunStatusCodeSkippedWithRunIf ... StepRunStatusCodeSkippedWithRunIf = 4 + // StepRunStatusCodePreparationFailed ... + StepRunStatusCodePreparationFailed = 5 // Version ... Version = "11" diff --git a/vendor/github.com/bitrise-io/bitrise/models/models_methods.go b/vendor/github.com/bitrise-io/bitrise/models/models_methods.go index c04ccc1..389c313 100644 --- a/vendor/github.com/bitrise-io/bitrise/models/models_methods.go +++ b/vendor/github.com/bitrise-io/bitrise/models/models_methods.go @@ -944,7 +944,7 @@ func MergeStepWith(step, otherStep stepmanModels.StepModel) (stepmanModels.StepM step.Toolkit = new(stepmanModels.StepToolkitModel) *step.Toolkit = *otherStep.Toolkit } - if otherStep.Deps != nil && (len(otherStep.Deps.Brew) > 0 || len(otherStep.Deps.AptGet) > 0 || len(otherStep.Deps.CheckOnly) > 0) { + if otherStep.Deps != nil && (len(otherStep.Deps.Brew) > 0 || len(otherStep.Deps.AptGet) > 0) { step.Deps = otherStep.Deps } if otherStep.IsRequiresAdminUser != nil { diff --git a/vendor/github.com/bitrise-io/envman/models/models_methods.go b/vendor/github.com/bitrise-io/envman/models/models_methods.go index 000d321..833b59c 100644 --- a/vendor/github.com/bitrise-io/envman/models/models_methods.go +++ b/vendor/github.com/bitrise-io/envman/models/models_methods.go @@ -23,7 +23,7 @@ const ( // DefaultSkipIfEmpty ... DefaultSkipIfEmpty = false - //DefaultIsRequired ... + // DefaultIsRequired ... DefaultIsRequired = false // DefaultIsDontChangeValue ... DefaultIsDontChangeValue = false @@ -42,11 +42,11 @@ func NewEnvJSONList(jsonStr string) (EnvsJSONListModel, error) { return list, nil } -// GetKeyValuePair ... -func (env EnvironmentItemModel) GetKeyValuePair() (string, string, error) { +// GetKeyValuePairWithType ... +func (env EnvironmentItemModel) GetKeyValuePairWithType() (string, interface{}, error) { // Collect keys and values - keys := []string{} - values := []interface{}{} + var keys []string + var values []interface{} for key, value := range env { keys = append(keys, key) @@ -84,6 +84,16 @@ func (env EnvironmentItemModel) GetKeyValuePair() (string, string, error) { return "", "", fmt.Errorf("more than 1 environment key specified: %v", keys) } + return key, value, nil +} + +// GetKeyValuePair ... +func (env EnvironmentItemModel) GetKeyValuePair() (string, string, error) { + key, value, err := env.GetKeyValuePairWithType() + if err != nil { + return "", "", err + } + // Cast env value to string valueStr := "" @@ -312,13 +322,10 @@ func (env *EnvironmentItemModel) FillMissingDefaults() error { // Validate ... func (env EnvironmentItemModel) Validate() error { - key, _, err := env.GetKeyValuePair() + _, _, err := env.GetKeyValuePair() if err != nil { return err } - if key == "" { - return errors.New("no environment key found") - } _, err = env.GetOptions() if err != nil { return err diff --git a/vendor/github.com/bitrise-io/go-android/cache/cache.go b/vendor/github.com/bitrise-io/go-android/v2/cache/cache.go similarity index 99% rename from vendor/github.com/bitrise-io/go-android/cache/cache.go rename to vendor/github.com/bitrise-io/go-android/v2/cache/cache.go index 2396339..ac0973c 100644 --- a/vendor/github.com/bitrise-io/go-android/cache/cache.go +++ b/vendor/github.com/bitrise-io/go-android/v2/cache/cache.go @@ -10,10 +10,10 @@ import ( "strings" "github.com/bitrise-io/go-steputils/cache" - "github.com/bitrise-io/go-utils/command" "github.com/bitrise-io/go-utils/fileutil" "github.com/bitrise-io/go-utils/log" "github.com/bitrise-io/go-utils/pathutil" + "github.com/bitrise-io/go-utils/v2/command" ) // AndroidGradleCacheItemCollector ... diff --git a/vendor/github.com/bitrise-io/go-android/cache/gradle.go b/vendor/github.com/bitrise-io/go-android/v2/cache/gradle.go similarity index 98% rename from vendor/github.com/bitrise-io/go-android/cache/gradle.go rename to vendor/github.com/bitrise-io/go-android/v2/cache/gradle.go index 4a72392..f0c4e1a 100644 --- a/vendor/github.com/bitrise-io/go-android/cache/gradle.go +++ b/vendor/github.com/bitrise-io/go-android/v2/cache/gradle.go @@ -7,9 +7,9 @@ import ( "regexp" "strings" - "github.com/bitrise-io/go-utils/command" "github.com/bitrise-io/go-utils/errorutil" "github.com/bitrise-io/go-utils/pathutil" + "github.com/bitrise-io/go-utils/v2/command" "github.com/hashicorp/go-version" ) diff --git a/vendor/github.com/bitrise-io/go-steputils/command/gems/bundler.go b/vendor/github.com/bitrise-io/go-steputils/command/gems/bundler.go new file mode 100644 index 0000000..0763041 --- /dev/null +++ b/vendor/github.com/bitrise-io/go-steputils/command/gems/bundler.go @@ -0,0 +1,48 @@ +package gems + +import ( + "fmt" + "os/exec" + + "github.com/bitrise-io/go-steputils/command/rubycommand" + "github.com/bitrise-io/go-utils/command" +) + +// InstallBundlerCommand returns a command to install a specific bundler version +func InstallBundlerCommand(gemfileLockVersion Version) *command.Model { + args := []string{"install", "bundler", "--force", "--no-document"} + if gemfileLockVersion.Found { + args = append(args, []string{"--version", gemfileLockVersion.Version}...) + } + + return command.New("gem", args...) +} + +// BundleInstallCommand returns a command to install a bundle using bundler +func BundleInstallCommand(gemfileLockVersion Version) (*command.Model, error) { + var args []string + if gemfileLockVersion.Found { + args = append(args, "_"+gemfileLockVersion.Version+"_") + } + args = append(args, []string{"install", "--jobs", "20", "--retry", "5"}...) + + return rubycommand.New("bundle", args...) +} + +// BundleExecPrefix returns a slice containing: "bundle [_verson_] exec" +func BundleExecPrefix(bundlerVersion Version) []string { + bundleExec := []string{"bundle"} + if bundlerVersion.Found { + bundleExec = append(bundleExec, fmt.Sprintf("_%s_", bundlerVersion.Version)) + } + return append(bundleExec, "exec") +} + +// RbenvVersionsCommand retruns a command to print used and available ruby versions if rbenv is installed +func RbenvVersionsCommand() *command.Model { + if _, err := exec.LookPath("rbenv"); err != nil { + return nil + } + + return command.New("rbenv", "versions") +} diff --git a/vendor/github.com/bitrise-io/go-steputils/command/rubycommand/rubycommand.go b/vendor/github.com/bitrise-io/go-steputils/command/rubycommand/rubycommand.go new file mode 100644 index 0000000..554497f --- /dev/null +++ b/vendor/github.com/bitrise-io/go-steputils/command/rubycommand/rubycommand.go @@ -0,0 +1,276 @@ +package rubycommand + +import ( + "bufio" + "bytes" + "errors" + "fmt" + "regexp" + "strings" + + "github.com/bitrise-io/go-utils/command" + "github.com/bitrise-io/go-utils/log" + "github.com/bitrise-io/go-utils/pathutil" +) + +const ( + systemRubyPth = "/usr/bin/ruby" + brewRubyPth = "/usr/local/bin/ruby" + brewRubyPthAlt = "/usr/local/opt/ruby/bin/ruby" +) + +// InstallType ... +type InstallType int8 + +const ( + // Unkown ... + Unkown InstallType = iota + // SystemRuby ... + SystemRuby + // BrewRuby ... + BrewRuby + // RVMRuby ... + RVMRuby + // RbenvRuby ... + RbenvRuby +) + +func cmdExist(slice ...string) bool { + if len(slice) == 0 { + return false + } + + cmd, err := command.NewWithParams(slice...) + if err != nil { + return false + } + + return (cmd.Run() == nil) +} + +// RubyInstallType returns which version manager was used for the ruby install +func RubyInstallType() InstallType { + whichRuby, err := command.New("which", "ruby").RunAndReturnTrimmedCombinedOutput() + if err != nil { + return Unkown + } + + installType := Unkown + if whichRuby == systemRubyPth { + installType = SystemRuby + } else if whichRuby == brewRubyPth { + installType = BrewRuby + } else if whichRuby == brewRubyPthAlt { + installType = BrewRuby + } else if cmdExist("rvm", "-v") { + installType = RVMRuby + } else if cmdExist("rbenv", "-v") { + installType = RbenvRuby + } + + return installType +} + +func sudoNeeded(installType InstallType, slice ...string) bool { + if installType != SystemRuby { + return false + } + + if len(slice) < 2 { + return false + } + + name := slice[0] + if name == "bundle" { + command := slice[1] + /* + bundle command can contain version: + `bundle _2.0.1_ install` + */ + const bundleVersionMarker = "_" + if strings.HasPrefix(slice[1], bundleVersionMarker) && strings.HasSuffix(slice[1], bundleVersionMarker) { + if len(slice) < 3 { + return false + } + command = slice[2] + } + + return (command == "install" || command == "update") + } else if name == "gem" { + command := slice[1] + return (command == "install" || command == "uninstall") + } + + return false +} + +// NewWithParams ... +func NewWithParams(params ...string) (*command.Model, error) { + rubyInstallType := RubyInstallType() + if rubyInstallType == Unkown { + return nil, errors.New("unknown ruby installation type") + } + + if sudoNeeded(rubyInstallType, params...) { + params = append([]string{"sudo"}, params...) + } + + return command.NewWithParams(params...) +} + +// NewFromSlice ... +func NewFromSlice(slice []string) (*command.Model, error) { + return NewWithParams(slice...) +} + +// New ... +func New(name string, args ...string) (*command.Model, error) { + slice := append([]string{name}, args...) + return NewWithParams(slice...) +} + +// GemUpdate ... +func GemUpdate(gem string) ([]*command.Model, error) { + cmds := []*command.Model{} + + cmd, err := New("gem", "update", gem, "--no-document") + if err != nil { + return []*command.Model{}, err + } + + cmds = append(cmds, cmd) + + rubyInstallType := RubyInstallType() + if rubyInstallType == RbenvRuby { + cmd, err := New("rbenv", "rehash") + if err != nil { + return []*command.Model{}, err + } + + cmds = append(cmds, cmd) + } + + return cmds, nil +} + +func gemInstallCommand(gem, version string, enablePrerelease bool) []string { + slice := []string{"gem", "install", gem, "--no-document"} + if enablePrerelease { + slice = append(slice, "--prerelease") + } + if version != "" { + slice = append(slice, "-v", version) + } + + return slice +} + +// GemInstall ... +func GemInstall(gem, version string, enablePrerelease bool) ([]*command.Model, error) { + cmd, err := NewFromSlice(gemInstallCommand(gem, version, enablePrerelease)) + if err != nil { + return []*command.Model{}, err + } + + cmds := []*command.Model{cmd} + + rubyInstallType := RubyInstallType() + if rubyInstallType == RbenvRuby { + cmd, err := New("rbenv", "rehash") + if err != nil { + return []*command.Model{}, err + } + + cmds = append(cmds, cmd) + } + + return cmds, nil +} + +func findGemInList(gemList, gem, version string) (bool, error) { + // minitest (5.10.1, 5.9.1, 5.9.0, 5.8.3, 4.7.5) + pattern := fmt.Sprintf(`^%s \(.*%s.*\)`, gem, version) + re := regexp.MustCompile(pattern) + + reader := bytes.NewReader([]byte(gemList)) + scanner := bufio.NewScanner(reader) + for scanner.Scan() { + line := scanner.Text() + match := re.FindString(line) + if match != "" { + return true, nil + } + } + if err := scanner.Err(); err != nil { + return false, err + } + return false, nil +} + +// IsGemInstalled ... +func IsGemInstalled(gem, version string) (bool, error) { + cmd, err := New("gem", "list") + if err != nil { + return false, err + } + + out, err := cmd.RunAndReturnTrimmedCombinedOutput() + if err != nil { + return false, fmt.Errorf("%s: error: %s", out, err) + } + + return findGemInList(out, gem, version) +} + +func isSpecifiedRbenvRubyInstalled(message string) (bool, string, error) { + // + // Not installed + reg, err := regexp.Compile("rbenv: version \x60.*' is not installed") // \x60 == ` (The go linter suggested to use the hex code instead) + if err != nil { + return false, "", fmt.Errorf("failed to parse regex ( %s ) on the error message, error: %s", "rbenv: version \x60.*' is not installed", err) // \x60 == ` (The go linter suggested to use the hex code instead) + } + + var version string + if reg.MatchString(message) { + message := reg.FindString(message) + version = strings.Split(strings.Split(message, "`")[1], "'")[0] + return false, version, nil + } + + // + // Installed + reg, err = regexp.Compile(".* \\(set by") + if err != nil { + return false, "", fmt.Errorf("failed to parse regex ( %s ) on the error message, error: %s", ".* \\(set by", err) + } + + if reg.MatchString(message) { + s := reg.FindString(message) + version = strings.Split(s, " (set by")[0] + return true, version, nil + } + return false, version, nil +} + +// IsSpecifiedRbenvRubyInstalled checks if the selected ruby version is installed via rbenv. +// Ruby version is set by +// 1. The RBENV_VERSION environment variable +// 2. The first .ruby-version file found by searching the directory of the script you are executing and each of its +// parent directories until reaching the root of your filesystem. +// 3.The first .ruby-version file found by searching the current working directory and each of its parent directories +// until reaching the root of your filesystem. +// 4. The global ~/.rbenv/version file. You can modify this file using the rbenv global command. +// src: https://github.com/rbenv/rbenv#choosing-the-ruby-version +func IsSpecifiedRbenvRubyInstalled(workdir string) (bool, string, error) { + absWorkdir, err := pathutil.AbsPath(workdir) + if err != nil { + return false, "", fmt.Errorf("failed to get absolute path for ( %s ), error: %s", workdir, err) + } + + cmd := command.New("rbenv", "version").SetDir(absWorkdir) + out, err := cmd.RunAndReturnTrimmedCombinedOutput() + if err != nil { + log.Warnf("failed to check installed ruby version, %s error: %s", out, err) + } + return isSpecifiedRbenvRubyInstalled(out) +} diff --git a/vendor/github.com/bitrise-io/go-steputils/input/fileprovider.go b/vendor/github.com/bitrise-io/go-steputils/input/fileprovider.go index b8528e6..fd42c05 100644 --- a/vendor/github.com/bitrise-io/go-steputils/input/fileprovider.go +++ b/vendor/github.com/bitrise-io/go-steputils/input/fileprovider.go @@ -16,6 +16,8 @@ const ( // FileDownloader .. type FileDownloader interface { Get(destination, source string) error + GetRemoteContents(source string) ([]byte, error) + ReadLocalFile(path string) ([]byte, error) } // FileProvider supports retrieving the local path to a file either provided @@ -34,23 +36,25 @@ func NewFileProvider(filedownloader FileDownloader) FileProvider { // LocalPath ... func (fileProvider FileProvider) LocalPath(path string) (string, error) { + if strings.HasPrefix(path, fileSchema) { // Local file + return fileProvider.trimmedFilePath(path) + } - var localPath string - if strings.HasPrefix(path, fileSchema) { - trimmedPath, err := fileProvider.trimmedFilePath(path) - if err != nil { - return "", err - } - localPath = trimmedPath - } else { - downloadedPath, err := fileProvider.downloadFile(path) + return fileProvider.downloadFileToLocalPath(path) +} + +// Contents returns the contents of remote or local URL +func (fileProvider FileProvider) Contents(srcPath string) ([]byte, error) { + if strings.HasPrefix(srcPath, fileSchema) { // Local file + trimmedPath, err := fileProvider.trimmedFilePath(srcPath) if err != nil { - return "", err + return nil, err } - localPath = downloadedPath + + return fileProvider.filedownloader.ReadLocalFile(trimmedPath) } - return localPath, nil + return fileProvider.filedownloader.GetRemoteContents(srcPath) } // Removes file:// from the begining of the path @@ -59,7 +63,7 @@ func (fileProvider FileProvider) trimmedFilePath(path string) (string, error) { return pathutil.AbsPath(pth) } -func (fileProvider FileProvider) downloadFile(url string) (string, error) { +func (fileProvider FileProvider) downloadFileToLocalPath(url string) (string, error) { tmpDir, err := pathutil.NormalizedOSTempDirPath("FileProviderprovider") if err != nil { return "", err diff --git a/vendor/github.com/bitrise-io/go-steputils/stepconf/errors.go b/vendor/github.com/bitrise-io/go-steputils/stepconf/errors.go deleted file mode 100644 index 52b6d0b..0000000 --- a/vendor/github.com/bitrise-io/go-steputils/stepconf/errors.go +++ /dev/null @@ -1,26 +0,0 @@ -package stepconf - -import ( - "errors" - "strings" -) - -// ErrNotStructPtr indicates a type is not a pointer to a struct. -var ErrNotStructPtr = errors.New("must be a pointer to a struct") - -// ParseError occurs when a struct field cannot be set. -type ParseError struct { - Field string - Value string - Err error -} - -// Error implements builtin errors.Error. -func (e *ParseError) Error() string { - segments := []string{e.Field} - if e.Value != "" { - segments = append(segments, e.Value) - } - segments = append(segments, e.Err.Error()) - return strings.Join(segments, ": ") -} diff --git a/vendor/github.com/bitrise-io/go-steputils/stepconf/secret.go b/vendor/github.com/bitrise-io/go-steputils/stepconf/secret.go deleted file mode 100644 index f9140ce..0000000 --- a/vendor/github.com/bitrise-io/go-steputils/stepconf/secret.go +++ /dev/null @@ -1,15 +0,0 @@ -package stepconf - -// Secret variables are not shown in the printed output. -type Secret string - -const secret = "*****" - -// String implements fmt.Stringer.String. -// When a Secret is printed, it's masking the underlying string with asterisks. -func (s Secret) String() string { - if s == "" { - return "" - } - return secret -} diff --git a/vendor/github.com/bitrise-io/go-steputils/stepconf/stepconf.go b/vendor/github.com/bitrise-io/go-steputils/stepconf/stepconf.go index 932bf80..b978740 100644 --- a/vendor/github.com/bitrise-io/go-steputils/stepconf/stepconf.go +++ b/vendor/github.com/bitrise-io/go-steputils/stepconf/stepconf.go @@ -9,22 +9,144 @@ import ( "strconv" "strings" - "github.com/bitrise-io/go-utils/env" + "github.com/bitrise-io/go-utils/colorstring" "github.com/bitrise-io/go-utils/parseutil" ) -const ( - rangeMinimumGroupName = "min" - rangeMaximumGroupName = "max" - rangeMinBracketGroupName = "minbr" - rangeMaxBracketGroupName = "maxbr" - rangeRegex = `range(?P<` + rangeMinBracketGroupName + `>\[|\])(?P<` + rangeMinimumGroupName + `>.*?)\.\.(?P<` + rangeMaximumGroupName + `>.*?)(?P<` + rangeMaxBracketGroupName + `>\[|\])` - multilineConstraintName = "multiline" -) +// ErrNotStructPtr indicates a type is not a pointer to a struct. +var ErrNotStructPtr = errors.New("must be a pointer to a struct") -// parse populates a struct with the retrieved values from environment variables -// described by struct tags and applies the defined validations. -func parse(conf interface{}, envRepository env.Repository) error { +// ParseError occurs when a struct field cannot be set. +type ParseError struct { + Field string + Value string + Err error +} + +const rangeMinimumGroupName = "min" +const rangeMaximumGroupName = "max" +const rangeMinBracketGroupName = "minbr" +const rangeMaxBracketGroupName = "maxbr" +const rangeRegex = `range(?P<` + rangeMinBracketGroupName + `>\[|\])(?P<` + rangeMinimumGroupName + `>.*?)\.\.(?P<` + rangeMaximumGroupName + `>.*?)(?P<` + rangeMaxBracketGroupName + `>\[|\])` +const multilineConstraintName = "multiline" + +// Error implements builtin errors.Error. +func (e *ParseError) Error() string { + segments := []string{e.Field} + if e.Value != "" { + segments = append(segments, e.Value) + } + segments = append(segments, e.Err.Error()) + return strings.Join(segments, ": ") +} + +// Secret variables are not shown in the printed output. +type Secret string + +const secret = "*****" + +// String implements fmt.Stringer.String. +// When a Secret is printed, it's masking the underlying string with asterisks. +func (s Secret) String() string { + if s == "" { + return "" + } + return secret +} + +// Print the name of the struct with Title case in blue color with followed by a newline, +// then print all fields formatted as '- field name: field value` separated by newline. +func Print(config interface{}) { + fmt.Print(toString(config)) +} + +func valueString(v reflect.Value) string { + if v.Kind() != reflect.Ptr { + if v.Kind() == reflect.String && v.Len() == 0 { + return fmt.Sprintf("") + } + return fmt.Sprintf("%v", v.Interface()) + } + + if !v.IsNil() { + return fmt.Sprintf("%v", v.Elem().Interface()) + } + + return "" +} + +// returns the name of the struct with Title case in blue color followed by a newline, +// then print all fields formatted as '- field name: field value` separated by newline. +func toString(config interface{}) string { + v := reflect.ValueOf(config) + t := reflect.TypeOf(config) + + if v.Kind() == reflect.Ptr { + v = v.Elem() + } + + if t.Kind() == reflect.Ptr { + t = t.Elem() + } + + str := fmt.Sprint(colorstring.Bluef("%s:\n", strings.Title(t.Name()))) + for i := 0; i < t.NumField(); i++ { + field := t.Field(i) + var key, _ = parseTag(field.Tag.Get("env")) + if key == "" { + key = field.Name + } + str += fmt.Sprintf("- %s: %s\n", key, valueString(v.Field(i))) + } + + return str +} + +// parseTag splits a struct field's env tag into its name and option. +func parseTag(tag string) (string, string) { + if idx := strings.Index(tag, ","); idx != -1 { + return tag[:idx], tag[idx+1:] + } + return tag, "" +} + +// EnvProvider ... +type EnvProvider interface { + Getenv(key string) string +} + +// OSEnvProvider ... +type OSEnvProvider struct{} + +// NewOSEnvProvider ... +func NewOSEnvProvider() EnvProvider { + return OSEnvProvider{} +} + +// Getenv ... +func (p OSEnvProvider) Getenv(key string) string { + return os.Getenv(key) +} + +// EnvParser ... +type EnvParser struct { + envProvider EnvProvider +} + +// NewDefaultEnvParser ... +func NewDefaultEnvParser() EnvParser { + return NewEnvParser(NewOSEnvProvider()) +} + +// NewEnvParser ... +func NewEnvParser(envProvider EnvProvider) EnvParser { + return EnvParser{ + envProvider: envProvider, + } +} + +// Parse ... +func (p EnvParser) Parse(conf interface{}) error { c := reflect.ValueOf(conf) if c.Kind() != reflect.Ptr { return ErrNotStructPtr @@ -42,7 +164,7 @@ func parse(conf interface{}, envRepository env.Repository) error { continue } key, constraint := parseTag(tag) - value := envRepository.Get(key) + value := p.envProvider.Getenv(key) if err := setField(c.Field(i), value, constraint); err != nil { errs = append(errs, &ParseError{t.Field(i).Name, value, err}) @@ -61,12 +183,20 @@ func parse(conf interface{}, envRepository env.Repository) error { return nil } -// parseTag splits a struct field's env tag into its name and option. -func parseTag(tag string) (string, string) { - if idx := strings.Index(tag, ","); idx != -1 { - return tag[:idx], tag[idx+1:] +var defaultEnvParser *EnvParser + +func getDefaultEnvParser() EnvParser { + if defaultEnvParser == nil { + parser := NewDefaultEnvParser() + defaultEnvParser = &parser } - return tag, "" + return *defaultEnvParser +} + +// Parse populates a struct with the retrieved values from environment variables +// described by struct tags and applies the defined validations. +func Parse(conf interface{}) error { + return getDefaultEnvParser().Parse(conf) } func setField(field reflect.Value, value, constraint string) error { @@ -139,7 +269,7 @@ func validateConstraint(value, constraint string) error { return fmt.Errorf("value is not in value options (%s)", constraint) } case regexp.MustCompile(rangeRegex).FindString(constraint): - if err := validateRangeFields(value, constraint); err != nil { + if err := ValidateRangeFields(value, constraint); err != nil { return err } case multilineConstraintName: @@ -150,12 +280,12 @@ func validateConstraint(value, constraint string) error { return nil } -// validateRangeFields validates if the given range is proper. Ranges are optional, empty values are valid. -func validateRangeFields(valueStr, constraint string) error { +// ValidateRangeFields validates if the given range is proper. Ranges are optional, empty values are valid. +func ValidateRangeFields(valueStr, constraint string) error { if valueStr == "" { return nil } - constraintMin, constraintMax, constraintMinBr, constraintMaxBr, err := getRangeValues(constraint) + constraintMin, constraintMax, constraintMinBr, constraintMaxBr, err := GetRangeValues(constraint) if err != nil { return err } @@ -375,8 +505,8 @@ func validateRangeMaxFieldValue(max float64, value float64, inclusive bool) erro return nil } -// getRangeValues reads up the given range constraint and returns the values, or an error if the constraint is malformed or could not be parsed. -func getRangeValues(value string) (min string, max string, minBracket string, maxBracket string, err error) { +// GetRangeValues reads up the given range constraint and returns the values, or an error if the constraint is malformed or could not be parsed. +func GetRangeValues(value string) (min string, max string, minBracket string, maxBracket string, err error) { regex := regexp.MustCompile(rangeRegex) groups := regex.FindStringSubmatch(value) if len(groups) < 1 { diff --git a/vendor/github.com/bitrise-io/go-steputils/stepconf/stepinput.go b/vendor/github.com/bitrise-io/go-steputils/stepconf/stepinput.go deleted file mode 100644 index d4b57c1..0000000 --- a/vendor/github.com/bitrise-io/go-steputils/stepconf/stepinput.go +++ /dev/null @@ -1,24 +0,0 @@ -package stepconf - -import "github.com/bitrise-io/go-utils/env" - -// InputParser ... -type InputParser interface { - Parse(input interface{}) error -} - -type defaultInputParser struct { - envRepository env.Repository -} - -// NewInputParser ... -func NewInputParser(envRepository env.Repository) InputParser { - return defaultInputParser{ - envRepository: envRepository, - } -} - -// Parse ... -func (p defaultInputParser) Parse(input interface{}) error { - return parse(input, p.envRepository) -} diff --git a/vendor/github.com/bitrise-io/go-steputils/stepconf/strings.go b/vendor/github.com/bitrise-io/go-steputils/stepconf/strings.go deleted file mode 100644 index 365e50c..0000000 --- a/vendor/github.com/bitrise-io/go-steputils/stepconf/strings.go +++ /dev/null @@ -1,49 +0,0 @@ -package stepconf - -import ( - "fmt" - "reflect" - "strings" - - "github.com/bitrise-io/go-utils/colorstring" -) - -// Print the name of the struct with Title case in blue color with followed by a newline, -// then print all fields formatted as '- field name: field value` separated by newline. -func Print(config interface{}) { - fmt.Print(toString(config)) -} - -func valueString(v reflect.Value) string { - if v.Kind() != reflect.Ptr { - return fmt.Sprintf("%v", v.Interface()) - } - - if !v.IsNil() { - return fmt.Sprintf("%v", v.Elem().Interface()) - } - - return "" -} - -// returns the name of the struct with Title case in blue color followed by a newline, -// then print all fields formatted as '- field name: field value` separated by newline. -func toString(config interface{}) string { - v := reflect.ValueOf(config) - t := reflect.TypeOf(config) - - if v.Kind() == reflect.Ptr { - v = v.Elem() - } - - if t.Kind() == reflect.Ptr { - t = t.Elem() - } - - str := fmt.Sprint(colorstring.Bluef("%s:\n", strings.Title(t.Name()))) - for i := 0; i < t.NumField(); i++ { - str += fmt.Sprintf("- %s: %s\n", t.Field(i).Name, valueString(v.Field(i))) - } - - return str -} diff --git a/vendor/github.com/bitrise-io/go-steputils/tools/tools.go b/vendor/github.com/bitrise-io/go-steputils/tools/tools.go index f665afa..3372b16 100644 --- a/vendor/github.com/bitrise-io/go-steputils/tools/tools.go +++ b/vendor/github.com/bitrise-io/go-steputils/tools/tools.go @@ -1,16 +1,14 @@ package tools import ( - "github.com/bitrise-io/go-utils/command" - "github.com/bitrise-io/go-utils/env" "strings" -) -// TODO remove -var temporaryFactory = command.NewFactory(env.NewRepository()) + "github.com/bitrise-io/go-utils/command" +) // ExportEnvironmentWithEnvman ... func ExportEnvironmentWithEnvman(key, value string) error { - cmd := temporaryFactory.Create("envman", []string{"add", "--key", key}, &command.Opts{Stdin: strings.NewReader(value)}) + cmd := command.New("envman", "add", "--key", key) + cmd.SetStdin(strings.NewReader(value)) return cmd.Run() } diff --git a/vendor/github.com/bitrise-io/go-steputils/ruby/command.go b/vendor/github.com/bitrise-io/go-steputils/v2/ruby/command.go similarity index 91% rename from vendor/github.com/bitrise-io/go-steputils/ruby/command.go rename to vendor/github.com/bitrise-io/go-steputils/v2/ruby/command.go index b7c7e15..fea48b9 100644 --- a/vendor/github.com/bitrise-io/go-steputils/ruby/command.go +++ b/vendor/github.com/bitrise-io/go-steputils/v2/ruby/command.go @@ -4,8 +4,8 @@ import ( "errors" "strings" - "github.com/bitrise-io/go-utils/command" - "github.com/bitrise-io/go-utils/env" + "github.com/bitrise-io/go-utils/v2/command" + "github.com/bitrise-io/go-utils/v2/env" ) // CommandFactory ... @@ -64,6 +64,9 @@ func (f commandFactory) CreateGemInstall(gem, version string, enablePrerelease, if f.installType == RbenvRuby { cmd := f.Create("rbenv", []string{"rehash"}, nil) cmds = append(cmds, cmd) + } else if f.installType == ASDFRuby { + cmd := f.Create("asdf", []string{"reshim", "ruby"}, nil) + cmds = append(cmds, cmd) } return cmds @@ -77,6 +80,9 @@ func (f commandFactory) CreateGemUpdate(gem string, opts *command.Opts) []comman if f.installType == RbenvRuby { cmd := f.Create("rbenv", []string{"rehash"}, nil) cmds = append(cmds, cmd) + } else if f.installType == ASDFRuby { + cmd := f.Create("asdf", []string{"reshim", "ruby"}, nil) + cmds = append(cmds, cmd) } return cmds diff --git a/vendor/github.com/bitrise-io/go-steputils/ruby/environment.go b/vendor/github.com/bitrise-io/go-steputils/v2/ruby/environment.go similarity index 64% rename from vendor/github.com/bitrise-io/go-steputils/ruby/environment.go rename to vendor/github.com/bitrise-io/go-steputils/v2/ruby/environment.go index b376372..fe1f5b7 100644 --- a/vendor/github.com/bitrise-io/go-steputils/ruby/environment.go +++ b/vendor/github.com/bitrise-io/go-steputils/v2/ruby/environment.go @@ -7,9 +7,10 @@ import ( "regexp" "strings" - "github.com/bitrise-io/go-utils/command" - "github.com/bitrise-io/go-utils/env" "github.com/bitrise-io/go-utils/pathutil" + "github.com/bitrise-io/go-utils/v2/command" + "github.com/bitrise-io/go-utils/v2/env" + "github.com/bitrise-io/go-utils/v2/log" ) const ( @@ -32,6 +33,8 @@ const ( RVMRuby // RbenvRuby ... RbenvRuby + // ASDFRuby ... + ASDFRuby ) // Environment ... @@ -39,18 +42,21 @@ type Environment interface { RubyInstallType() InstallType IsGemInstalled(gem, version string) (bool, error) IsSpecifiedRbenvRubyInstalled(workdir string) (bool, string, error) + IsSpecifiedASDFRubyInstalled(workdir string) (bool, string, error) } type environment struct { factory CommandFactory cmdLocator env.CommandLocator + logger log.Logger } // NewEnvironment ... -func NewEnvironment(factory CommandFactory, cmdLocator env.CommandLocator) Environment { +func NewEnvironment(factory CommandFactory, cmdLocator env.CommandLocator, logger log.Logger) Environment { return environment{ factory: factory, cmdLocator: cmdLocator, + logger: logger, } } @@ -59,6 +65,35 @@ func (m environment) RubyInstallType() InstallType { return rubyInstallType(m.cmdLocator) } +func rubyInstallType(cmdLocator env.CommandLocator) InstallType { + pth, err := cmdLocator.LookPath("ruby") + if err != nil { + return Unknown + } + + installType := Unknown + if pth == systemRubyPth { + installType = SystemRuby + } else if pth == brewRubyPth { + installType = BrewRuby + } else if pth == brewRubyPthAlt { + installType = BrewRuby + } else if _, err := cmdLocator.LookPath("rvm"); err == nil { + installType = RVMRuby + } else if _, err := cmdLocator.LookPath("rbenv"); err == nil { + installType = RbenvRuby + } else if _, err := cmdLocator.LookPath("asdf"); err == nil { + // asdf doesn't store its installs in a definite location, + // but it does store its shims in a 'shims' directory, which + // is what we'll get from the `LookPath("ruby")` call above. + if strings.Contains(pth, "shims/ruby") { + installType = ASDFRuby + } + } + + return installType +} + func (m environment) IsGemInstalled(gem, version string) (bool, error) { cmd := m.factory.Create("gem", []string{"list"}, nil) @@ -88,39 +123,18 @@ func (m environment) IsSpecifiedRbenvRubyInstalled(workdir string) (bool, string cmd := m.factory.Create("rbenv", []string{"version"}, &command.Opts{Dir: absWorkdir}) out, err := cmd.RunAndReturnTrimmedCombinedOutput() if err != nil { - return false, "", fmt.Errorf("failed to check installed ruby version, %s error: %s", out, err) + m.logger.Warnf("failed to check installed ruby version, %s error: %s", out, err) } return isSpecifiedRbenvRubyInstalled(out) } -func rubyInstallType(cmdLocator env.CommandLocator) InstallType { - pth, err := cmdLocator.LookPath("ruby") - if err != nil { - return Unknown - } - - installType := Unknown - if pth == systemRubyPth { - installType = SystemRuby - } else if pth == brewRubyPth { - installType = BrewRuby - } else if pth == brewRubyPthAlt { - installType = BrewRuby - } else if _, err := cmdLocator.LookPath("rvm"); err == nil { - installType = RVMRuby - } else if _, err := cmdLocator.LookPath("rbenv"); err == nil { - installType = RbenvRuby - } - - return installType -} - func isSpecifiedRbenvRubyInstalled(message string) (bool, string, error) { // // Not installed - reg, err := regexp.Compile("rbenv: version \x60.*' is not installed") // \x60 == ` (The go linter suggested to use the hex code instead) + regexPattern := "rbenv: version \x60.*' is not installed" // \x60 == ` (The go linter suggested to use the hex code instead) + reg, err := regexp.Compile(regexPattern) if err != nil { - return false, "", fmt.Errorf("failed to parse regex ( %s ) on the error message, error: %s", "rbenv: version \x60.*' is not installed", err) // \x60 == ` (The go linter suggested to use the hex code instead) + return false, "", fmt.Errorf("failed to parse regex ( %s ) on the error message, error: %s", regexPattern, err) } var version string @@ -145,6 +159,46 @@ func isSpecifiedRbenvRubyInstalled(message string) (bool, string, error) { return false, version, nil } +func (m environment) IsSpecifiedASDFRubyInstalled(workdir string) (isInstalled bool, versionInstalled string, error error) { + absWorkdir, err := pathutil.AbsPath(workdir) + if err != nil { + return false, "", fmt.Errorf("failed to get absolute path for ( %s ), error: %s", workdir, err) + } + + cmd := m.factory.Create("asdf", []string{"current", "ruby"}, &command.Opts{Dir: absWorkdir}) + out, err := cmd.RunAndReturnTrimmedCombinedOutput() + if err != nil { + m.logger.Warnf("failed to check installed ruby version, %s error: %s", out, err) + } + + return isSpecifiedASDFRubyInstalled(out) +} + +func isSpecifiedASDFRubyInstalled(message string) (isInstalled bool, versionInstalled string, error error) { + regexPattern := "Not installed. Run \"asdf install ruby .*\"" + reg, err := regexp.Compile(regexPattern) + if err != nil { + return false, "", fmt.Errorf("failed to parse regex ( %s ) on the error message, error: %s", regexPattern, err) + } + + var version string + if reg.MatchString(message) { + // + // Not installed + version = strings.Split(strings.Split(message, "\"asdf install ruby ")[1], "\"")[0] + return false, version, nil + } + // + // Installed + patternTerminator := "/" + if strings.Contains(message, "ASDF_RUBY_VERSION") { + patternTerminator = "ASDF_RUBY_VERSION" + } + version = strings.Split(strings.Split(message, "ruby ")[1], patternTerminator)[0] + version = strings.TrimSpace(version) + return true, version, nil +} + func findGemInList(gemList, gem, version string) (bool, error) { // minitest (5.10.1, 5.9.1, 5.9.0, 5.8.3, 4.7.5) pattern := fmt.Sprintf(`^%s \(.*%s.*\)`, gem, version) diff --git a/vendor/github.com/bitrise-io/go-utils/command/command.go b/vendor/github.com/bitrise-io/go-utils/command/command.go index 0ef8af3..c068490 100644 --- a/vendor/github.com/bitrise-io/go-utils/command/command.go +++ b/vendor/github.com/bitrise-io/go-utils/command/command.go @@ -1,113 +1,129 @@ package command import ( + "errors" "io" + "os" "os/exec" "strconv" "strings" - - "github.com/bitrise-io/go-utils/env" ) -// Opts ... -type Opts struct { - Stdout io.Writer - Stderr io.Writer - Stdin io.Reader - Env []string - Dir string +// ---------- + +// Model ... +type Model struct { + cmd *exec.Cmd +} + +// New ... +func New(name string, args ...string) *Model { + return &Model{ + cmd: exec.Command(name, args...), + } } -// Factory ... -type Factory interface { - Create(name string, args []string, opts *Opts) Command +// NewWithStandardOuts - same as NewCommand, but sets the command's +// stdout and stderr to the standard (OS) out (os.Stdout) and err (os.Stderr) +func NewWithStandardOuts(name string, args ...string) *Model { + return New(name, args...).SetStdout(os.Stdout).SetStderr(os.Stderr) } -type defaultFactory struct { - envRepository env.Repository +// NewWithParams ... +func NewWithParams(params ...string) (*Model, error) { + if len(params) == 0 { + return nil, errors.New("no command provided") + } else if len(params) == 1 { + return New(params[0]), nil + } + + return New(params[0], params[1:]...), nil } -// NewFactory ... -func NewFactory(envRepository env.Repository) Factory { - return defaultFactory{envRepository: envRepository} +// NewFromSlice ... +func NewFromSlice(slice []string) (*Model, error) { + return NewWithParams(slice...) } -// Create ... -func (f defaultFactory) Create(name string, args []string, opts *Opts) Command { - cmd := exec.Command(name, args...) - if opts != nil { - cmd.Stdout = opts.Stdout - cmd.Stderr = opts.Stderr - cmd.Stdin = opts.Stdin - - // If Env is nil, the new process uses the current process's - // environment. - // If we pass env vars we want to append them to the - // current process's environment. - cmd.Env = append(f.envRepository.List(), opts.Env...) - cmd.Dir = opts.Dir +// NewWithCmd ... +func NewWithCmd(cmd *exec.Cmd) *Model { + return &Model{ + cmd: cmd, } - return defaultCommand{cmd} } -// Command ... -type Command interface { - PrintableCommandArgs() string - Run() error - RunAndReturnExitCode() (int, error) - RunAndReturnTrimmedOutput() (string, error) - RunAndReturnTrimmedCombinedOutput() (string, error) - Start() error - Wait() error +// GetCmd ... +func (m *Model) GetCmd() *exec.Cmd { + return m.cmd } -type defaultCommand struct { - cmd *exec.Cmd +// SetDir ... +func (m *Model) SetDir(dir string) *Model { + m.cmd.Dir = dir + return m } -// PrintableCommandArgs ... -func (c defaultCommand) PrintableCommandArgs() string { - return printableCommandArgs(false, c.cmd.Args) +// SetEnvs ... +func (m *Model) SetEnvs(envs ...string) *Model { + m.cmd.Env = envs + return m +} + +// AppendEnvs - appends the envs to the current os.Environ() +// Calling this multiple times will NOT appens the envs one by one, +// only the last "envs" set will be appended to os.Environ()! +func (m *Model) AppendEnvs(envs ...string) *Model { + return m.SetEnvs(append(os.Environ(), envs...)...) +} + +// SetStdin ... +func (m *Model) SetStdin(in io.Reader) *Model { + m.cmd.Stdin = in + return m +} + +// SetStdout ... +func (m *Model) SetStdout(out io.Writer) *Model { + m.cmd.Stdout = out + return m +} + +// SetStderr ... +func (m *Model) SetStderr(err io.Writer) *Model { + m.cmd.Stderr = err + return m } // Run ... -func (c defaultCommand) Run() error { - return c.cmd.Run() +func (m Model) Run() error { + return m.cmd.Run() } // RunAndReturnExitCode ... -func (c defaultCommand) RunAndReturnExitCode() (int, error) { - err := c.cmd.Run() - exitCode := c.cmd.ProcessState.ExitCode() - return exitCode, err +func (m Model) RunAndReturnExitCode() (int, error) { + return RunCmdAndReturnExitCode(m.cmd) } // RunAndReturnTrimmedOutput ... -func (c defaultCommand) RunAndReturnTrimmedOutput() (string, error) { - outBytes, err := c.cmd.Output() - outStr := string(outBytes) - return strings.TrimSpace(outStr), err +func (m Model) RunAndReturnTrimmedOutput() (string, error) { + return RunCmdAndReturnTrimmedOutput(m.cmd) } // RunAndReturnTrimmedCombinedOutput ... -func (c defaultCommand) RunAndReturnTrimmedCombinedOutput() (string, error) { - outBytes, err := c.cmd.CombinedOutput() - outStr := string(outBytes) - return strings.TrimSpace(outStr), err +func (m Model) RunAndReturnTrimmedCombinedOutput() (string, error) { + return RunCmdAndReturnTrimmedCombinedOutput(m.cmd) } -// Start ... -func (c defaultCommand) Start() error { - return c.cmd.Start() +// PrintableCommandArgs ... +func (m Model) PrintableCommandArgs() string { + return PrintableCommandArgs(false, m.cmd.Args) } -// Wait ... -func (c defaultCommand) Wait() error { - return c.cmd.Wait() -} +// ---------- -func printableCommandArgs(isQuoteFirst bool, fullCommandArgs []string) string { - var cmdArgsDecorated []string +// PrintableCommandArgs ... +func PrintableCommandArgs(isQuoteFirst bool, fullCommandArgs []string) string { + cmdArgsDecorated := []string{} for idx, anArg := range fullCommandArgs { quotedArg := strconv.Quote(anArg) if idx == 0 && !isQuoteFirst { @@ -118,3 +134,119 @@ func printableCommandArgs(isQuoteFirst bool, fullCommandArgs []string) string { return strings.Join(cmdArgsDecorated, " ") } + +// RunCmdAndReturnExitCode ... +func RunCmdAndReturnExitCode(cmd *exec.Cmd) (exitCode int, err error) { + err = cmd.Run() + exitCode = cmd.ProcessState.ExitCode() + return +} + +// RunCmdAndReturnTrimmedOutput ... +func RunCmdAndReturnTrimmedOutput(cmd *exec.Cmd) (string, error) { + outBytes, err := cmd.Output() + outStr := string(outBytes) + return strings.TrimSpace(outStr), err +} + +// RunCmdAndReturnTrimmedCombinedOutput ... +func RunCmdAndReturnTrimmedCombinedOutput(cmd *exec.Cmd) (string, error) { + outBytes, err := cmd.CombinedOutput() + outStr := string(outBytes) + return strings.TrimSpace(outStr), err +} + +// RunCommandWithReaderAndWriters ... +func RunCommandWithReaderAndWriters(inReader io.Reader, outWriter, errWriter io.Writer, name string, args ...string) error { + cmd := exec.Command(name, args...) + cmd.Stdin = inReader + cmd.Stdout = outWriter + cmd.Stderr = errWriter + return cmd.Run() +} + +// RunCommandWithWriters ... +func RunCommandWithWriters(outWriter, errWriter io.Writer, name string, args ...string) error { + cmd := exec.Command(name, args...) + cmd.Stdout = outWriter + cmd.Stderr = errWriter + return cmd.Run() +} + +// RunCommandInDirWithEnvsAndReturnExitCode ... +func RunCommandInDirWithEnvsAndReturnExitCode(envs []string, dir, name string, args ...string) (int, error) { + cmd := exec.Command(name, args...) + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + if dir != "" { + cmd.Dir = dir + } + if len(envs) > 0 { + cmd.Env = envs + } + + return RunCmdAndReturnExitCode(cmd) +} + +// RunCommandInDirAndReturnExitCode ... +func RunCommandInDirAndReturnExitCode(dir, name string, args ...string) (int, error) { + return RunCommandInDirWithEnvsAndReturnExitCode([]string{}, dir, name, args...) +} + +// RunCommandWithEnvsAndReturnExitCode ... +func RunCommandWithEnvsAndReturnExitCode(envs []string, name string, args ...string) (int, error) { + return RunCommandInDirWithEnvsAndReturnExitCode(envs, "", name, args...) +} + +// RunCommandInDir ... +func RunCommandInDir(dir, name string, args ...string) error { + cmd := exec.Command(name, args...) + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + if dir != "" { + cmd.Dir = dir + } + return cmd.Run() +} + +// RunCommand ... +func RunCommand(name string, args ...string) error { + return RunCommandInDir("", name, args...) +} + +// RunCommandAndReturnStdout .. +func RunCommandAndReturnStdout(name string, args ...string) (string, error) { + cmd := exec.Command(name, args...) + return RunCmdAndReturnTrimmedOutput(cmd) +} + +// RunCommandInDirAndReturnCombinedStdoutAndStderr ... +func RunCommandInDirAndReturnCombinedStdoutAndStderr(dir, name string, args ...string) (string, error) { + cmd := exec.Command(name, args...) + if dir != "" { + cmd.Dir = dir + } + return RunCmdAndReturnTrimmedCombinedOutput(cmd) +} + +// RunCommandAndReturnCombinedStdoutAndStderr .. +func RunCommandAndReturnCombinedStdoutAndStderr(name string, args ...string) (string, error) { + return RunCommandInDirAndReturnCombinedStdoutAndStderr("", name, args...) +} + +// RunBashCommand ... +func RunBashCommand(cmdStr string) error { + return RunCommand("bash", "-c", cmdStr) +} + +// RunBashCommandLines ... +func RunBashCommandLines(cmdLines []string) error { + for _, aLine := range cmdLines { + if err := RunCommand("bash", "-c", aLine); err != nil { + return err + } + } + return nil +} diff --git a/vendor/github.com/bitrise-io/go-utils/command/file.go b/vendor/github.com/bitrise-io/go-utils/command/file.go index be29aa1..6b22172 100644 --- a/vendor/github.com/bitrise-io/go-utils/command/file.go +++ b/vendor/github.com/bitrise-io/go-utils/command/file.go @@ -2,7 +2,6 @@ package command import ( "errors" - "github.com/bitrise-io/go-utils/env" "os" "strings" @@ -21,7 +20,7 @@ func CopyFile(src, dst string) error { return errors.New("Source is a directory: " + src) } args := []string{src, dst} - return NewFactory(env.NewRepository()).Create("rsync", args, &Opts{Stderr: os.Stderr, Stdout: os.Stdout}).Run() + return RunCommand("rsync", args...) } // CopyDir ... @@ -30,7 +29,7 @@ func CopyDir(src, dst string, isOnlyContent bool) error { src = src + "/" } args := []string{"-ar", src, dst} - return NewFactory(env.NewRepository()).Create("rsync", args, &Opts{Stderr: os.Stderr, Stdout: os.Stdout}).Run() + return RunCommand("rsync", args...) } // RemoveDir ... diff --git a/vendor/github.com/bitrise-io/go-utils/errorutil/errorutil.go b/vendor/github.com/bitrise-io/go-utils/errorutil/errorutil.go index dd5f8d2..d7d8955 100644 --- a/vendor/github.com/bitrise-io/go-utils/errorutil/errorutil.go +++ b/vendor/github.com/bitrise-io/go-utils/errorutil/errorutil.go @@ -2,12 +2,14 @@ package errorutil import ( + "errors" "os/exec" "regexp" ) func exitCode(err error) int { - if exitError, ok := err.(*exec.ExitError); ok { + var exitError *exec.ExitError + if errors.As(err, &exitError) { return exitError.ProcessState.ExitCode() } return -1 @@ -22,7 +24,7 @@ func IsExitStatusError(err error) bool { func IsExitStatusErrorStr(errString string) bool { // https://golang.org/src/os/exec_posix.go?s=2421:2459#L87 // example exit status error string: exit status 1 - var rex = regexp.MustCompile(`^exit status [0-9]{1,3}$`) + var rex = regexp.MustCompile(`^exit status \d{1,3}$`) return rex.MatchString(errString) } diff --git a/vendor/github.com/bitrise-io/go-utils/filedownloader/filedownloader.go b/vendor/github.com/bitrise-io/go-utils/filedownloader/filedownloader.go index ef8f3fd..30a3905 100644 --- a/vendor/github.com/bitrise-io/go-utils/filedownloader/filedownloader.go +++ b/vendor/github.com/bitrise-io/go-utils/filedownloader/filedownloader.go @@ -1,6 +1,8 @@ package filedownloader import ( + "bytes" + "context" "fmt" "io" "net/http" @@ -11,22 +13,33 @@ import ( // HTTPClient ... type HTTPClient interface { - Get(source string) (*http.Response, error) + Do(req *http.Request) (*http.Response, error) } -// HTTPFileDownloader ... -type HTTPFileDownloader struct { - client HTTPClient +// FileDownloader ... +type FileDownloader struct { + client HTTPClient + context context.Context } // New ... -func New(client HTTPClient) HTTPFileDownloader { - return HTTPFileDownloader{client} +func New(client HTTPClient) FileDownloader { + return FileDownloader{ + client: client, + } +} + +// NewWithContext ... +func NewWithContext(context context.Context, client HTTPClient) FileDownloader { + return FileDownloader{ + client: client, + context: context, + } } // GetWithFallback downloads a file from a given source. Provided destination should be a file that does not exist. // You can specify fallback sources which will be used in order if downloading fails from either source. -func (downloader HTTPFileDownloader) GetWithFallback(destination, source string, fallbackSources ...string) error { +func (downloader FileDownloader) GetWithFallback(destination, source string, fallbackSources ...string) error { sources := append([]string{source}, fallbackSources...) for _, source := range sources { err := downloader.Get(destination, source) @@ -37,39 +50,69 @@ func (downloader HTTPFileDownloader) GetWithFallback(destination, source string, return nil } } + return fmt.Errorf("None of the sources returned 200 OK status") } // Get downloads a file from a given source. Provided destination should be a file that does not exist. -func (downloader HTTPFileDownloader) Get(destination, source string) error { - - resp, err := downloader.client.Get(source) +func (downloader FileDownloader) Get(destination, source string) error { + f, err := os.Create(destination) if err != nil { return err } - if resp.StatusCode != http.StatusOK { - return fmt.Errorf("unable to download file from: %s. Status code: %d", source, resp.StatusCode) - } - defer func() { - if err := resp.Body.Close(); err != nil { - log.Errorf("Failed to close body, error: %s", err) + if err := f.Close(); err != nil { + log.Errorf("Failed to close file, error: %s", err) } }() - f, err := os.Create(destination) + return download(downloader.context, downloader.client, source, f) +} + +// GetRemoteContents fetches a remote URL contents +func (downloader FileDownloader) GetRemoteContents(URL string) ([]byte, error) { + var buffer bytes.Buffer + if err := download(downloader.context, downloader.client, URL, &buffer); err != nil { + return nil, err + } + + return buffer.Bytes(), nil +} + +// ReadLocalFile returns a local file contents +func (downloader FileDownloader) ReadLocalFile(path string) ([]byte, error) { + return os.ReadFile(path) +} + +func download(context context.Context, client HTTPClient, source string, destination io.Writer) error { + req, err := http.NewRequest(http.MethodGet, source, nil) + if err != nil { + return fmt.Errorf("failed to create request: %s", err) + } + + if context != nil { + req = req.WithContext(context) + } + + resp, err := client.Do(req) if err != nil { return err } defer func() { - if err := f.Close(); err != nil { - log.Errorf("Failed to close file, error: %s", err) + if resp.Body != nil { + if err := resp.Body.Close(); err != nil { + log.Errorf("Failed to close body, error: %s", err) + } } }() - if _, err = io.Copy(f, resp.Body); err != nil { + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("unable to download file from: %s. Status code: %d", source, resp.StatusCode) + } + + if _, err = io.Copy(destination, resp.Body); err != nil { return err } diff --git a/vendor/github.com/bitrise-io/go-utils/fileutil/fileutil.go b/vendor/github.com/bitrise-io/go-utils/fileutil/fileutil.go index 3633e28..80c913b 100644 --- a/vendor/github.com/bitrise-io/go-utils/fileutil/fileutil.go +++ b/vendor/github.com/bitrise-io/go-utils/fileutil/fileutil.go @@ -7,56 +7,10 @@ import ( "io/ioutil" "log" "os" - "path/filepath" "github.com/bitrise-io/go-utils/pathutil" ) -// FileManager ... -type FileManager interface { - Remove(path string) error - RemoveAll(path string) error - Write(path string, value string, mode os.FileMode) error -} - -type fileManager struct{} - -// NewFileManager ... -func NewFileManager() FileManager { - return fileManager{} -} - -// Remove ... -func (fileManager) Remove(path string) error { - return os.Remove(path) -} - -// RemoveAll ... -func (fileManager) RemoveAll(path string) error { - return os.RemoveAll(path) -} - -// Write ... -func (fileManager) Write(path string, value string, mode os.FileMode) error { - if err := ensureSavePath(path); err != nil { - return err - } - - if err := WriteStringToFile(path, value); err != nil { - return err - } - - if err := os.Chmod(path, mode); err != nil { - return err - } - return nil -} - -func ensureSavePath(savePath string) error { - dirPath := filepath.Dir(savePath) - return os.MkdirAll(dirPath, 0700) -} - // WriteStringToFile ... func WriteStringToFile(pth string, fileCont string) error { return WriteBytesToFile(pth, []byte(fileCont)) diff --git a/vendor/github.com/bitrise-io/go-utils/log/defaultlogger.go b/vendor/github.com/bitrise-io/go-utils/log/defaultlogger.go new file mode 100644 index 0000000..0d2a307 --- /dev/null +++ b/vendor/github.com/bitrise-io/go-utils/log/defaultlogger.go @@ -0,0 +1,57 @@ +package log + +// DefaultLogger ... +type DefaultLogger struct { + ts bool +} + +// NewDefaultLogger ... +func NewDefaultLogger(withTimestamp bool) DefaultLogger { + return DefaultLogger{withTimestamp} +} + +// Donef ... +func (dl DefaultLogger) Donef(format string, v ...interface{}) { + fSelect(dl.ts, TDonef, Donef)(format, v...) +} + +// Successf ... +func (dl DefaultLogger) Successf(format string, v ...interface{}) { + fSelect(dl.ts, TSuccessf, Successf)(format, v...) +} + +// Infof ... +func (dl DefaultLogger) Infof(format string, v ...interface{}) { + fSelect(dl.ts, TInfof, Infof)(format, v...) +} + +// Printf ... +func (dl DefaultLogger) Printf(format string, v ...interface{}) { + fSelect(dl.ts, TPrintf, Printf)(format, v...) +} + +// Warnf ... +func (dl DefaultLogger) Warnf(format string, v ...interface{}) { + fSelect(dl.ts, TWarnf, Warnf)(format, v...) +} + +// Errorf ... +func (dl DefaultLogger) Errorf(format string, v ...interface{}) { + fSelect(dl.ts, TErrorf, Errorf)(format, v...) +} + +// Debugf ... +func (dl DefaultLogger) Debugf(format string, v ...interface{}) { + if enableDebugLog { + fSelect(dl.ts, TDebugf, Debugf)(format, v...) + } +} + +type logfunc func(string, ...interface{}) + +func fSelect(t bool, tf logfunc, f logfunc) logfunc { + if t { + return tf + } + return f +} diff --git a/vendor/github.com/bitrise-io/go-utils/log/dummylogger.go b/vendor/github.com/bitrise-io/go-utils/log/dummylogger.go new file mode 100644 index 0000000..54b0bb9 --- /dev/null +++ b/vendor/github.com/bitrise-io/go-utils/log/dummylogger.go @@ -0,0 +1,30 @@ +package log + +// DummyLogger ... +type DummyLogger struct{} + +// NewDummyLogger ... +func NewDummyLogger() DummyLogger { + return DummyLogger{} +} + +// Donef ... +func (dl DummyLogger) Donef(format string, v ...interface{}) {} + +// Successf ... +func (dl DummyLogger) Successf(format string, v ...interface{}) {} + +// Infof ... +func (dl DummyLogger) Infof(format string, v ...interface{}) {} + +// Printf ... +func (dl DummyLogger) Printf(format string, v ...interface{}) {} + +// Debugf ... +func (dl DummyLogger) Debugf(format string, v ...interface{}) {} + +// Warnf ... +func (dl DummyLogger) Warnf(format string, v ...interface{}) {} + +// Errorf ... +func (dl DummyLogger) Errorf(format string, v ...interface{}) {} diff --git a/vendor/github.com/bitrise-io/go-utils/log/json_logger.go b/vendor/github.com/bitrise-io/go-utils/log/json_logger.go new file mode 100644 index 0000000..31148b3 --- /dev/null +++ b/vendor/github.com/bitrise-io/go-utils/log/json_logger.go @@ -0,0 +1,33 @@ +package log + +import ( + "fmt" + "io" + "os" +) + +// JSONLoger ... +type JSONLoger struct { + writer io.Writer +} + +// NewJSONLoger ... +func NewJSONLoger(writer io.Writer) *JSONLoger { + return &JSONLoger{ + writer: writer, + } +} + +// NewDefaultJSONLoger ... +func NewDefaultJSONLoger() JSONLoger { + return JSONLoger{ + writer: os.Stdout, + } +} + +// Print ... +func (l JSONLoger) Print(f Formatable) { + if _, err := fmt.Fprint(l.writer, f.JSON()); err != nil { + fmt.Printf("failed to print message: %s, error: %s\n", f.JSON(), err) + } +} diff --git a/vendor/github.com/bitrise-io/go-utils/log/log.go b/vendor/github.com/bitrise-io/go-utils/log/log.go index 84bd490..1b69028 100644 --- a/vendor/github.com/bitrise-io/go-utils/log/log.go +++ b/vendor/github.com/bitrise-io/go-utils/log/log.go @@ -7,240 +7,28 @@ import ( "time" ) -// Logger ... -type Logger interface { - Infof(format string, v ...interface{}) - Warnf(format string, v ...interface{}) - Printf(format string, v ...interface{}) - Donef(format string, v ...interface{}) - Debugf(format string, v ...interface{}) - Errorf(format string, v ...interface{}) - TInfof(format string, v ...interface{}) - TWarnf(format string, v ...interface{}) - TPrintf(format string, v ...interface{}) - TDonef(format string, v ...interface{}) - TDebugf(format string, v ...interface{}) - TErrorf(format string, v ...interface{}) - Println() - EnableDebugLog(enable bool) -} - -const defaultTimeStampLayout = "15:04:05" - -type defaultLogger struct { - enableDebugLog bool - timestampLayout string - stdout io.Writer -} - -// NewLogger ... -func NewLogger() Logger { - return &defaultLogger{enableDebugLog: false, timestampLayout: defaultTimeStampLayout, stdout: os.Stdout} -} - -// EnableDebugLog ... -func (l *defaultLogger) EnableDebugLog(enable bool) { - l.enableDebugLog = enable -} - -// Infof ... -func (l *defaultLogger) Infof(format string, v ...interface{}) { - l.printf(infoSeverity, false, format, v...) -} - -// Warnf ... -func (l *defaultLogger) Warnf(format string, v ...interface{}) { - l.printf(warnSeverity, false, format, v...) -} - -// Printf ... -func (l *defaultLogger) Printf(format string, v ...interface{}) { - l.printf(normalSeverity, false, format, v...) -} - -// Donef ... -func (l *defaultLogger) Donef(format string, v ...interface{}) { - l.printf(doneSeverity, false, format, v...) -} - -// Debugf ... -func (l *defaultLogger) Debugf(format string, v ...interface{}) { - if l.enableDebugLog { - l.printf(debugSeverity, false, format, v...) - } -} - -// Errorf ... -func (l *defaultLogger) Errorf(format string, v ...interface{}) { - l.printf(errorSeverity, false, format, v...) -} - -// TInfof ... -func (l *defaultLogger) TInfof(format string, v ...interface{}) { - l.printf(infoSeverity, true, format, v...) -} - -// TWarnf ... -func (l *defaultLogger) TWarnf(format string, v ...interface{}) { - l.printf(warnSeverity, true, format, v...) -} - -// TPrintf ... -func (l *defaultLogger) TPrintf(format string, v ...interface{}) { - l.printf(normalSeverity, true, format, v...) -} - -// TDonef ... -func (l *defaultLogger) TDonef(format string, v ...interface{}) { - l.printf(doneSeverity, true, format, v...) -} - -// TDebugf ... -func (l *defaultLogger) TDebugf(format string, v ...interface{}) { - if l.enableDebugLog { - l.printf(debugSeverity, true, format, v...) - } -} - -// TErrorf ... -func (l *defaultLogger) TErrorf(format string, v ...interface{}) { - l.printf(errorSeverity, true, format, v...) -} - -// Println ... -func (l *defaultLogger) Println() { - fmt.Println() -} - -func (l *defaultLogger) timestampField() string { - currentTime := time.Now() - return fmt.Sprintf("[%s]", currentTime.Format(l.timestampLayout)) -} - -func (l *defaultLogger) prefixCurrentTime(message string) string { - return fmt.Sprintf("%s %s", l.timestampField(), message) -} +var outWriter io.Writer = os.Stdout -func (l *defaultLogger) createLogMsg(severity Severity, withTime bool, format string, v ...interface{}) string { - colorFunc := severityColorFuncMap[severity] - message := colorFunc(format, v...) - if withTime { - message = l.prefixCurrentTime(message) - } - - return message -} - -func (l *defaultLogger) printf(severity Severity, withTime bool, format string, v ...interface{}) { - message := l.createLogMsg(severity, withTime, format, v...) - if _, err := fmt.Fprintln(l.stdout, message); err != nil { - fmt.Printf("failed to print message: %s, error: %s\n", message, err) - } -} - -// RInfof ... -func RInfof(stepID string, tag string, data map[string]interface{}, format string, v ...interface{}) { - rprintf("info", stepID, tag, data, format, v...) -} - -// RWarnf ... -func RWarnf(stepID string, tag string, data map[string]interface{}, format string, v ...interface{}) { - rprintf("warn", stepID, tag, data, format, v...) -} - -// RErrorf ... -func RErrorf(stepID string, tag string, data map[string]interface{}, format string, v ...interface{}) { - rprintf("error", stepID, tag, data, format, v...) +// SetOutWriter ... +func SetOutWriter(writer io.Writer) { + outWriter = writer } -var deprecatedLogger = defaultLogger{stdout: os.Stdout, enableDebugLog: false, timestampLayout: defaultTimeStampLayout} +var enableDebugLog = false // SetEnableDebugLog ... -// Deprecated: use Logger instead. func SetEnableDebugLog(enable bool) { - deprecatedLogger.enableDebugLog = enable + enableDebugLog = enable } +var timestampLayout = "15:04:05" + // SetTimestampLayout ... -// Deprecated: use Logger instead. func SetTimestampLayout(layout string) { - deprecatedLogger.timestampLayout = layout -} - -// SetOutWriter ... -// Deprecated: use Logger for verification instead. -func SetOutWriter(writer io.Writer) { - deprecatedLogger.stdout = writer -} - -// Donef ... -// Deprecated: use Logger instead. -func Donef(format string, v ...interface{}) { - deprecatedLogger.Donef(format, v...) -} - -// Infof ... -// Deprecated: use Logger instead. -func Infof(format string, v ...interface{}) { - deprecatedLogger.Infof(format, v...) + timestampLayout = layout } -// Printf ... -// Deprecated: use Logger instead. -func Printf(format string, v ...interface{}) { - deprecatedLogger.Printf(format, v...) -} - -// Debugf ... -// Deprecated: use Logger instead. -func Debugf(format string, v ...interface{}) { - deprecatedLogger.Debugf(format, v...) -} - -// Warnf ... -// Deprecated: use Logger instead. -func Warnf(format string, v ...interface{}) { - deprecatedLogger.Warnf(format, v...) -} - -// Errorf ... -// Deprecated: use Logger instead. -func Errorf(format string, v ...interface{}) { - deprecatedLogger.Errorf(format, v...) -} - -// TDonef ... -// Deprecated: use Logger instead. -func TDonef(format string, v ...interface{}) { - deprecatedLogger.TDonef(format, v...) -} - -// TInfof ... -// Deprecated: use Logger instead. -func TInfof(format string, v ...interface{}) { - deprecatedLogger.TInfof(format, v...) -} - -// TPrintf ... -// Deprecated: use Logger instead. -func TPrintf(format string, v ...interface{}) { - deprecatedLogger.TPrintf(format, v...) -} - -// TDebugf ... -// Deprecated: use Logger instead. -func TDebugf(format string, v ...interface{}) { - deprecatedLogger.TDebugf(format, v...) -} - -// TWarnf ... -// Deprecated: use Logger instead. -func TWarnf(format string, v ...interface{}) { - deprecatedLogger.TWarnf(format, v...) -} - -// TErrorf ... -// Deprecated: use Logger instead. -func TErrorf(format string, v ...interface{}) { - deprecatedLogger.TErrorf(format, v...) +func timestampField() string { + currentTime := time.Now() + return fmt.Sprintf("[%s]", currentTime.Format(timestampLayout)) } diff --git a/vendor/github.com/bitrise-io/go-utils/log/logger.go b/vendor/github.com/bitrise-io/go-utils/log/logger.go new file mode 100644 index 0000000..4691122 --- /dev/null +++ b/vendor/github.com/bitrise-io/go-utils/log/logger.go @@ -0,0 +1,12 @@ +package log + +// Logger ... +type Logger interface { + Print(f Formatable) +} + +// Formatable ... +type Formatable interface { + String() string + JSON() string +} diff --git a/vendor/github.com/bitrise-io/go-utils/log/print.go b/vendor/github.com/bitrise-io/go-utils/log/print.go new file mode 100644 index 0000000..1c817c4 --- /dev/null +++ b/vendor/github.com/bitrise-io/go-utils/log/print.go @@ -0,0 +1,115 @@ +package log + +import ( + "fmt" +) + +func printf(severity Severity, withTime bool, format string, v ...interface{}) { + message := createLogMsg(severity, withTime, format, v...) + if _, err := fmt.Fprintln(outWriter, message); err != nil { + fmt.Printf("failed to print message: %s, error: %s\n", message, err) + } +} + +func createLogMsg(severity Severity, withTime bool, format string, v ...interface{}) string { + colorFunc := severityColorFuncMap[severity] + message := colorFunc(format, v...) + if withTime { + message = prefixCurrentTime(message) + } + + return message +} + +func prefixCurrentTime(message string) string { + return fmt.Sprintf("%s %s", timestampField(), message) +} + +// Successf ... +func Successf(format string, v ...interface{}) { + printf(successSeverity, false, format, v...) +} + +// Donef ... +func Donef(format string, v ...interface{}) { + Successf(format, v...) +} + +// Infof ... +func Infof(format string, v ...interface{}) { + printf(infoSeverity, false, format, v...) +} + +// Printf ... +func Printf(format string, v ...interface{}) { + printf(normalSeverity, false, format, v...) +} + +// Debugf ... +func Debugf(format string, v ...interface{}) { + if enableDebugLog { + printf(debugSeverity, false, format, v...) + } +} + +// Warnf ... +func Warnf(format string, v ...interface{}) { + printf(warnSeverity, false, format, v...) +} + +// Errorf ... +func Errorf(format string, v ...interface{}) { + printf(errorSeverity, false, format, v...) +} + +// TSuccessf ... +func TSuccessf(format string, v ...interface{}) { + printf(successSeverity, true, format, v...) +} + +// TDonef ... +func TDonef(format string, v ...interface{}) { + TSuccessf(format, v...) +} + +// TInfof ... +func TInfof(format string, v ...interface{}) { + printf(infoSeverity, true, format, v...) +} + +// TPrintf ... +func TPrintf(format string, v ...interface{}) { + printf(normalSeverity, true, format, v...) +} + +// TDebugf ... +func TDebugf(format string, v ...interface{}) { + if enableDebugLog { + printf(debugSeverity, true, format, v...) + } +} + +// TWarnf ... +func TWarnf(format string, v ...interface{}) { + printf(warnSeverity, true, format, v...) +} + +// TErrorf ... +func TErrorf(format string, v ...interface{}) { + printf(errorSeverity, true, format, v...) +} + +// RInfof ... +func RInfof(stepID string, tag string, data map[string]interface{}, format string, v ...interface{}) { + rprintf("info", stepID, tag, data, format, v...) +} + +// RWarnf ... +func RWarnf(stepID string, tag string, data map[string]interface{}, format string, v ...interface{}) { + rprintf("warn", stepID, tag, data, format, v...) +} + +// RErrorf ... +func RErrorf(stepID string, tag string, data map[string]interface{}, format string, v ...interface{}) { + rprintf("error", stepID, tag, data, format, v...) +} diff --git a/vendor/github.com/bitrise-io/go-utils/log/raw_logger.go b/vendor/github.com/bitrise-io/go-utils/log/raw_logger.go new file mode 100644 index 0000000..a673380 --- /dev/null +++ b/vendor/github.com/bitrise-io/go-utils/log/raw_logger.go @@ -0,0 +1,33 @@ +package log + +import ( + "fmt" + "io" + "os" +) + +// RawLogger ... +type RawLogger struct { + writer io.Writer +} + +// NewRawLogger ... +func NewRawLogger(writer io.Writer) *RawLogger { + return &RawLogger{ + writer: writer, + } +} + +// NewDefaultRawLogger ... +func NewDefaultRawLogger() RawLogger { + return RawLogger{ + writer: os.Stdout, + } +} + +// Print ... +func (l RawLogger) Print(f Formatable) { + if _, err := fmt.Fprintln(l.writer, f.String()); err != nil { + fmt.Printf("failed to print message: %s, error: %s\n", f.String(), err) + } +} diff --git a/vendor/github.com/bitrise-io/go-utils/log/severity.go b/vendor/github.com/bitrise-io/go-utils/log/severity.go index fc1fc96..4e7786d 100644 --- a/vendor/github.com/bitrise-io/go-utils/log/severity.go +++ b/vendor/github.com/bitrise-io/go-utils/log/severity.go @@ -10,26 +10,26 @@ const ( warnSeverity normalSeverity infoSeverity - doneSeverity + successSeverity debugSeverity ) type severityColorFunc colorstring.ColorfFunc var ( - doneSeverityColorFunc severityColorFunc = colorstring.Greenf - infoSeverityColorFunc severityColorFunc = colorstring.Bluef - normalSeverityColorFunc severityColorFunc = colorstring.NoColorf - debugSeverityColorFunc severityColorFunc = colorstring.Magentaf - warnSeverityColorFunc severityColorFunc = colorstring.Yellowf - errorSeverityColorFunc severityColorFunc = colorstring.Redf + successSeverityColorFunc severityColorFunc = colorstring.Greenf + infoSeverityColorFunc severityColorFunc = colorstring.Bluef + normalSeverityColorFunc severityColorFunc = colorstring.NoColorf + debugSeverityColorFunc severityColorFunc = colorstring.Magentaf + warnSeverityColorFunc severityColorFunc = colorstring.Yellowf + errorSeverityColorFunc severityColorFunc = colorstring.Redf ) var severityColorFuncMap = map[Severity]severityColorFunc{ - doneSeverity: doneSeverityColorFunc, - infoSeverity: infoSeverityColorFunc, - normalSeverity: normalSeverityColorFunc, - debugSeverity: debugSeverityColorFunc, - warnSeverity: warnSeverityColorFunc, - errorSeverity: errorSeverityColorFunc, + successSeverity: successSeverityColorFunc, + infoSeverity: infoSeverityColorFunc, + normalSeverity: normalSeverityColorFunc, + debugSeverity: debugSeverityColorFunc, + warnSeverity: warnSeverityColorFunc, + errorSeverity: errorSeverityColorFunc, } diff --git a/vendor/github.com/bitrise-io/go-utils/pathutil/pathutil.go b/vendor/github.com/bitrise-io/go-utils/pathutil/pathutil.go index aeb8e22..947c97c 100644 --- a/vendor/github.com/bitrise-io/go-utils/pathutil/pathutil.go +++ b/vendor/github.com/bitrise-io/go-utils/pathutil/pathutil.go @@ -10,25 +10,6 @@ import ( "strings" ) -// -// Path provider functions - -// PathProvider ... -type PathProvider interface { - CreateTempDir(prefix string) (string, error) -} - -type defaultPathProvider struct{} - -// NewPathProvider ... -func NewPathProvider() PathProvider { - return defaultPathProvider{} -} - -func (defaultPathProvider) CreateTempDir(prefix string) (string, error) { - return NormalizedOSTempDirPath(prefix) -} - // NormalizedOSTempDirPath ... // Creates a temp dir, and returns its path. // If tmpDirNamePrefix is provided it'll be used @@ -68,25 +49,6 @@ func EnsureDirExist(dir string) error { return nil } -// -// Path checker functions - -// PathChecker ... -type PathChecker interface { - IsPathExists(pth string) (bool, error) -} - -type defaultPathChecker struct{} - -// NewPathChecker ... -func NewPathChecker() PathChecker { - return defaultPathChecker{} -} - -func (c defaultPathChecker) IsPathExists(pth string) (bool, error) { - return IsPathExists(pth) -} - func genericIsPathExists(pth string) (os.FileInfo, bool, error) { if pth == "" { return nil, false, errors.New("No path provided") diff --git a/vendor/github.com/bitrise-io/go-utils/retry/retry.go b/vendor/github.com/bitrise-io/go-utils/retry/retry.go index be38040..facb89f 100644 --- a/vendor/github.com/bitrise-io/go-utils/retry/retry.go +++ b/vendor/github.com/bitrise-io/go-utils/retry/retry.go @@ -8,6 +8,9 @@ import ( // Action ... type Action func(attempt uint) error +// AbortableAction ... +type AbortableAction func(attempt uint) (error, bool) + // Model ... type Model struct { retry uint @@ -38,19 +41,37 @@ func (Model *Model) Wait(waitTime time.Duration) *Model { return Model } -// Try ... +// Try continues executing the supplied action while this action parameter returns an error and the configured +// number of times has not been reached. Otherwise, it stops and returns the last received error. func (Model Model) Try(action Action) error { + return Model.TryWithAbort(func(attempt uint) (error, bool) { + return action(attempt), false + }) +} + +// TryWithAbort continues executing the supplied action while this action parameter returns an error, a false bool +// value and the configured number of times has not been reached. Returning a true value from the action aborts the +// retry loop. +// +// Good for retrying actions which can return a mix of retryable and non-retryable failures. +func (Model Model) TryWithAbort(action AbortableAction) error { if action == nil { return fmt.Errorf("no action specified") } var err error + var shouldAbort bool + for attempt := uint(0); (0 == attempt || nil != err) && attempt <= Model.retry; attempt++ { if attempt > 0 && Model.waitTime > 0 { time.Sleep(Model.waitTime) } - err = action(attempt) + err, shouldAbort = action(attempt) + + if shouldAbort { + break + } } return err diff --git a/vendor/github.com/bitrise-io/go-utils/v2/LICENSE b/vendor/github.com/bitrise-io/go-utils/v2/LICENSE new file mode 100644 index 0000000..a6a5c39 --- /dev/null +++ b/vendor/github.com/bitrise-io/go-utils/v2/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 Bitrise + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/vendor/github.com/bitrise-io/go-utils/v2/command/command.go b/vendor/github.com/bitrise-io/go-utils/v2/command/command.go new file mode 100644 index 0000000..eedc628 --- /dev/null +++ b/vendor/github.com/bitrise-io/go-utils/v2/command/command.go @@ -0,0 +1,120 @@ +package command + +import ( + "io" + "os/exec" + "strconv" + "strings" + + "github.com/bitrise-io/go-utils/v2/env" +) + +// Opts ... +type Opts struct { + Stdout io.Writer + Stderr io.Writer + Stdin io.Reader + Env []string + Dir string +} + +// Factory ... +type Factory interface { + Create(name string, args []string, opts *Opts) Command +} + +type factory struct { + envRepository env.Repository +} + +// NewFactory ... +func NewFactory(envRepository env.Repository) Factory { + return factory{envRepository: envRepository} +} + +// Create ... +func (f factory) Create(name string, args []string, opts *Opts) Command { + cmd := exec.Command(name, args...) + if opts != nil { + cmd.Stdout = opts.Stdout + cmd.Stderr = opts.Stderr + cmd.Stdin = opts.Stdin + + // If Env is nil, the new process uses the current process's + // environment. + // If we pass env vars we want to append them to the + // current process's environment. + cmd.Env = append(f.envRepository.List(), opts.Env...) + cmd.Dir = opts.Dir + } + return command{cmd} +} + +// Command ... +type Command interface { + PrintableCommandArgs() string + Run() error + RunAndReturnExitCode() (int, error) + RunAndReturnTrimmedOutput() (string, error) + RunAndReturnTrimmedCombinedOutput() (string, error) + Start() error + Wait() error +} + +type command struct { + cmd *exec.Cmd +} + +// PrintableCommandArgs ... +func (c command) PrintableCommandArgs() string { + return printableCommandArgs(false, c.cmd.Args) +} + +// Run ... +func (c command) Run() error { + return c.cmd.Run() +} + +// RunAndReturnExitCode ... +func (c command) RunAndReturnExitCode() (int, error) { + err := c.cmd.Run() + exitCode := c.cmd.ProcessState.ExitCode() + return exitCode, err +} + +// RunAndReturnTrimmedOutput ... +func (c command) RunAndReturnTrimmedOutput() (string, error) { + outBytes, err := c.cmd.Output() + outStr := string(outBytes) + return strings.TrimSpace(outStr), err +} + +// RunAndReturnTrimmedCombinedOutput ... +func (c command) RunAndReturnTrimmedCombinedOutput() (string, error) { + outBytes, err := c.cmd.CombinedOutput() + outStr := string(outBytes) + return strings.TrimSpace(outStr), err +} + +// Start ... +func (c command) Start() error { + return c.cmd.Start() +} + +// Wait ... +func (c command) Wait() error { + return c.cmd.Wait() +} + +func printableCommandArgs(isQuoteFirst bool, fullCommandArgs []string) string { + var cmdArgsDecorated []string + for idx, anArg := range fullCommandArgs { + quotedArg := strconv.Quote(anArg) + if idx == 0 && !isQuoteFirst { + quotedArg = anArg + } + cmdArgsDecorated = append(cmdArgsDecorated, quotedArg) + } + + return strings.Join(cmdArgsDecorated, " ") +} diff --git a/vendor/github.com/bitrise-io/go-utils/env/env.go b/vendor/github.com/bitrise-io/go-utils/v2/env/env.go similarity index 73% rename from vendor/github.com/bitrise-io/go-utils/env/env.go rename to vendor/github.com/bitrise-io/go-utils/v2/env/env.go index 221f27d..85cf1ae 100644 --- a/vendor/github.com/bitrise-io/go-utils/env/env.go +++ b/vendor/github.com/bitrise-io/go-utils/v2/env/env.go @@ -32,27 +32,27 @@ type Repository interface { // NewRepository ... func NewRepository() Repository { - return defaultRepository{} + return repository{} } -type defaultRepository struct{} +type repository struct{} // Get ... -func (d defaultRepository) Get(key string) string { +func (d repository) Get(key string) string { return os.Getenv(key) } // Set ... -func (d defaultRepository) Set(key, value string) error { +func (d repository) Set(key, value string) error { return os.Setenv(key, value) } // Unset ... -func (d defaultRepository) Unset(key string) error { +func (d repository) Unset(key string) error { return os.Unsetenv(key) } // List ... -func (d defaultRepository) List() []string { +func (d repository) List() []string { return os.Environ() } diff --git a/vendor/github.com/bitrise-io/go-utils/v2/log/log.go b/vendor/github.com/bitrise-io/go-utils/v2/log/log.go new file mode 100644 index 0000000..0c77db9 --- /dev/null +++ b/vendor/github.com/bitrise-io/go-utils/v2/log/log.go @@ -0,0 +1,139 @@ +package log + +import ( + "fmt" + "io" + "os" + "time" +) + +// Logger ... +type Logger interface { + Infof(format string, v ...interface{}) + Warnf(format string, v ...interface{}) + Printf(format string, v ...interface{}) + Donef(format string, v ...interface{}) + Debugf(format string, v ...interface{}) + Errorf(format string, v ...interface{}) + TInfof(format string, v ...interface{}) + TWarnf(format string, v ...interface{}) + TPrintf(format string, v ...interface{}) + TDonef(format string, v ...interface{}) + TDebugf(format string, v ...interface{}) + TErrorf(format string, v ...interface{}) + Println() + EnableDebugLog(enable bool) +} + +const defaultTimeStampLayout = "15:04:05" + +type logger struct { + enableDebugLog bool + timestampLayout string + stdout io.Writer +} + +// NewLogger ... +func NewLogger() Logger { + return &logger{enableDebugLog: false, timestampLayout: defaultTimeStampLayout, stdout: os.Stdout} +} + +// EnableDebugLog ... +func (l *logger) EnableDebugLog(enable bool) { + l.enableDebugLog = enable +} + +// Infof ... +func (l *logger) Infof(format string, v ...interface{}) { + l.printf(infoSeverity, false, format, v...) +} + +// Warnf ... +func (l *logger) Warnf(format string, v ...interface{}) { + l.printf(warnSeverity, false, format, v...) +} + +// Printf ... +func (l *logger) Printf(format string, v ...interface{}) { + l.printf(normalSeverity, false, format, v...) +} + +// Donef ... +func (l *logger) Donef(format string, v ...interface{}) { + l.printf(doneSeverity, false, format, v...) +} + +// Debugf ... +func (l *logger) Debugf(format string, v ...interface{}) { + if l.enableDebugLog { + l.printf(debugSeverity, false, format, v...) + } +} + +// Errorf ... +func (l *logger) Errorf(format string, v ...interface{}) { + l.printf(errorSeverity, false, format, v...) +} + +// TInfof ... +func (l *logger) TInfof(format string, v ...interface{}) { + l.printf(infoSeverity, true, format, v...) +} + +// TWarnf ... +func (l *logger) TWarnf(format string, v ...interface{}) { + l.printf(warnSeverity, true, format, v...) +} + +// TPrintf ... +func (l *logger) TPrintf(format string, v ...interface{}) { + l.printf(normalSeverity, true, format, v...) +} + +// TDonef ... +func (l *logger) TDonef(format string, v ...interface{}) { + l.printf(doneSeverity, true, format, v...) +} + +// TDebugf ... +func (l *logger) TDebugf(format string, v ...interface{}) { + if l.enableDebugLog { + l.printf(debugSeverity, true, format, v...) + } +} + +// TErrorf ... +func (l *logger) TErrorf(format string, v ...interface{}) { + l.printf(errorSeverity, true, format, v...) +} + +// Println ... +func (l *logger) Println() { + fmt.Println() +} + +func (l *logger) timestampField() string { + currentTime := time.Now() + return fmt.Sprintf("[%s]", currentTime.Format(l.timestampLayout)) +} + +func (l *logger) prefixCurrentTime(message string) string { + return fmt.Sprintf("%s %s", l.timestampField(), message) +} + +func (l *logger) createLogMsg(severity Severity, withTime bool, format string, v ...interface{}) string { + colorFunc := severityColorFuncMap[severity] + message := colorFunc(format, v...) + if withTime { + message = l.prefixCurrentTime(message) + } + + return message +} + +func (l *logger) printf(severity Severity, withTime bool, format string, v ...interface{}) { + message := l.createLogMsg(severity, withTime, format, v...) + if _, err := fmt.Fprintln(l.stdout, message); err != nil { + fmt.Printf("failed to print message: %s, error: %s\n", message, err) + } +} diff --git a/vendor/github.com/bitrise-io/go-utils/v2/log/severity.go b/vendor/github.com/bitrise-io/go-utils/v2/log/severity.go new file mode 100644 index 0000000..fc1fc96 --- /dev/null +++ b/vendor/github.com/bitrise-io/go-utils/v2/log/severity.go @@ -0,0 +1,35 @@ +package log + +import "github.com/bitrise-io/go-utils/colorstring" + +// Severity ... +type Severity uint8 + +const ( + errorSeverity Severity = iota + warnSeverity + normalSeverity + infoSeverity + doneSeverity + debugSeverity +) + +type severityColorFunc colorstring.ColorfFunc + +var ( + doneSeverityColorFunc severityColorFunc = colorstring.Greenf + infoSeverityColorFunc severityColorFunc = colorstring.Bluef + normalSeverityColorFunc severityColorFunc = colorstring.NoColorf + debugSeverityColorFunc severityColorFunc = colorstring.Magentaf + warnSeverityColorFunc severityColorFunc = colorstring.Yellowf + errorSeverityColorFunc severityColorFunc = colorstring.Redf +) + +var severityColorFuncMap = map[Severity]severityColorFunc{ + doneSeverity: doneSeverityColorFunc, + infoSeverity: infoSeverityColorFunc, + normalSeverity: normalSeverityColorFunc, + debugSeverity: debugSeverityColorFunc, + warnSeverity: warnSeverityColorFunc, + errorSeverity: errorSeverityColorFunc, +} diff --git a/vendor/github.com/bitrise-io/go-xcode/LICENSE b/vendor/github.com/bitrise-io/go-xcode/LICENSE new file mode 100644 index 0000000..cdfcf1f --- /dev/null +++ b/vendor/github.com/bitrise-io/go-xcode/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Bitrise + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/github.com/bitrise-io/go-xcode/devportalservice/devportalservice.go b/vendor/github.com/bitrise-io/go-xcode/devportalservice/devportalservice.go index 5d0d77f..a4702b5 100644 --- a/vendor/github.com/bitrise-io/go-xcode/devportalservice/devportalservice.go +++ b/vendor/github.com/bitrise-io/go-xcode/devportalservice/devportalservice.go @@ -6,6 +6,7 @@ import ( "fmt" "io/ioutil" "net/http" + "os" "regexp" "strings" "text/template" @@ -254,3 +255,21 @@ func validateTestDevice(deviceList []TestDevice) (validDevices, duplicatedDevice return validDevices, duplicatedDevices } + +// WritePrivateKeyToFile writes the contents of the private key to a temporary file and returns its path +func (c *APIKeyConnection) WritePrivateKeyToFile() (string, error) { + privatekeyFile, err := os.CreateTemp("", fmt.Sprintf("AuthKey_%s_*.p8", c.KeyID)) + if err != nil { + return "", fmt.Errorf("failed to create private key file: %s", err) + } + + if _, err := privatekeyFile.Write([]byte(c.PrivateKey)); err != nil { + return "", fmt.Errorf("failed to write private key: %s", err) + } + + if err := privatekeyFile.Close(); err != nil { + return "", fmt.Errorf("failed to close private key file: %s", err) + } + + return privatekeyFile.Name(), nil +} diff --git a/vendor/github.com/bitrise-io/stepman/models/models.go b/vendor/github.com/bitrise-io/stepman/models/models.go index 2ba805f..7ab6ea6 100644 --- a/vendor/github.com/bitrise-io/stepman/models/models.go +++ b/vendor/github.com/bitrise-io/stepman/models/models.go @@ -40,16 +40,10 @@ type AptGetDepModel struct { BinName string `json:"bin_name,omitempty" yaml:"bin_name,omitempty"` } -// CheckOnlyDepModel ... -type CheckOnlyDepModel struct { - Name string `json:"name,omitempty" yaml:"name,omitempty"` -} - // DepsModel ... type DepsModel struct { - Brew []BrewDepModel `json:"brew,omitempty" yaml:"brew,omitempty"` - AptGet []AptGetDepModel `json:"apt_get,omitempty" yaml:"apt_get,omitempty"` - CheckOnly []CheckOnlyDepModel `json:"check_only,omitempty" yaml:"check_only,omitempty"` + Brew []BrewDepModel `json:"brew,omitempty" yaml:"brew,omitempty"` + AptGet []AptGetDepModel `json:"apt_get,omitempty" yaml:"apt_get,omitempty"` } // BashStepToolkitModel ... @@ -63,10 +57,17 @@ type GoStepToolkitModel struct { PackageName string `json:"package_name" yaml:"package_name"` } +// SwiftStepToolkitModel ... +type SwiftStepToolkitModel struct { + BinaryLocation string `json:"binary_location,omitempty" yaml:"binary_location,omitempty"` + ExecutableName string `json:"executable_name,omitempty" yaml:"executable_name,omitempty"` +} + // StepToolkitModel ... type StepToolkitModel struct { - Bash *BashStepToolkitModel `json:"bash,omitempty" yaml:"bash,omitempty"` - Go *GoStepToolkitModel `json:"go,omitempty" yaml:"go,omitempty"` + Bash *BashStepToolkitModel `json:"bash,omitempty" yaml:"bash,omitempty"` + Go *GoStepToolkitModel `json:"go,omitempty" yaml:"go,omitempty"` + Swift *SwiftStepToolkitModel `json:"swift,omitempty" yaml:"swift,omitempty"` } // StepModel ... diff --git a/vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go b/vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go index 8d306bf..fe28d15 100644 --- a/vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go +++ b/vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go @@ -32,6 +32,7 @@ func DefaultPooledTransport() *http.Transport { IdleConnTimeout: 90 * time.Second, TLSHandshakeTimeout: 10 * time.Second, ExpectContinueTimeout: 1 * time.Second, + ForceAttemptHTTP2: true, MaxIdleConnsPerHost: runtime.GOMAXPROCS(0) + 1, } return transport diff --git a/vendor/github.com/hashicorp/go-cleanhttp/go.mod b/vendor/github.com/hashicorp/go-cleanhttp/go.mod deleted file mode 100644 index 310f075..0000000 --- a/vendor/github.com/hashicorp/go-cleanhttp/go.mod +++ /dev/null @@ -1 +0,0 @@ -module github.com/hashicorp/go-cleanhttp diff --git a/vendor/github.com/hashicorp/go-retryablehttp/README.md b/vendor/github.com/hashicorp/go-retryablehttp/README.md index 8943bec..09f5eaf 100644 --- a/vendor/github.com/hashicorp/go-retryablehttp/README.md +++ b/vendor/github.com/hashicorp/go-retryablehttp/README.md @@ -45,6 +45,25 @@ The returned response object is an `*http.Response`, the same thing you would usually get from `net/http`. Had the request failed one or more times, the above call would block and retry with exponential backoff. +## Retrying cases that fail after a seeming success + +It's possible for a request to succeed in the sense that the expected response headers are received, but then to encounter network-level errors while reading the response body. In go-retryablehttp's most basic usage, this error would not be retryable, due to the out-of-band handling of the response body. In some cases it may be desirable to handle the response body as part of the retryable operation. + +A toy example (which will retry the full request and succeed on the second attempt) is shown below: + +```go +c := retryablehttp.NewClient() +r := retryablehttp.NewRequest("GET", "://foo", nil) +handlerShouldRetry := true +r.SetResponseHandler(func(*http.Response) error { + if !handlerShouldRetry { + return nil + } + handlerShouldRetry = false + return errors.New("retryable error") +}) +``` + ## Getting a stdlib `*http.Client` with retries It's possible to convert a `*retryablehttp.Client` directly to a `*http.Client`. diff --git a/vendor/github.com/hashicorp/go-retryablehttp/client.go b/vendor/github.com/hashicorp/go-retryablehttp/client.go index adbdd92..57116e9 100644 --- a/vendor/github.com/hashicorp/go-retryablehttp/client.go +++ b/vendor/github.com/hashicorp/go-retryablehttp/client.go @@ -69,11 +69,21 @@ var ( // scheme specified in the URL is invalid. This error isn't typed // specifically so we resort to matching on the error string. schemeErrorRe = regexp.MustCompile(`unsupported protocol scheme`) + + // A regular expression to match the error returned by net/http when the + // TLS certificate is not trusted. This error isn't typed + // specifically so we resort to matching on the error string. + notTrustedErrorRe = regexp.MustCompile(`certificate is not trusted`) ) // ReaderFunc is the type of function that can be given natively to NewRequest type ReaderFunc func() (io.Reader, error) +// ResponseHandlerFunc is a type of function that takes in a Response, and does something with it. +// It only runs if the initial part of the request was successful. +// If an error is returned, the client's retry policy will be used to determine whether to retry the whole request. +type ResponseHandlerFunc func(*http.Response) error + // LenReader is an interface implemented by many in-memory io.Reader's. Used // for automatically sending the right Content-Length header when possible. type LenReader interface { @@ -86,6 +96,8 @@ type Request struct { // used to rewind the request data in between retries. body ReaderFunc + responseHandler ResponseHandlerFunc + // Embed an HTTP request directly. This makes a *Request act exactly // like an *http.Request so that all meta methods are supported. *http.Request @@ -94,8 +106,16 @@ type Request struct { // WithContext returns wrapped Request with a shallow copy of underlying *http.Request // with its context changed to ctx. The provided ctx must be non-nil. func (r *Request) WithContext(ctx context.Context) *Request { - r.Request = r.Request.WithContext(ctx) - return r + return &Request{ + body: r.body, + responseHandler: r.responseHandler, + Request: r.Request.WithContext(ctx), + } +} + +// SetResponseHandler allows setting the response handler. +func (r *Request) SetResponseHandler(fn ResponseHandlerFunc) { + r.responseHandler = fn } // BodyBytes allows accessing the request body. It is an analogue to @@ -252,23 +272,31 @@ func FromRequest(r *http.Request) (*Request, error) { return nil, err } // Could assert contentLength == r.ContentLength - return &Request{bodyReader, r}, nil + return &Request{body: bodyReader, Request: r}, nil } // NewRequest creates a new wrapped request. func NewRequest(method, url string, rawBody interface{}) (*Request, error) { + return NewRequestWithContext(context.Background(), method, url, rawBody) +} + +// NewRequestWithContext creates a new wrapped request with the provided context. +// +// The context controls the entire lifetime of a request and its response: +// obtaining a connection, sending the request, and reading the response headers and body. +func NewRequestWithContext(ctx context.Context, method, url string, rawBody interface{}) (*Request, error) { bodyReader, contentLength, err := getBodyReaderAndContentLength(rawBody) if err != nil { return nil, err } - httpReq, err := http.NewRequest(method, url, nil) + httpReq, err := http.NewRequestWithContext(ctx, method, url, nil) if err != nil { return nil, err } httpReq.ContentLength = contentLength - return &Request{bodyReader, httpReq}, nil + return &Request{body: bodyReader, Request: httpReq}, nil } // Logger interface allows to use other loggers than @@ -435,6 +463,9 @@ func baseRetryPolicy(resp *http.Response, err error) (bool, error) { } // Don't retry if the error was due to TLS cert verification failure. + if notTrustedErrorRe.MatchString(v.Error()) { + return false, v + } if _, ok := v.Err.(x509.UnknownAuthorityError); ok { return false, v } @@ -455,7 +486,7 @@ func baseRetryPolicy(resp *http.Response, err error) (bool, error) { // the server time to recover, as 500's are typically not permanent // errors and may relate to outages on the server side. This will catch // invalid response codes as well, like 0 and 999. - if resp.StatusCode == 0 || (resp.StatusCode >= 500 && resp.StatusCode != 501) { + if resp.StatusCode == 0 || (resp.StatusCode >= 500 && resp.StatusCode != http.StatusNotImplemented) { return true, fmt.Errorf("unexpected HTTP status %s", resp.Status) } @@ -555,13 +586,12 @@ func (c *Client) Do(req *Request) (*http.Response, error) { var resp *http.Response var attempt int var shouldRetry bool - var doErr, checkErr error + var doErr, respErr, checkErr error for i := 0; ; i++ { + doErr, respErr = nil, nil attempt++ - var code int // HTTP response code - // Always rewind the request body when non-nil. if req.body != nil { body, err := req.body() @@ -589,19 +619,24 @@ func (c *Client) Do(req *Request) (*http.Response, error) { // Attempt the request resp, doErr = c.HTTPClient.Do(req.Request) - if resp != nil { - code = resp.StatusCode - } // Check if we should continue with retries. shouldRetry, checkErr = c.CheckRetry(req.Context(), resp, doErr) + if !shouldRetry && doErr == nil && req.responseHandler != nil { + respErr = req.responseHandler(resp) + shouldRetry, checkErr = c.CheckRetry(req.Context(), resp, respErr) + } - if doErr != nil { + err := doErr + if respErr != nil { + err = respErr + } + if err != nil { switch v := logger.(type) { case LeveledLogger: - v.Error("request failed", "error", doErr, "method", req.Method, "url", req.URL) + v.Error("request failed", "error", err, "method", req.Method, "url", req.URL) case Logger: - v.Printf("[ERR] %s %s request failed: %v", req.Method, req.URL, doErr) + v.Printf("[ERR] %s %s request failed: %v", req.Method, req.URL, err) } } else { // Call this here to maintain the behavior of logging all requests, @@ -636,11 +671,11 @@ func (c *Client) Do(req *Request) (*http.Response, error) { } wait := c.Backoff(c.RetryWaitMin, c.RetryWaitMax, i, resp) - desc := fmt.Sprintf("%s %s", req.Method, req.URL) - if code > 0 { - desc = fmt.Sprintf("%s (status: %d)", desc, code) - } if logger != nil { + desc := fmt.Sprintf("%s %s", req.Method, req.URL) + if resp != nil { + desc = fmt.Sprintf("%s (status: %d)", desc, resp.StatusCode) + } switch v := logger.(type) { case LeveledLogger: v.Debug("retrying request", "request", desc, "timeout", wait, "remaining", remain) @@ -648,11 +683,13 @@ func (c *Client) Do(req *Request) (*http.Response, error) { v.Printf("[DEBUG] %s: retrying in %s (%d left)", desc, wait, remain) } } + timer := time.NewTimer(wait) select { case <-req.Context().Done(): + timer.Stop() c.HTTPClient.CloseIdleConnections() return nil, req.Context().Err() - case <-time.After(wait): + case <-timer.C: } // Make shallow copy of http Request so that we can modify its body @@ -662,15 +699,19 @@ func (c *Client) Do(req *Request) (*http.Response, error) { } // this is the closest we have to success criteria - if doErr == nil && checkErr == nil && !shouldRetry { + if doErr == nil && respErr == nil && checkErr == nil && !shouldRetry { return resp, nil } defer c.HTTPClient.CloseIdleConnections() - err := doErr + var err error if checkErr != nil { err = checkErr + } else if respErr != nil { + err = respErr + } else { + err = doErr } if c.ErrorHandler != nil { diff --git a/vendor/github.com/hashicorp/go-retryablehttp/go.mod b/vendor/github.com/hashicorp/go-retryablehttp/go.mod deleted file mode 100644 index 7cc02b7..0000000 --- a/vendor/github.com/hashicorp/go-retryablehttp/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module github.com/hashicorp/go-retryablehttp - -require ( - github.com/hashicorp/go-cleanhttp v0.5.1 - github.com/hashicorp/go-hclog v0.9.2 -) - -go 1.13 diff --git a/vendor/github.com/hashicorp/go-retryablehttp/go.sum b/vendor/github.com/hashicorp/go-retryablehttp/go.sum deleted file mode 100644 index 71afe56..0000000 --- a/vendor/github.com/hashicorp/go-retryablehttp/go.sum +++ /dev/null @@ -1,10 +0,0 @@ -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM= -github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= -github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI= -github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= diff --git a/vendor/github.com/hashicorp/go-version/CHANGELOG.md b/vendor/github.com/hashicorp/go-version/CHANGELOG.md index dbae7f7..5f16dd1 100644 --- a/vendor/github.com/hashicorp/go-version/CHANGELOG.md +++ b/vendor/github.com/hashicorp/go-version/CHANGELOG.md @@ -1,3 +1,23 @@ +# 1.6.0 (June 28, 2022) + +FEATURES: + +- Add `Prerelease` function to `Constraint` to return true if the version includes a prerelease field ([#100](https://github.com/hashicorp/go-version/pull/100)) + +# 1.5.0 (May 18, 2022) + +FEATURES: + +- Use `encoding` `TextMarshaler` & `TextUnmarshaler` instead of JSON equivalents ([#95](https://github.com/hashicorp/go-version/pull/95)) +- Add JSON handlers to allow parsing from/to JSON ([#93](https://github.com/hashicorp/go-version/pull/93)) + +# 1.4.0 (January 5, 2022) + +FEATURES: + + - Introduce `MustConstraints()` ([#87](https://github.com/hashicorp/go-version/pull/87)) + - `Constraints`: Introduce `Equals()` and `sort.Interface` methods ([#88](https://github.com/hashicorp/go-version/pull/88)) + # 1.3.0 (March 31, 2021) Please note that CHANGELOG.md does not exist in the source code prior to this release. diff --git a/vendor/github.com/hashicorp/go-version/README.md b/vendor/github.com/hashicorp/go-version/README.md index 851a337..4d25050 100644 --- a/vendor/github.com/hashicorp/go-version/README.md +++ b/vendor/github.com/hashicorp/go-version/README.md @@ -1,5 +1,5 @@ # Versioning Library for Go -[![Build Status](https://circleci.com/gh/hashicorp/go-version/tree/master.svg?style=svg)](https://circleci.com/gh/hashicorp/go-version/tree/master) +[![Build Status](https://circleci.com/gh/hashicorp/go-version/tree/main.svg?style=svg)](https://circleci.com/gh/hashicorp/go-version/tree/main) [![GoDoc](https://godoc.org/github.com/hashicorp/go-version?status.svg)](https://godoc.org/github.com/hashicorp/go-version) go-version is a library for parsing versions and version constraints, diff --git a/vendor/github.com/hashicorp/go-version/constraint.go b/vendor/github.com/hashicorp/go-version/constraint.go index d055759..da5d1ac 100644 --- a/vendor/github.com/hashicorp/go-version/constraint.go +++ b/vendor/github.com/hashicorp/go-version/constraint.go @@ -4,6 +4,7 @@ import ( "fmt" "reflect" "regexp" + "sort" "strings" ) @@ -11,30 +12,40 @@ import ( // ">= 1.0". type Constraint struct { f constraintFunc + op operator check *Version original string } +func (c *Constraint) Equals(con *Constraint) bool { + return c.op == con.op && c.check.Equal(con.check) +} + // Constraints is a slice of constraints. We make a custom type so that // we can add methods to it. type Constraints []*Constraint type constraintFunc func(v, c *Version) bool -var constraintOperators map[string]constraintFunc +var constraintOperators map[string]constraintOperation + +type constraintOperation struct { + op operator + f constraintFunc +} var constraintRegexp *regexp.Regexp func init() { - constraintOperators = map[string]constraintFunc{ - "": constraintEqual, - "=": constraintEqual, - "!=": constraintNotEqual, - ">": constraintGreaterThan, - "<": constraintLessThan, - ">=": constraintGreaterThanEqual, - "<=": constraintLessThanEqual, - "~>": constraintPessimistic, + constraintOperators = map[string]constraintOperation{ + "": {op: equal, f: constraintEqual}, + "=": {op: equal, f: constraintEqual}, + "!=": {op: notEqual, f: constraintNotEqual}, + ">": {op: greaterThan, f: constraintGreaterThan}, + "<": {op: lessThan, f: constraintLessThan}, + ">=": {op: greaterThanEqual, f: constraintGreaterThanEqual}, + "<=": {op: lessThanEqual, f: constraintLessThanEqual}, + "~>": {op: pessimistic, f: constraintPessimistic}, } ops := make([]string, 0, len(constraintOperators)) @@ -66,6 +77,16 @@ func NewConstraint(v string) (Constraints, error) { return Constraints(result), nil } +// MustConstraints is a helper that wraps a call to a function +// returning (Constraints, error) and panics if error is non-nil. +func MustConstraints(c Constraints, err error) Constraints { + if err != nil { + panic(err) + } + + return c +} + // Check tests if a version satisfies all the constraints. func (cs Constraints) Check(v *Version) bool { for _, c := range cs { @@ -77,6 +98,56 @@ func (cs Constraints) Check(v *Version) bool { return true } +// Equals compares Constraints with other Constraints +// for equality. This may not represent logical equivalence +// of compared constraints. +// e.g. even though '>0.1,>0.2' is logically equivalent +// to '>0.2' it is *NOT* treated as equal. +// +// Missing operator is treated as equal to '=', whitespaces +// are ignored and constraints are sorted before comaparison. +func (cs Constraints) Equals(c Constraints) bool { + if len(cs) != len(c) { + return false + } + + // make copies to retain order of the original slices + left := make(Constraints, len(cs)) + copy(left, cs) + sort.Stable(left) + right := make(Constraints, len(c)) + copy(right, c) + sort.Stable(right) + + // compare sorted slices + for i, con := range left { + if !con.Equals(right[i]) { + return false + } + } + + return true +} + +func (cs Constraints) Len() int { + return len(cs) +} + +func (cs Constraints) Less(i, j int) bool { + if cs[i].op < cs[j].op { + return true + } + if cs[i].op > cs[j].op { + return false + } + + return cs[i].check.LessThan(cs[j].check) +} + +func (cs Constraints) Swap(i, j int) { + cs[i], cs[j] = cs[j], cs[i] +} + // Returns the string format of the constraints func (cs Constraints) String() string { csStr := make([]string, len(cs)) @@ -92,6 +163,12 @@ func (c *Constraint) Check(v *Version) bool { return c.f(v, c.check) } +// Prerelease returns true if the version underlying this constraint +// contains a prerelease field. +func (c *Constraint) Prerelease() bool { + return len(c.check.Prerelease()) > 0 +} + func (c *Constraint) String() string { return c.original } @@ -107,8 +184,11 @@ func parseSingle(v string) (*Constraint, error) { return nil, err } + cop := constraintOperators[matches[1]] + return &Constraint{ - f: constraintOperators[matches[1]], + f: cop.f, + op: cop.op, check: check, original: v, }, nil @@ -138,6 +218,18 @@ func prereleaseCheck(v, c *Version) bool { // Constraint functions //------------------------------------------------------------------- +type operator rune + +const ( + equal operator = '=' + notEqual operator = '≠' + greaterThan operator = '>' + lessThan operator = '<' + greaterThanEqual operator = '≥' + lessThanEqual operator = '≤' + pessimistic operator = '~' +) + func constraintEqual(v, c *Version) bool { return v.Equal(c) } diff --git a/vendor/github.com/hashicorp/go-version/go.mod b/vendor/github.com/hashicorp/go-version/go.mod deleted file mode 100644 index f528555..0000000 --- a/vendor/github.com/hashicorp/go-version/go.mod +++ /dev/null @@ -1 +0,0 @@ -module github.com/hashicorp/go-version diff --git a/vendor/github.com/hashicorp/go-version/version.go b/vendor/github.com/hashicorp/go-version/version.go index 8068834..e87df69 100644 --- a/vendor/github.com/hashicorp/go-version/version.go +++ b/vendor/github.com/hashicorp/go-version/version.go @@ -64,7 +64,6 @@ func newVersion(v string, pattern *regexp.Regexp) (*Version, error) { } segmentsStr := strings.Split(matches[1], ".") segments := make([]int64, len(segmentsStr)) - si := 0 for i, str := range segmentsStr { val, err := strconv.ParseInt(str, 10, 64) if err != nil { @@ -72,8 +71,7 @@ func newVersion(v string, pattern *regexp.Regexp) (*Version, error) { "Error parsing version: %s", err) } - segments[i] = int64(val) - si++ + segments[i] = val } // Even though we could support more than three segments, if we @@ -92,7 +90,7 @@ func newVersion(v string, pattern *regexp.Regexp) (*Version, error) { metadata: matches[10], pre: pre, segments: segments, - si: si, + si: len(segmentsStr), original: v, }, nil } @@ -390,3 +388,20 @@ func (v *Version) String() string { func (v *Version) Original() string { return v.original } + +// UnmarshalText implements encoding.TextUnmarshaler interface. +func (v *Version) UnmarshalText(b []byte) error { + temp, err := NewVersion(string(b)) + if err != nil { + return err + } + + *v = *temp + + return nil +} + +// MarshalText implements encoding.TextMarshaler interface. +func (v *Version) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} diff --git a/vendor/github.com/ryanuber/go-glob/go.mod b/vendor/github.com/ryanuber/go-glob/go.mod deleted file mode 100644 index f382035..0000000 --- a/vendor/github.com/ryanuber/go-glob/go.mod +++ /dev/null @@ -1 +0,0 @@ -module github.com/ryanuber/go-glob diff --git a/vendor/gopkg.in/yaml.v2/go.mod b/vendor/gopkg.in/yaml.v2/go.mod deleted file mode 100644 index 2cbb85a..0000000 --- a/vendor/gopkg.in/yaml.v2/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module gopkg.in/yaml.v2 - -go 1.15 - -require gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 diff --git a/vendor/modules.txt b/vendor/modules.txt index 04b47a2..2ea40c8 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,29 +1,38 @@ # github.com/beevik/etree v1.1.0 +## explicit github.com/beevik/etree -# github.com/bitrise-io/bitrise v0.0.0-20210519130014-380842fb41c1 +# github.com/bitrise-io/bitrise v0.0.0-20220719135434-7f794d69d858 +## explicit; go 1.16 github.com/bitrise-io/bitrise/models -# github.com/bitrise-io/bitrise-init v0.0.0-20210520122036-d213de321eb8 +# github.com/bitrise-io/bitrise-init v0.0.0-20220504131857-f00a24c7c8ba +## explicit; go 1.16 github.com/bitrise-io/bitrise-init/analytics github.com/bitrise-io/bitrise-init/models github.com/bitrise-io/bitrise-init/scanners/android github.com/bitrise-io/bitrise-init/steps github.com/bitrise-io/bitrise-init/utility -# github.com/bitrise-io/envman v0.0.0-20210517135508-b2b4fe89eac5 +# github.com/bitrise-io/envman v0.0.0-20220512153504-166d59151b78 +## explicit; go 1.16 github.com/bitrise-io/envman/models -# github.com/bitrise-io/go-android v0.0.0-20210913151943-e1ea0b4df36d -github.com/bitrise-io/go-android/cache -# github.com/bitrise-io/go-steputils v0.0.0-20210924114124-851d30b88892 +# github.com/bitrise-io/go-android/v2 v2.0.0-alpha.3 +## explicit; go 1.16 +github.com/bitrise-io/go-android/v2/cache +# github.com/bitrise-io/go-steputils v1.0.2 +## explicit; go 1.15 github.com/bitrise-io/go-steputils/cache github.com/bitrise-io/go-steputils/command/gems +github.com/bitrise-io/go-steputils/command/rubycommand github.com/bitrise-io/go-steputils/input -github.com/bitrise-io/go-steputils/ruby github.com/bitrise-io/go-steputils/step github.com/bitrise-io/go-steputils/stepconf github.com/bitrise-io/go-steputils/tools -# github.com/bitrise-io/go-utils v0.0.0-20210924090918-3e7a04d0da9d +# github.com/bitrise-io/go-steputils/v2 v2.0.0-alpha.8 +## explicit; go 1.16 +github.com/bitrise-io/go-steputils/v2/ruby +# github.com/bitrise-io/go-utils v1.0.2 +## explicit; go 1.13 github.com/bitrise-io/go-utils/colorstring github.com/bitrise-io/go-utils/command -github.com/bitrise-io/go-utils/env github.com/bitrise-io/go-utils/errorutil github.com/bitrise-io/go-utils/filedownloader github.com/bitrise-io/go-utils/fileutil @@ -33,20 +42,33 @@ github.com/bitrise-io/go-utils/pathutil github.com/bitrise-io/go-utils/pointers github.com/bitrise-io/go-utils/retry github.com/bitrise-io/go-utils/sliceutil -# github.com/bitrise-io/go-xcode v0.0.0-20210521101355-fb6a1eb6e05b +# github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.8 +## explicit; go 1.16 +github.com/bitrise-io/go-utils/v2/command +github.com/bitrise-io/go-utils/v2/env +github.com/bitrise-io/go-utils/v2/log +# github.com/bitrise-io/go-xcode v1.0.9 +## explicit; go 1.15 github.com/bitrise-io/go-xcode/appleauth github.com/bitrise-io/go-xcode/devportalservice -# github.com/bitrise-io/stepman v0.0.0-20210517135458-203f7a48d37a +# github.com/bitrise-io/stepman v0.0.0-20220718172049-e5ae0a09c2f2 +## explicit; go 1.16 github.com/bitrise-io/stepman/models -# github.com/hashicorp/go-cleanhttp v0.5.1 +# github.com/hashicorp/go-cleanhttp v0.5.2 +## explicit; go 1.13 github.com/hashicorp/go-cleanhttp -# github.com/hashicorp/go-retryablehttp v0.7.0 +# github.com/hashicorp/go-retryablehttp v0.7.1 +## explicit; go 1.13 github.com/hashicorp/go-retryablehttp -# github.com/hashicorp/go-version v1.3.0 +# github.com/hashicorp/go-version v1.6.0 +## explicit github.com/hashicorp/go-version # github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 +## explicit github.com/kballard/go-shellquote # github.com/ryanuber/go-glob v1.0.0 +## explicit github.com/ryanuber/go-glob # gopkg.in/yaml.v2 v2.4.0 +## explicit; go 1.15 gopkg.in/yaml.v2