mirror of
https://github.com/kairos-io/packages.git
synced 2025-07-16 00:06:32 +00:00
Make sure that if a package file has been changed, that a related definition/collection file has also been changed (#668)
* list changed files Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * simplify Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * simplify Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * test file Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Add bump validator Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * wrong dir Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * go version 1.23 Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * force go version Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * test Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * revert test changes Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Do the check also on amd Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * use a new job Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * add checkout step Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Use hasPrefix Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> --------- Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com>
This commit is contained in:
parent
216a85c779
commit
15ce83c3f4
24
.github/workflows/pr.yaml
vendored
24
.github/workflows/pr.yaml
vendored
@ -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:
|
||||
|
BIN
tools/bump-validator/bump-validator
Executable file
BIN
tools/bump-validator/bump-validator
Executable file
Binary file not shown.
3
tools/bump-validator/go.mod
Normal file
3
tools/bump-validator/go.mod
Normal file
@ -0,0 +1,3 @@
|
||||
module github.com/kairos-io/packages/tools/bump-validator
|
||||
|
||||
go 1.21.1
|
50
tools/bump-validator/main.go
Normal file
50
tools/bump-validator/main.go
Normal file
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user