|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "log" |
| 5 | + "os" |
| 6 | + "path/filepath" |
| 7 | + |
| 8 | + "github.com/cloudfoundry/runtime-ci/task-libs/bosh" |
| 9 | +) |
| 10 | + |
| 11 | +func main() { |
| 12 | + if len(os.Args) < 3 { |
| 13 | + log.Fatalf("Usage: %s <buildDir> <branchToCompare>", os.Args[0]) |
| 14 | + } |
| 15 | + |
| 16 | + buildDir := os.Args[1] |
| 17 | + branchToCompare := os.Args[2] |
| 18 | + |
| 19 | + content, err := os.ReadFile(filepath.Join(buildDir, "cf-deployment-main", "cf-deployment.yml")) |
| 20 | + if err != nil { |
| 21 | + log.Fatalf("Failed to read main branch cf-deployment.yml: %s", err) |
| 22 | + } |
| 23 | + |
| 24 | + mainManifest, err := bosh.NewManifestFromFile(content) |
| 25 | + if err != nil { |
| 26 | + log.Fatalf("Failed to unmarshal main branch cf-deployment.yml: %s", err) |
| 27 | + } |
| 28 | + |
| 29 | + content, err = os.ReadFile(filepath.Join(buildDir, "cf-deployment-"+branchToCompare, "cf-deployment.yml")) |
| 30 | + if err != nil { |
| 31 | + log.Fatalf("Failed to read %s branch cf-deployment.yml: %s", branchToCompare, err) |
| 32 | + } |
| 33 | + |
| 34 | + branchToCompareManifest, err := bosh.NewManifestFromFile(content) |
| 35 | + if err != nil { |
| 36 | + log.Fatalf("Failed to unmarshal %s branch cf-deployment.yml: %s", branchToCompare, err) |
| 37 | + } |
| 38 | + |
| 39 | + mainStemcell := mainManifest.Stemcells[0] |
| 40 | + branchToCompareStemcell := branchToCompareManifest.Stemcells[0] |
| 41 | + |
| 42 | + if mainStemcell.OS != branchToCompareStemcell.OS { |
| 43 | + log.Printf("%s branch stemcell OS (%s) is different to the main branch stemcell OS (%s). Proceeding.", |
| 44 | + branchToCompare, branchToCompareStemcell.OS, mainStemcell.OS) |
| 45 | + os.Exit(0) |
| 46 | + } |
| 47 | + |
| 48 | + result, err := branchToCompareStemcell.CompareVersion(mainStemcell) |
| 49 | + if err != nil { |
| 50 | + log.Fatalf("Failed to compare stemcell versions: %s", err) |
| 51 | + } |
| 52 | + |
| 53 | + if result == -1 { |
| 54 | + log.Fatalf("%s branch stemcell version (%s) is behind the main branch stemcell version (%s). Aborting.", |
| 55 | + branchToCompare, branchToCompareStemcell.Version, mainStemcell.Version) |
| 56 | + } |
| 57 | + |
| 58 | + log.Printf("%s branch stemcell version (%s) is ahead of, or equal to, the main branch stemcell version (%s). Proceeding.", |
| 59 | + branchToCompare, branchToCompareStemcell.Version, mainStemcell.Version) |
| 60 | +} |
0 commit comments