Skip to content

Commit

Permalink
feat(CI)
Browse files Browse the repository at this point in the history
  • Loading branch information
loan-mgt committed Jan 10, 2024
1 parent 0d4830e commit f2e3abd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ jobs:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: |
Release notes and description go here.
draft: false
CLI tool to validate flyway migration for CI/CD
draft: true
prerelease: false

- name: Debug Release
Expand Down
Binary file removed dfv
Binary file not shown.
15 changes: 10 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,20 @@ func main() {
fmt.Printf("Conditions: isMigrationFile: %t, isAlphabeticallyLast: %t\n", isMigrationFile(relativeFilePath), isAlphabeticallyLast(relativeFilePath, migrationDir))
}

switch status {
case "M":
// Regex for <X><score>
if isMatch(status, `^M`) {
if isMigrationFile(relativeFilePath) {
validationErrors = append(validationErrors, fmt.Sprintf("Error: Cannot modify migration file after it was applied: %s\n\t%s", relativeFilePath, newFilePath))
}
case "A":
} else if isMatch(status, `^A`) {
if isMigrationFile(relativeFilePath) && !isAlphabeticallyLast(relativeFilePath, migrationDir) {
validationErrors = append(validationErrors, fmt.Sprintf("Error: Added migration file not alphabetically last: %s\n\t%s", relativeFilePath, newFilePath))
}
case "D":
} else if isMatch(status, `^D`) {
if isMigrationFile(relativeFilePath) {
validationErrors = append(validationErrors, fmt.Sprintf("Error: Cannot remove migration file after it was applied: %s\n\t%s", relativeFilePath, newFilePath))
}
case "R":
} else if isMatch(status, `^R`) {
if isMigrationFile(relativeFilePath) {
validationErrors = append(validationErrors, fmt.Sprintf("Error: Cannot rename migration file after it was applied: %s\n\t%s", relativeFilePath, newFilePath))
}
Expand Down Expand Up @@ -167,6 +167,11 @@ func getMigrationFiles(migrationDir string) ([]string, error) {
return files, err
}

func isMatch(input, pattern string) bool {
re := regexp.MustCompile(pattern)
return re.MatchString(input)
}

func printHelp() {
fmt.Println("Usage: dum-flyway-validate [OPTIONS]")
fmt.Println(" --migration-dir Specify the migration directory (default: current directory)")
Expand Down

0 comments on commit f2e3abd

Please sign in to comment.