You've already forked goreleaser
							
							
				mirror of
				https://github.com/goreleaser/goreleaser.git
				synced 2025-10-30 23:58:09 +02:00 
			
		
		
		
	Allow for patterns in default file patterns
This commit is contained in:
		
							
								
								
									
										0
									
								
								config/.test/2/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								config/.test/2/README.md
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								config/.test/3/LICENCE.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								config/.test/3/LICENCE.txt
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								config/.test/3/README.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								config/.test/3/README.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -3,6 +3,7 @@ package config | ||||
| import ( | ||||
| 	"errors" | ||||
| 	"io/ioutil" | ||||
| 	"log" | ||||
| 	"os" | ||||
| 	"path" | ||||
| 	"path/filepath" | ||||
| @@ -11,7 +12,10 @@ import ( | ||||
| 	yaml "gopkg.in/yaml.v1" | ||||
| ) | ||||
|  | ||||
| var emptyBrew = Homebrew{} | ||||
| var ( | ||||
| 	emptyBrew    = Homebrew{} | ||||
| 	filePatterns = []string{"LICENCE.*", "LICENSE.*", "README.*"} | ||||
| ) | ||||
|  | ||||
| // Homebrew contains the brew section | ||||
| type Homebrew struct { | ||||
| @@ -70,10 +74,13 @@ func fix(config ProjectConfig) ProjectConfig { | ||||
| 	if len(config.Files) == 0 { | ||||
| 		config.Files = []string{} | ||||
|  | ||||
| 		for _, f := range []string{"README.md", "LICENCE.md", "LICENSE.md"} { | ||||
| 			if _, err := os.Stat(f); err == nil { | ||||
| 				config.Files = append(config.Files, f) | ||||
| 		for _, pattern := range filePatterns { | ||||
| 			matches, err := globPath(pattern) | ||||
| 			if err != nil { | ||||
| 				log.Fatalf("Error searching for %q: %v", pattern, err) | ||||
| 			} | ||||
|  | ||||
| 			config.Files = append(config.Files, matches...) | ||||
| 		} | ||||
| 	} | ||||
| 	if config.Token == "" { | ||||
|   | ||||
| @@ -22,18 +22,41 @@ func TestFixConfigMissingFiles(t *testing.T) { | ||||
| 	assert := assert.New(t) | ||||
| 	config := fix(ProjectConfig{}) | ||||
|  | ||||
| 	assert.NotContains(config.Files, "README.md") | ||||
| 	assert.NotContains(config.Files, "LICENSE.md") | ||||
| 	assert.NotContains(config.Files, "LICENCE.md") | ||||
| 	assert.Equal([]string{}, config.Files) | ||||
| } | ||||
|  | ||||
| func TestFixConfigNoMissingFiles(t *testing.T) { | ||||
| func TestFixConfigUSENMarkdown(t *testing.T) { | ||||
| 	assert := assert.New(t) | ||||
|  | ||||
| 	os.Chdir("./.test") | ||||
| 	config := fix(ProjectConfig{}) | ||||
| 	cwd, _ := os.Getwd() | ||||
| 	os.Chdir("./.test/1") | ||||
|  | ||||
| 	assert.Contains(config.Files, "README.md") | ||||
| 	assert.Contains(config.Files, "LICENSE.md") | ||||
| 	assert.Contains(config.Files, "LICENCE.md") | ||||
| 	config := fix(ProjectConfig{}) | ||||
| 	assert.Equal([]string{"LICENSE.md", "README.md"}, config.Files) | ||||
|  | ||||
| 	os.Chdir(cwd) | ||||
| } | ||||
|  | ||||
| func TestFixConfigRealENMarkdown(t *testing.T) { | ||||
| 	assert := assert.New(t) | ||||
|  | ||||
| 	cwd, _ := os.Getwd() | ||||
| 	os.Chdir("./.test/2") | ||||
|  | ||||
| 	config := fix(ProjectConfig{}) | ||||
| 	assert.Equal([]string{"LICENCE.md", "README.md"}, config.Files) | ||||
|  | ||||
| 	os.Chdir(cwd) | ||||
| } | ||||
|  | ||||
| func TestFixConfigArbitratryENTXT(t *testing.T) { | ||||
| 	assert := assert.New(t) | ||||
|  | ||||
| 	cwd, _ := os.Getwd() | ||||
| 	os.Chdir("./.test/3") | ||||
|  | ||||
| 	config := fix(ProjectConfig{}) | ||||
| 	assert.Equal([]string{"LICENCE.txt", "README.txt"}, config.Files) | ||||
|  | ||||
| 	os.Chdir(cwd) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user