-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure that if a package file has been changed, that a related def…
…inition/collection file has also been changed (#668) * list changed files Signed-off-by: Mauro Morales <[email protected]> * simplify Signed-off-by: Mauro Morales <[email protected]> * simplify Signed-off-by: Mauro Morales <[email protected]> * test file Signed-off-by: Mauro Morales <[email protected]> * Add bump validator Signed-off-by: Mauro Morales <[email protected]> * wrong dir Signed-off-by: Mauro Morales <[email protected]> * go version 1.23 Signed-off-by: Mauro Morales <[email protected]> * force go version Signed-off-by: Mauro Morales <[email protected]> * test Signed-off-by: Mauro Morales <[email protected]> * revert test changes Signed-off-by: Mauro Morales <[email protected]> * Do the check also on amd Signed-off-by: Mauro Morales <[email protected]> * use a new job Signed-off-by: Mauro Morales <[email protected]> * add checkout step Signed-off-by: Mauro Morales <[email protected]> * Use hasPrefix Signed-off-by: Mauro Morales <[email protected]> --------- Signed-off-by: Mauro Morales <[email protected]>
- Loading branch information
1 parent
216a85c
commit 15ce83c
Showing
4 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/kairos-io/packages/tools/bump-validator | ||
|
||
go 1.21.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
// isDefinitionFile checks if the basename of the file is definition.yaml or collection.yaml | ||
func isDefinitionFile(file string) bool { | ||
basename := filepath.Base(file) | ||
return basename == "definition.yaml" || basename == "collection.yaml" | ||
} | ||
|
||
// reduceRelated keeps only the definition files that are siblings or in a parten directory of the given file | ||
func reduceRelated(file string, files []string) []string { | ||
var relatedFiles []string | ||
dir := filepath.Dir(file) | ||
for _, f := range files { | ||
otherDir := filepath.Dir(f) | ||
if isDefinitionFile(f) && strings.HasPrefix(dir, otherDir) { | ||
relatedFiles = append(relatedFiles, f) | ||
} | ||
} | ||
return relatedFiles | ||
} | ||
|
||
func main() { | ||
var missingVersionBump bool | ||
|
||
files := os.Args[1:] | ||
for _, file := range files { | ||
// fmt.Println("Processing file ", file) | ||
if isDefinitionFile(file) { | ||
// fmt.Println("Skipping definition file ", file) | ||
continue | ||
} | ||
|
||
relatedFiles := reduceRelated(file, files) | ||
if len(relatedFiles) == 0 { | ||
missingVersionBump = true | ||
fmt.Println("Error: Version bump missing for file ", file) | ||
} | ||
} | ||
|
||
if missingVersionBump { | ||
os.Exit(1) | ||
} | ||
} |