コード例 #1
0
ファイル: os.go プロジェクト: carriercomm/dlite
func getReleases() ([]semver.Version, map[string]Version, error) {
	res, err := http.Get("https://api.github.com/repos/nlf/dhyve-os/releases")
	if err != nil {
		return nil, nil, err
	}

	defer res.Body.Close()
	vers := []Version{}
	decoder := json.NewDecoder(res.Body)
	err = decoder.Decode(vers)
	if err != nil {
		return nil, nil, err
	}

	versions := map[string]Version{}
	rng, err := semver.ParseRange(">= 3.0.0-beta0")
	if err != nil {
		return nil, nil, err
	}

	svers := []semver.Version{}
	for _, vers := range versions {
		v := semver.MustParse(vers.Tag)
		if rng(v) {
			versions[vers.Tag] = vers
			svers = append(svers, v)
		}
	}

	semver.Sort(svers)
	return svers, versions, nil
}
コード例 #2
0
// SortBySemver returns the provided releases, ordered by semantic versioning,
// in descending order i.e. [4.2.3, 1.2.1, 1.2.0]
// If a version cannot be parsed as semantic versioning, this is logged to stdout
// and that release is not returned. No error is returned in this case.
// Therefore the number of returned releases may be fewer than the number of
// provided releases.
func (s Sorter) SortBySemver(input []pivnet.Release) ([]pivnet.Release, error) {
	var versions []semver.Version
	versionsToReleases := make(map[string]pivnet.Release)

	for _, release := range input {
		asSemver, err := s.semverConverter.ToValidSemver(release.Version)
		if err != nil {
			s.logger.Info(fmt.Sprintf(
				"failed to parse release version as semver: '%s'",
				release.Version,
			))
			continue
		}

		versionsToReleases[asSemver.String()] = release
		versions = append(versions, asSemver)
	}

	semver.Sort(versions)

	sortedStrings := toStrings(versions)

	sortedReleases := make([]pivnet.Release, len(sortedStrings))

	count := len(sortedStrings)
	for i, v := range sortedStrings {
		// perform reversal so we return descending, not ascending
		sortedReleases[count-i-1] = versionsToReleases[v]
	}

	return sortedReleases, nil
}
コード例 #3
0
ファイル: main.go プロジェクト: xchapter7x/versioning
func main() {
	var (
		e           error
		l           string
		versionList semver.Versions
	)
	exec.Command("git", "fetch", "--tags").Run()
	cmd := exec.Command("git", "tag", "-l")
	b, _ := cmd.Output()
	bfr := bytes.NewBuffer(b)

	for e == nil {
		l, e = bfr.ReadString('\n')

		if v, ve := semver.Make(strings.Replace(strings.TrimSpace(l), "v", "", -1)); ve == nil {
			versionList = append(versionList, v)
		}
	}
	semver.Sort(versionList)
	currentVersion := versionList[len(versionList)-1]

	switch os.Args[1] {
	case "bump_patch":
		currentVersion.Patch++

	case "bump_minor":
		currentVersion.Patch = 0
		currentVersion.Minor++

	case "bump_major":
		currentVersion.Patch = 0
		currentVersion.Minor = 0
		currentVersion.Major++
	}
	fmt.Printf("v%s", currentVersion)
}
コード例 #4
0
ファイル: main.go プロジェクト: LeanKit-Labs/drone-cowpoke
func main() {
	fmt.Println("starting drone-rancher-catalog...")

	var catalog = catalog{}
	plugin.Param("workspace", &catalog.workspace)
	plugin.Param("repo", &catalog.repo)
	plugin.Param("build", &catalog.build)
	plugin.Param("vargs", &catalog.vargs)
	plugin.MustParse()

	check(catalog.vargs.DockerRepo, "ERROR: docker_repo: Docker Registry Repo to read tags from, not specified")
	check(catalog.vargs.DockerUsername, "ERROR: docker_username: Docker Registry Username not specified")
	check(catalog.vargs.DockerPassword, "ERROR: docker_password: Docker Registry Password not specified")
	check(catalog.vargs.CatalogRepo, "ERROR: catalog_repo: GitHub Catalog Repo not specified")
	check(catalog.vargs.GitHubToken, "ERROR: github_token: GitHub User Token not specified")
	check(catalog.vargs.CowpokeURL, "ERROR: cowpoke_url: cowpoke url not specified")
	check(catalog.vargs.RancherCatalogName, "ERROR: rancher_catalog_name: catalog name in rancher is not specified")

	if len(catalog.vargs.DockerURL) == 0 {
		catalog.vargs.DockerURL = "https://registry.hub.docker.com/"
	}
	if len(catalog.vargs.GitHubUser) == 0 {
		catalog.vargs.GitHubUser = catalog.build.Author
	}
	if len(catalog.vargs.GitHubEmail) == 0 {
		catalog.vargs.GitHubEmail = catalog.build.Email
	}

	// create a dir outside the workspace
	if !exists(baseDir) {
		os.Mkdir(baseDir, 0755)
	}

	catalog.cloneCatalogRepo()
	os.Chdir(repoDir)
	catalog.gitConfigureEmail()
	catalog.gitConfigureUser()

	if !exists("./templates") {
		os.Mkdir("./templates", 0755)
	}

	dockerComposeTmpl := catalog.parseTemplateFile(dockerComposeTemplateFile)
	rancherComposeTmpl := catalog.parseTemplateFile(rancherComposeTemplateFile)
	configTmpl := catalog.parseTemplateFile(configTemplateFile)
	upgradeTags := getTagsFromYaml(catalog.workspace)
	tags := catalog.getTags()
	tbb := catalog.TagsByBranch(tags)

	var cowpokeRequests []*http.Request
	var catalogCreationCheckRequests []*http.Request

	fmt.Println("Creating Catalog Templates for:")
	for branch := range tbb.branches {
		var count int
		var last *Tag

		// create branch dir
		branchDir := fmt.Sprintf("./templates/%s", branch)
		if !exists(branchDir) {
			os.Mkdir(branchDir, 0755)
		}

		// sort semver so we can count builds in a feature branch
		var vKeys []semver.Version
		for k := range tbb.branches[branch].versions {
			version, err := semver.Parse(k)
			if err != nil {
				fmt.Printf("Error parsing version %v \n", err)
				continue
			}
			vKeys = append(vKeys, version)
		}
		semver.Sort(vKeys)
		for _, version := range vKeys {
			// sort builds to count in order
			var bKeys []int
			ver := version.String()
			for k := range tbb.branches[branch].versions[ver].builds {
				bKeys = append(bKeys, k)
			}
			sort.Ints(bKeys)

			for _, build := range bKeys {
				tbb.branches[branch].versions[ver].builds[build].Count = count

				// create dir structure
				buildDir := fmt.Sprintf("%s/%d", branchDir, count)
				if !exists(buildDir) {
					fmt.Printf("  %d:%s %s-%d\n", count, branch, ver, build)
					os.Mkdir(buildDir, 0755)
				}

				// create docker-compose.yml and rancher-compose.yml from template
				// don't generate files if they already exist
				dockerComposeTarget := fmt.Sprintf("%s/docker-compose.yml", buildDir)
				if !exists(dockerComposeTarget) {
					catalog.executeTemplate(dockerComposeTarget, dockerComposeTmpl, tbb.branches[branch].versions[ver].builds[build])
				}
				rancherComposeTarget := fmt.Sprintf("%s/rancher-compose.yml", buildDir)
				if !exists(rancherComposeTarget) {
					catalog.executeTemplate(rancherComposeTarget, rancherComposeTmpl, tbb.branches[branch].versions[ver].builds[build])
				}

				last = tbb.branches[branch].versions[ver].builds[build]
				count++
			}
			if stringInSlice(last.Tag, upgradeTags) {
				//count was already incremented so it needs to be decremented for the cowpoke request.
				//it is important for iteration that there be the same number of elements in both of these arrays
				//Therefore even if buildCatalogCheckRequest returns nil we add it to the slice. The nil check happens doRequest
				catalogCreationCheckRequests = append(catalogCreationCheckRequests, buildCatalogCreationCheckRequest(catalog.vargs.CatalogRepo, branch, count-1, catalog.vargs.GitHubToken))
				cowpokeRequests = append(cowpokeRequests, cowpokeRequest(count-1, branch, catalog.vargs.CatalogRepo, catalog.vargs.RancherCatalogName, catalog.vargs.GitHubToken, catalog.vargs.CowpokeURL, catalog.vargs.BearerToken))
			}

		}

		// create config.yml from temlplate
		configTarget := fmt.Sprintf("%s/config.yml", branchDir)
		catalog.executeTemplate(configTarget, configTmpl, last)

		// Icon file
		copyIcon(iconFileBase, branchDir)
	}
	// TODO: Delete dir/files if tags don't exist anymore. Need to maintian build dir numbering

	if catalog.gitChanged() {
		catalog.addCatalogRepo()
		catalog.commitCatalogRepo()
		catalog.pushCatalogRepo()
	}
	client := &http.Client{
		Timeout: time.Second * 60,
	}
	time.Sleep(3000 * time.Millisecond) //give github time to be consisitent
	for index, request := range cowpokeRequests {
		doRequest(catalogCreationCheckRequests[index], request, client)
	}
	fmt.Println("... Finished drone-rancher-catalog")
}