add validation of master changelog
@@ -35,8 +35,6 @@ func main() {
defer templateFile.Close()
// parse CHANGE_TEMPLATE
- // TODO add validation dates in ascending order
- // TODO add validation no duplicate versions
scanner := bufio.NewScanner(templateFile)
changeArray := []Change{}
changeStrings := []string{}
@@ -62,6 +60,11 @@ func main() {
}
}
+ if !validateChangelog(changeArray) {
+ fmt.Println("Master Changelog is invalid.")
+ return
+ }
+
// Create formatted strings for each log
amazonLinuxChangeString := getAmazonLinuxChangeString(changeArray)
ubuntuChangeString := getUbuntuChangeString(changeArray)
@@ -93,6 +96,28 @@ func main() {
rewriteChangelog(AMAZON_LINUX, completeAmazonLinuxChangeString)
}
+func validateChangelog(allChange []Change) bool {
+ //validate that all dates are in ascending order
+ for i := 1; i < len(allChange); i++ {
+ prevTime := allChange[i].Datetime
+ nextTime := allChange[i-1].Datetime
+ if !prevTime.Before(nextTime) {
+ fmt.Printf("datetimes out of order: %s should be after %s\n", prevTime.String(), nextTime.String())
+ return false
+ }
+ }
+ //validate that there are no duplicate versions
+ versionSet := make(map[string]bool)
+ for _, change := range allChange {
+ versionSet[change.Version] = true
+ }
+ if len(versionSet) != len(allChange) {
+ fmt.Printf("there's a duplicate version present\n")
+ return false
+ }
+ return true
+}
+
// format as follows:
//
// * Wed Jan 08 2020 Cameron Sparr <cssparr@amazon.com> - 1.36.0-1
