@@ -2,13 +2,8 @@ package cli
22
33import (
44 "fmt"
5- "path/filepath"
6- "time"
75
8- "github.com/bitrise-io/go-utils/command/git"
96 "github.com/bitrise-io/go-utils/log"
10- "github.com/bitrise-io/go-utils/pathutil"
11- "github.com/bitrise-io/go-utils/retry"
127 "github.com/bitrise-io/stepman/models"
138 "github.com/bitrise-io/stepman/stepman"
149 "github.com/urfave/cli"
@@ -112,124 +107,10 @@ func stepInfo(c *cli.Context) error {
112107func QueryStepInfo (library , id , version string , log stepman.Logger ) (models.StepInfoModel , error ) {
113108 switch library {
114109 case "git" :
115- return QueryStepInfoFromGit (id , version )
110+ return stepman . QueryStepInfoFromGit (id , version )
116111 case "path" :
117- return QueryStepInfoFromPath (id )
112+ return stepman . QueryStepInfoFromPath (id )
118113 default : // library step
119- return QueryStepInfoFromLibrary (library , id , version , log )
114+ return stepman . QueryStepInfoFromLibrary (library , id , version , log )
120115 }
121116}
122-
123- // QueryStepInfoFromGit returns step info from git source.
124- func QueryStepInfoFromGit (gitURL , tagOrBranch string ) (models.StepInfoModel , error ) {
125- tmpStepDir , err := pathutil .NormalizedOSTempDirPath ("__step__" )
126- if err != nil {
127- return models.StepInfoModel {}, fmt .Errorf ("query git step info: create tmp dir: %s" , err )
128- }
129-
130- if tagOrBranch == "" {
131- tagOrBranch = "master"
132- }
133-
134- if err := retry .Times (2 ).Wait (3 * time .Second ).Try (func (attempt uint ) error {
135- repo , err := git .New (tmpStepDir )
136- if err != nil {
137- return err
138- }
139- return repo .CloneTagOrBranch (gitURL , tagOrBranch ).Run ()
140- }); err != nil {
141- return models.StepInfoModel {}, fmt .Errorf ("query git step info: clone %s: %s" , gitURL , err )
142- }
143-
144- stepDefinitionPth := filepath .Join (tmpStepDir , "step.yml" )
145- if exist , err := pathutil .IsPathExists (stepDefinitionPth ); err != nil {
146- return models.StepInfoModel {}, fmt .Errorf ("query git step info: check if step.yml exist: %s" , err )
147- } else if ! exist {
148- return models.StepInfoModel {}, fmt .Errorf ("query git step info: step.yml does not exist at %s" , stepDefinitionPth )
149- }
150-
151- step , err := stepman .ParseStepDefinition (stepDefinitionPth , false )
152- if err != nil {
153- return models.StepInfoModel {}, fmt .Errorf ("query git step info: parse step.yml (%s): %s" , stepDefinitionPth , err )
154- }
155-
156- return models.StepInfoModel {
157- Library : "git" ,
158- ID : gitURL ,
159- Version : tagOrBranch ,
160- OriginalVersion : "" ,
161- LatestVersion : "" ,
162- GroupInfo : models.StepGroupInfoModel {},
163- Step : step ,
164- DefinitionPth : stepDefinitionPth ,
165- }, nil
166- }
167-
168- // QueryStepInfoFromPath returns step info from a local path source
169- func QueryStepInfoFromPath (dir string ) (models.StepInfoModel , error ) {
170- stepDefinitionPth := filepath .Join (dir , "step.yml" )
171- if exist , err := pathutil .IsPathExists (stepDefinitionPth ); err != nil {
172- return models.StepInfoModel {}, fmt .Errorf ("query local step info: check if step.yml exist: %s" , err )
173- } else if ! exist {
174- return models.StepInfoModel {}, fmt .Errorf ("query local step info: step.yml does not exist at %s" , stepDefinitionPth )
175- }
176-
177- step , err := stepman .ParseStepDefinition (stepDefinitionPth , false )
178- if err != nil {
179- return models.StepInfoModel {}, fmt .Errorf ("query local step info: parse step.yml (%s): %s" , stepDefinitionPth , err )
180- }
181-
182- return models.StepInfoModel {
183- Library : "path" ,
184- ID : dir ,
185- Version : "" ,
186- OriginalVersion : "" ,
187- LatestVersion : "" ,
188- GroupInfo : models.StepGroupInfoModel {},
189- Step : step ,
190- DefinitionPth : stepDefinitionPth ,
191- }, nil
192- }
193-
194- // QueryStepInfoFromLibrary returns a step version based on the version string, which can be latest or locked to major or minor versions
195- func QueryStepInfoFromLibrary (library , id , version string , log stepman.Logger ) (models.StepInfoModel , error ) {
196- // Check if setup was done for collection
197- if exist , err := stepman .RootExistForLibrary (library ); err != nil {
198- return models.StepInfoModel {}, fmt .Errorf ("query steplib step info: check if setup was done for %s: %s" , library , err )
199- } else if ! exist {
200- if err := stepman .SetupLibrary (library , log ); err != nil {
201- return models.StepInfoModel {}, fmt .Errorf ("query steplib step info: setup %s: %s" , library , err )
202- }
203- }
204-
205- stepVersion , err := stepman .ReadStepVersionInfo (library , id , version )
206- if err != nil {
207- return models.StepInfoModel {}, fmt .Errorf ("query steplib step info: read step information: %s" , err )
208- }
209-
210- route , found := stepman .ReadRoute (library )
211- if ! found {
212- return models.StepInfoModel {}, fmt .Errorf ("query steplib step info: no route found for %s" , library )
213- }
214-
215- stepDir := stepman .GetStepCollectionDirPath (route , id , stepVersion .Version )
216- stepDefinitionPth := filepath .Join (stepDir , "step.yml" )
217-
218- infoPath := stepman .GetStepGlobalInfoPath (route , id )
219-
220- groupInfo , _ , err := stepman .ParseStepGroupInfoModel (infoPath )
221- if err != nil {
222- return models.StepInfoModel {}, err
223- }
224-
225- return models.StepInfoModel {
226- Library : library ,
227- ID : id ,
228- Version : stepVersion .Version ,
229- OriginalVersion : "" ,
230- LatestVersion : stepVersion .LatestAvailableVersion ,
231- GroupInfo : groupInfo ,
232- Step : stepVersion .Step ,
233- DefinitionPth : stepDefinitionPth ,
234- }, nil
235- }
0 commit comments