diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index f5c7674c5..681a14efa 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -6,6 +6,29 @@ concurrency: on: pull_request: jobs: + validate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v42 + with: + files: packages/** + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: 1.21.1 + - name: Validate changed packages bump version + if: steps.changed-files.outputs.any_changed == 'true' + env: + PKG_ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} + run: | + cd tools/bump-validator + go run main.go $PKG_ALL_CHANGED_FILES + build-arm64: runs-on: fast env: @@ -44,6 +67,7 @@ jobs: values: values/arm64.yaml buildx: true platform: linux/arm64 + build: runs-on: fast env: diff --git a/tools/bump-validator/bump-validator b/tools/bump-validator/bump-validator new file mode 100755 index 000000000..1f9ffbd26 Binary files /dev/null and b/tools/bump-validator/bump-validator differ diff --git a/tools/bump-validator/go.mod b/tools/bump-validator/go.mod new file mode 100644 index 000000000..c503503e3 --- /dev/null +++ b/tools/bump-validator/go.mod @@ -0,0 +1,3 @@ +module github.com/kairos-io/packages/tools/bump-validator + +go 1.21.1 diff --git a/tools/bump-validator/main.go b/tools/bump-validator/main.go new file mode 100644 index 000000000..d4868d919 --- /dev/null +++ b/tools/bump-validator/main.go @@ -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) + } +}