Skip to content

Commit

Permalink
[JIRA EXT-294] feat: Orb Tools 11 Support #680
Browse files Browse the repository at this point in the history
[JIRA EXT-294] Orb Tools 11 Support
  • Loading branch information
KyleTryon authored Apr 8, 2022
2 parents 263902a + 6ba0caa commit 105d8f0
Showing 1 changed file with 48 additions and 11 deletions.
59 changes: 48 additions & 11 deletions cmd/orb.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type createOrbTestUI struct {

type orbProtectTemplateRelease struct {
ZipUrl string `json:"zipball_url"`
Name string `json:"name"`
}

func (ui createOrbTestUI) askUserToConfirm(message string) bool {
Expand Down Expand Up @@ -310,7 +311,7 @@ Please note that at this time all orbs created in the registry are world-readabl

orbInit := &cobra.Command{
Use: "init <path>",
Short: "Initialize a new orb.",
Short: "Initialize a new orb project.",
Long: ``,
RunE: func(_ *cobra.Command, _ []string) error {
return initOrb(opts)
Expand Down Expand Up @@ -1060,7 +1061,7 @@ func initOrb(opts orbOptions) error {

fmt.Printf("Downloading Orb Project Template into %s\n", orbPath)
httpClient := http.Client{}
req, err := httpClient.Get("https://api.github.com/repos/CircleCI-Public/Orb-Project-Template/tags")
req, err := httpClient.Get("https://api.github.com/repos/CircleCI-Public/Orb-Template/tags")
if err != nil {
return errors.Wrap(err, "Unexpected error")
}
Expand All @@ -1075,15 +1076,26 @@ func initOrb(opts orbOptions) error {
return errors.Wrap(err, "Unexpected error")
}

latestTag := tags[0].ZipUrl
resp, err := http.Get(latestTag)
// filter out any non-release tags
releaseTags := []orbProtectTemplateRelease{}
validTagRegex := regexp.MustCompile(`^v\d+\.\d+\.\d+$`)
for _, tag := range tags {
matched := validTagRegex.MatchString(tag.Name)
if matched {
releaseTags = append(releaseTags, tag)
}
}


latestRelease := releaseTags[0]
resp, err := http.Get(latestRelease.ZipUrl)
if err != nil {
return err
}
defer resp.Body.Close()

// Create the file
out, err := os.Create(filepath.Join(os.TempDir(), "orb-project-template.zip"))
out, err := os.Create(filepath.Join(os.TempDir(), "orb-template.zip"))
if err != nil {
return err
}
Expand All @@ -1095,7 +1107,7 @@ func initOrb(opts orbOptions) error {
return err
}

err = unzipToOrbPath(filepath.Join(os.TempDir(), "orb-project-template.zip"), orbPath)
err = unzipToOrbPath(filepath.Join(os.TempDir(), "orb-template.zip"), orbPath)
if err != nil {
return err
}
Expand Down Expand Up @@ -1297,13 +1309,24 @@ func initOrb(opts orbOptions) error {
return y[0]
}()

circleConfig, err := ioutil.ReadFile(path.Join(orbPath, ".circleci", "config.yml"))
circleConfigSetup, err := ioutil.ReadFile(path.Join(orbPath, ".circleci", "config.yml"))
if err != nil {
return err
}

circle := string(circleConfig)
err = ioutil.WriteFile(path.Join(orbPath, ".circleci", "config.yml"), []byte(orbTemplate(circle, projectName, ownerName, orbName, namespace)), 0644)
configSetupString := string(circleConfigSetup)
err = ioutil.WriteFile(path.Join(orbPath, ".circleci", "config.yml"), []byte(orbTemplate(configSetupString, projectName, ownerName, orbName, namespace)), 0644)
if err != nil {
return err
}

circleConfigDeploy, err := ioutil.ReadFile(path.Join(orbPath, ".circleci", "test-deploy.yml"))
if err != nil {
return err
}

configDeployString := string(circleConfigDeploy)
err = ioutil.WriteFile(path.Join(orbPath, ".circleci", "test-deploy.yml"), []byte(orbTemplate(configDeployString, projectName, ownerName, orbName, namespace)), 0644)
if err != nil {
return err
}
Expand All @@ -1312,12 +1335,24 @@ func initOrb(opts orbOptions) error {
if err != nil {
return err
}

readmeString := string(readme)
err = ioutil.WriteFile(path.Join(orbPath, "README.md"), []byte(orbTemplate(readmeString, projectName, ownerName, orbName, namespace)), 0644)
if err != nil {
return err
}

orbRoot, err := ioutil.ReadFile(path.Join(orbPath, "src", "@orb.yml"))
if err != nil {
return err
}

orbRootString := string(orbRoot)
err = ioutil.WriteFile(path.Join(orbPath, "src", "@orb.yml"), []byte(orbTemplate(orbRootString, projectName, ownerName, orbName, namespace)), 0644)
if err != nil {
return err
}

r, err := git.PlainInit(orbPath, false)
if err != nil {
return err
Expand Down Expand Up @@ -1401,9 +1436,11 @@ func initOrb(opts orbOptions) error {
return err
}

fmt.Printf("An initial commit has been created - please run \033[1;34m'git push origin %v'\033[0m to publish your first commit!\n", gitBranch)
fmt.Printf("An initial commit has been created - please run the following commands in a separate terminal window. \n")
fmt.Printf("\033[1;34m'git branch -M %v'\033[0m\n", gitBranch)
fmt.Printf("\033[1;34m'git push origin %v'\033[0m\n", gitBranch)
yprompt = &survey.Confirm{
Message: "I have pushed to my git repository using the above command",
Message: "I have pushed to my git repository using the above commands",
}
// We don't use this anywhere, but AskOne will fail if we don't give it a
// place to put the result.
Expand Down

0 comments on commit 105d8f0

Please sign in to comment.