Exemple #1
0
// Compress make archive from repository branch
func (repo *Repository) Compress(config *Config, d driver.Driver, p *packages.Composer) error {
	// Prepare path and archive path
	gd := &download.Git{
		Name:    p.Name,
		Version: p.Version,
		URL:     repo.URL,
		Source:  p.Source,
		DistDir: config.DistDir,
	}
	gd.Prepare()
	// Prepare compression
	cz := compress.Zip{
		SourcePath: gd.SourcePath,
	}
	cz.Prepare()
	// Run download
	if !gd.PathExist && !cz.IsExist {
		err := gd.Run()
		if err != nil {
			return err
		}
	}
	// Run compression
	if gd.PathExist && !cz.IsExist {
		err := cz.Run()
		if err != nil {
			return err
		}
	}

	if cz.IsExist {
		host := config.File.Homepage
		if config.File.Archive.PrefixURL != "" {
			host = config.File.Archive.PrefixURL
		}

		p.Dist = map[string]string{
			"type":      cz.Format,
			"url":       host + "/" + path.Join(config.File.Archive.Directory, strings.Replace(cz.TargetPath, gd.DistDir, "", -1)),
			"reference": d.GetReference(),
			"shasum":    hashFile(cz.TargetPath),
		}
	}

	return nil
}
Exemple #2
0
// Run start update repositories
func (repo *Repository) Run(config *Config) map[string]map[string]packages.Composer {
	var d driver.Driver
	switch repo.Type {
	case "git", "vcs", "composer":
		d = &driver.Git{URL: repo.URL}
		err := d.Run()
		if err != nil {
			utils.Logger.Error(err)
		}

		pm := make(map[string]map[string]packages.Composer)
		if len(pm[d.GetName()]) == 0 {
			pm[d.GetName()] = make(map[string]packages.Composer)
		}

		if config.File.Archive.Directory == "" {
			pm[d.GetName()] = d.GetPackages()
			return pm
		}

		flag := make(chan bool, len(d.GetPackages()))
		ch := make(chan packages.Composer)

		for _, value := range d.GetPackages() {
			go func(p packages.Composer) {
				flag <- true
				defer func() {
					<-flag
					ch <- p
				}()

				if config.File.Archive.SkipDev && !p.Stability {
					return
				}

				switch config.File.Archive.Format {
				case "zip":
					repo.Compress(config, d, &p)
				case "tar":
					utils.Logger.Error("Tar format not sopported yet!")
				default:
					utils.Logger.Errorf("Invalid archive format: %s!", config.File.Archive.Format)
				}
			}(value)
		}

		for i := 0; i < len(d.GetPackages()); i++ {
			p := <-ch
			pm[d.GetName()][p.Version] = p
		}

		return pm
	case "bitbucket", "git-bitbucket":
		utils.Logger.Error("Bitbucket driver not supported yet!")
	default:
		utils.Logger.Error("Driver was not specified!")
	}

	return map[string]map[string]packages.Composer{}
}