示例#1
0
文件: http.go 项目: boldfield/goxc
func httpWalk(config *httpTaskConfig, fullPath string, fi os.FileInfo, err error, tp TaskParams) error {
	if err != nil {
		return err
	}
	if fi.IsDir() {
		return nil
	}
	versionDir := filepath.Join(tp.OutDestRoot, tp.Settings.GetFullVersionName())
	relativePath := strings.TrimPrefix(strings.Replace(fullPath, versionDir, "", -1), "/")
	if !tp.Settings.IsQuiet() {
		log.Printf("Considering %s", relativePath)
	}
	resourceGlobs := core.ParseCommaGlobs(config.includePatterns)
	excludeGlobs := core.ParseCommaGlobs(config.excludePatterns)
	matches := false
	for _, resourceGlob := range resourceGlobs {
		ok, err := filepath.Match(resourceGlob, fi.Name())
		if err != nil {
			return err
		}
		if ok {
			matches = true
		}
	}
	if matches == false {
		if !tp.Settings.IsQuiet() {
			log.Printf("Not including %s (for include patterns %s)", relativePath, strings.Join(resourceGlobs, ", "))
		}
		return nil
	}
	for _, excludeGlob := range excludeGlobs {
		ok, err := filepath.Match(excludeGlob, fi.Name())
		if err != nil {
			return err
		}
		if ok {
			if !tp.Settings.IsQuiet() {
				log.Printf("Excluding %s (for exclude pattern %s)", relativePath, excludeGlob)
			}
			return nil
		}
	}
	return httpUploadFile(config, fullPath, fi, tp)
}
示例#2
0
文件: bintray.go 项目: boldfield/goxc
func walkFunc(fullPath string, fi2 os.FileInfo, err error, reportFilename string, dirs []string, tp TaskParams, format string, report BtReport) error {
	if fi2.IsDir() || fi2.Name() == reportFilename {

		return nil
	}
	subject := tp.Settings.GetTaskSettingString(TASK_BINTRAY, "subject")
	user := tp.Settings.GetTaskSettingString(TASK_BINTRAY, "user")
	if user == "" {
		user = subject
	}
	apikey := tp.Settings.GetTaskSettingString(TASK_BINTRAY, "apikey")
	repository := tp.Settings.GetTaskSettingString(TASK_BINTRAY, "repository")
	pkg := tp.Settings.GetTaskSettingString(TASK_BINTRAY, "package")
	apiHost := tp.Settings.GetTaskSettingString(TASK_BINTRAY, "apihost")
	downloadsHost := tp.Settings.GetTaskSettingString(TASK_BINTRAY, "downloadshost")
	includeResources := tp.Settings.GetTaskSettingString(TASK_BINTRAY, "include")
	excludeResources := tp.Settings.GetTaskSettingString(TASK_BINTRAY, "exclude")
	versionDir := filepath.Join(tp.OutDestRoot, tp.Settings.GetFullVersionName())

	relativePath := strings.Replace(fullPath, versionDir, "", -1)
	relativePath = strings.TrimPrefix(relativePath, "/")
	fmt.Printf("relative path %s, full path %s\n", relativePath, fullPath)

	resourceGlobs := core.ParseCommaGlobs(includeResources)
	//log.Printf("IncludeGlobs: %v", resourceGlobs)
	excludeGlobs := core.ParseCommaGlobs(excludeResources)
	//log.Printf("ExcludeGlobs: %v", excludeGlobs)
	matches := false
	for _, resourceGlob := range resourceGlobs {
		ok, err := filepath.Match(resourceGlob, fi2.Name())
		if err != nil {
			return err
		}
		if ok {
			matches = true
		}
	}
	if matches == false {
		if !tp.Settings.IsQuiet() {
			log.Printf("Not included: %s (pattern %v)", relativePath, includeResources)
		}
		return nil
	}
	for _, excludeGlob := range excludeGlobs {
		ok, err := filepath.Match(excludeGlob, fi2.Name())
		if err != nil {
			return err
		}
		if ok {
			if !tp.Settings.IsQuiet() {
				log.Printf("Excluded: %s (pattern %v)", relativePath, excludeGlob)
			}
			return nil
		}
	}
	first := true

	parent := filepath.Dir(relativePath)
	//platform := strings.Replace(parent, "_", "/", -1)
	//fmt.Fprintf(f, "\n * **%s**:", platform)
	for _, d := range dirs {
		if d == parent {
			first = false
		}
	}
	if first {
		dirs = append(dirs, parent)
	}
	//fmt.Printf("relative path %s, platform %s\n", relativePath, parent)
	text := fi2.Name()
	/*
		text := strings.Replace(fi2.Name(), "_", "\\_", -1)
		if strings.HasSuffix(fi2.Name(), ".zip") {
			text = "zip"
		} else if strings.HasSuffix(fi2.Name(), ".deb") {
			text = "deb"
		} else if strings.HasSuffix(fi2.Name(), ".tar.gz") {
			text = "tar.gz"
		} else if fi2.Name() == tp.AppName || fi2.Name() == tp.AppName+".exe" {
			text = "executable"
		}
	*/
	//PUT /content/:subject/:repo/:package/:version/:path
	url := apiHost + "/content/" + subject + "/" + repository + "/" + pkg + "/" + tp.Settings.GetFullVersionName() + "/" + relativePath
	// for some reason there's no /pkg/ level in the downloads url.
	downloadsUrl := downloadsHost + "/content/" + subject + "/" + repository + "/" + relativePath + "?direct"
	contentType := httpc.GetContentType(text)
	resp, err := httpc.UploadFile("PUT", url, subject, user, apikey, fullPath, relativePath, contentType, !tp.Settings.IsQuiet())
	if err != nil {
		if serr, ok := err.(httpc.HttpError); ok {
			if serr.StatusCode == 409 {
				//conflict. skip
				//continue but dont publish.
				//TODO - provide an option to replace existing artifact
				//TODO - ?check exists before attempting upload?
				log.Printf("WARNING - file already exists. Skipping. %v", resp)
				return nil
			} else {
				return err
			}
		} else {
			return err
		}
	}
	if !tp.Settings.IsQuiet() {
		log.Printf("File uploaded. (expected empty map[]): %v", resp)
	}
	//commaIfRequired := ""
	if first {
		first = false
	} else {
		//commaIfRequired = ","
	}
	if format == "markdown" {
		text = strings.Replace(text, "_", "\\_", -1)
	}
	category := GetCategory(relativePath)
	download := BtDownload{text, downloadsUrl}
	v, ok := report.Categories[category]
	var existing []BtDownload
	if !ok {
		existing = []BtDownload{}
	} else {
		existing = *v
	}
	existing = append(existing, download)
	report.Categories[category] = &existing

	//_, err = fmt.Fprintf(f, "%s [[%s](%s)]", commaIfRequired, text, downloadsUrl)
	if err != nil {
		return err
	}
	err = publish(apiHost, user, apikey, subject, repository, pkg, tp.Settings.GetFullVersionName(), !tp.Settings.IsQuiet())
	return err
}
示例#3
0
文件: tasks.go 项目: boldfield/goxc
// run all given tasks
func RunTasks(workingDirectory string, destPlatforms []platforms.Platform, settings *config.Settings, maxProcessors int) error {
	if settings.IsVerbose() {
		log.Printf("Using Go root: %s", settings.GoRoot)
		log.Printf("looping through each platform")
	}
	appName := core.GetAppName(settings.AppName, workingDirectory)

	outDestRoot, err := core.GetOutDestRoot(appName, workingDirectory, settings.ArtifactsDest)
	if err != nil {
		return err
	}
	defer log.SetPrefix("[goxc] ")
	exclusions := ResolveAliases(settings.TasksExclude)
	appends := ResolveAliases(settings.TasksAppend)
	mains := ResolveAliases(settings.Tasks)
	all := ResolveAliases(settings.TasksPrepend)
	//log.Printf("prepending %v", all)
	all = append(all, mains...)
	all = append(all, appends...)

	//exclude by resolved task names (not by aliases)
	tasksToRun := []string{}
	for _, taskName := range all {
		if !core.ContainsString(exclusions, taskName) {
			tasksToRun = append(tasksToRun, taskName)
		}
	}
	//0.6 check all tasks are valid before continuing
	for _, taskName := range tasksToRun {
		if _, keyExists := allTasks[taskName]; !keyExists {
			if strings.HasPrefix(taskName, ".") {
				log.Printf("'%s' looks like a directory, not a task - specify 'working directory' with -wd option", taskName)
			}
			if e, _ := core.FileExists(taskName); e {
				log.Printf("'%s' looks like a directory, not a task - specify 'working directory' with -wd option", taskName)
			}
			if settings.IsVerbose() {
				log.Printf("Task '%s' does NOT exist!", taskName)
			}
			return errors.New("Task '" + taskName + "' does not exist")
		}
	}
	mainDirs := []string{}
	allPackages := []string{}
	if len(tasksToRun) == 1 && tasksToRun[0] == "toolchain" {
		log.Printf("Toolchain task only - not searching for main dirs")
		//mainDirs = []string{workingDirectory}
	} else {
		var err error
		excludes := core.ParseCommaGlobs(settings.MainDirsExclude)
		excludesSource := core.ParseCommaGlobs(settings.SourceDirsExclude)
		excludesSource = append(excludesSource, excludes...)
		allPackages, err = source.FindSourceDirs(workingDirectory, "", excludesSource, settings.IsVerbose())
		if err != nil || len(allPackages) == 0 {
			log.Printf("Warning: could not establish list of source packages. Using working directory")
			allPackages = []string{workingDirectory}
		}
		mainDirs, err = source.FindMainDirs(workingDirectory, excludes, settings.IsVerbose())
		if err != nil || len(mainDirs) == 0 {
			log.Printf("Warning: could not find any main dirs: %v", err)
		} else {
			if settings.IsVerbose() {
				log.Printf("Found 'main package' dirs (len %d): %v", len(mainDirs), mainDirs)
			}
		}
	}
	if settings.IsVerbose() {
		log.Printf("Running tasks: %v", tasksToRun)
		log.Printf("All packages: %v", allPackages)
	}
	for _, taskName := range tasksToRun {
		log.SetPrefix("[goxc:" + taskName + "] ")
		if settings.IsVerbose() {
			log.Printf("Running task %s with settings: %v", taskName, settings.TaskSettings[taskName])
		}
		err := runTask(taskName, destPlatforms, allPackages, mainDirs, appName, workingDirectory, outDestRoot, settings, maxProcessors)
		if err != nil {
			// TODO: implement 'force' option.
			log.Printf("Stopping after '%s' failed with error '%v'", taskName, err)
			return err
		} else {
			if !settings.IsQuiet() {
				log.Printf("Task %s succeeded", taskName)
			}
		}
	}
	return nil
}