示例#1
0
文件: github.go 项目: yl10/goxc
func ghWalkFunc(fullPath string, fi2 os.FileInfo, err error, reportFilename string, dirs []string, tp tasks.TaskParams, format string, report tasks.BtReport) error {
	excludeResources := tp.Settings.GetTaskSettingString(tasks.TASK_PUBLISH_GITHUB, "exclude")
	excludeGlobs := core.ParseCommaGlobs(excludeResources)
	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)
	if fi2.IsDir() {
		//check globs ...
		for _, excludeGlob := range excludeGlobs {
			ok, err := filepath.Match(excludeGlob, fi2.Name())
			if err != nil {
				return err
			}
			if ok {
				if tp.Settings.IsVerbose() {
					log.Printf("Excluded: %s (pattern %v)", relativePath, excludeGlob)
				}
				return filepath.SkipDir
			}
		}
		return nil
	}
	if fi2.Name() == reportFilename {
		return nil
	}
	owner := tp.Settings.GetTaskSettingString(tasks.TASK_PUBLISH_GITHUB, "owner")
	user := tp.Settings.GetTaskSettingString(tasks.TASK_PUBLISH_GITHUB, "user")
	if user == "" {
		user = owner
	}
	apikey := tp.Settings.GetTaskSettingString(tasks.TASK_PUBLISH_GITHUB, "apikey")
	repository := tp.Settings.GetTaskSettingString(tasks.TASK_PUBLISH_GITHUB, "repository")
	apiHost := tp.Settings.GetTaskSettingString(tasks.TASK_PUBLISH_GITHUB, "apihost")
	uploadApiHost := "https://uploads.github.com"
	downloadsHost := tp.Settings.GetTaskSettingString(tasks.TASK_PUBLISH_GITHUB, "downloadshost")
	includeResources := tp.Settings.GetTaskSettingString(tasks.TASK_PUBLISH_GITHUB, "include")

	resourceGlobs := core.ParseCommaGlobs(includeResources)
	//log.Printf("IncludeGlobs: %v", resourceGlobs)
	//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.IsVerbose() {
			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.IsVerbose() {
				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()
	version := tp.Settings.GetFullVersionName()
	isVerbose := tp.Settings.IsVerbose()
	isQuiet := tp.Settings.IsQuiet()
	contentType := httpc.GetContentType(text)

	prefix := tp.Settings.GetTaskSettingString(tasks.TASK_TAG, "prefix")
	tagName := prefix + version
	release, err := ghGetReleaseForTag(apiHost, owner, apikey, repository, tagName, isVerbose)
	if err != nil {
		return err
	}
	err = ghDoUpload(uploadApiHost, apikey, owner, repository, release, relativePath, fullPath, contentType, isVerbose, isQuiet)
	if err != nil {
		return err
	}
	if first {
		first = false
	} else {
		//commaIfRequired = ","
	}
	if format == "markdown" {
		text = strings.Replace(text, "_", "\\_", -1)
	}
	category := tasks.GetCategory(relativePath)
	downloadsUrl := downloadsHost + "/" + owner + "/" + repository + "/releases/download/" + version + "/" + relativePath + ""
	download := tasks.BtDownload{Text: text, RelativeLink: downloadsUrl}
	v, ok := report.Categories[category]
	var existing []tasks.BtDownload
	if !ok {
		existing = []tasks.BtDownload{}
	} else {
		existing = *v
	}
	existing = append(existing, download)
	report.Categories[category] = &existing

	return err
}
示例#2
0
文件: bintray.go 项目: yl10/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
}