diff --git a/tasks/check-stemcell-versions-for-ship-it/main.go b/tasks/check-stemcell-versions-for-ship-it/main.go deleted file mode 100644 index e3ad05377..000000000 --- a/tasks/check-stemcell-versions-for-ship-it/main.go +++ /dev/null @@ -1,55 +0,0 @@ -package main - -import ( - "log" - "os" - "path/filepath" - - "github.com/cloudfoundry/runtime-ci/task-libs/bosh" -) - -func main() { - buildDir := os.Args[1] - - content, err := os.ReadFile(filepath.Join(buildDir, "cf-deployment-main", "cf-deployment.yml")) - if err != nil { - log.Fatalf("Failed to read main cf-deployment.yml: %s", err) - } - - mainManifest, err := bosh.NewManifestFromFile(content) - if err != nil { - log.Fatalf("Failed to unmarshal main cf-deployment.yml: %s", err) - } - - content, err = os.ReadFile(filepath.Join(buildDir, "cf-deployment-release-candidate", "cf-deployment.yml")) - if err != nil { - log.Fatalf("Failed to read release-candidate cf-deployment.yml: %s", err) - } - - releaseCandidateManifest, err := bosh.NewManifestFromFile(content) - if err != nil { - log.Fatalf("Failed to unmarshal release-candidate cf-deployment.yml: %s", err) - } - - mainStemcell := mainManifest.Stemcells[0] - releaseCandidateStemcell := releaseCandidateManifest.Stemcells[0] - - if mainStemcell.OS != releaseCandidateStemcell.OS { - log.Printf("Release candidate stemcell OS (%s) is different to the main stemcell OS (%s). Proceeding.", - releaseCandidateStemcell.OS, mainStemcell.OS) - os.Exit(0) - } - - result, err := releaseCandidateStemcell.CompareVersion(mainStemcell) - if err != nil { - log.Fatalf("Failed to compare stemcell versions: %s", err) - } - - if result == -1 { - log.Fatalf("Release candidate stemcell version (%s) is behind the main stemcell version (%s). Aborting.", - releaseCandidateStemcell.Version, mainStemcell.Version) - } - - log.Printf("Release candidate stemcell version (%s) is ahead of, or equal to, the main stemcell version (%s). Proceeding.", - releaseCandidateStemcell.Version, mainStemcell.Version) -} diff --git a/tasks/check-stemcell-versions-for-ship-it/task b/tasks/check-stemcell-versions-for-ship-it/task deleted file mode 100755 index f90685940..000000000 --- a/tasks/check-stemcell-versions-for-ship-it/task +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -set -eu - -function main() { - root_dir="$PWD" - pushd "$(dirname $0)" - go run main.go "${root_dir}" - popd -} - -main diff --git a/tasks/check-stemcell-versions/main.go b/tasks/check-stemcell-versions/main.go new file mode 100644 index 000000000..ce1903377 --- /dev/null +++ b/tasks/check-stemcell-versions/main.go @@ -0,0 +1,60 @@ +package main + +import ( + "log" + "os" + "path/filepath" + + "github.com/cloudfoundry/runtime-ci/task-libs/bosh" +) + +func main() { + if len(os.Args) < 3 { + log.Fatalf("Usage: %s ", os.Args[0]) + } + + buildDir := os.Args[1] + branchToCompare := os.Args[2] + + content, err := os.ReadFile(filepath.Join(buildDir, "cf-deployment-main", "cf-deployment.yml")) + if err != nil { + log.Fatalf("Failed to read main branch cf-deployment.yml: %s", err) + } + + mainManifest, err := bosh.NewManifestFromFile(content) + if err != nil { + log.Fatalf("Failed to unmarshal main branch cf-deployment.yml: %s", err) + } + + content, err = os.ReadFile(filepath.Join(buildDir, "cf-deployment-"+branchToCompare, "cf-deployment.yml")) + if err != nil { + log.Fatalf("Failed to read %s branch cf-deployment.yml: %s", branchToCompare, err) + } + + branchToCompareManifest, err := bosh.NewManifestFromFile(content) + if err != nil { + log.Fatalf("Failed to unmarshal %s branch cf-deployment.yml: %s", branchToCompare, err) + } + + mainStemcell := mainManifest.Stemcells[0] + branchToCompareStemcell := branchToCompareManifest.Stemcells[0] + + if mainStemcell.OS != branchToCompareStemcell.OS { + log.Printf("%s branch stemcell OS (%s) is different to the main branch stemcell OS (%s). Proceeding.", + branchToCompare, branchToCompareStemcell.OS, mainStemcell.OS) + os.Exit(0) + } + + result, err := branchToCompareStemcell.CompareVersion(mainStemcell) + if err != nil { + log.Fatalf("Failed to compare stemcell versions: %s", err) + } + + if result == -1 { + log.Fatalf("%s branch stemcell version (%s) is behind the main branch stemcell version (%s). Aborting.", + branchToCompare, branchToCompareStemcell.Version, mainStemcell.Version) + } + + log.Printf("%s branch stemcell version (%s) is ahead of, or equal to, the main branch stemcell version (%s). Proceeding.", + branchToCompare, branchToCompareStemcell.Version, mainStemcell.Version) +} diff --git a/tasks/check-stemcell-versions/task b/tasks/check-stemcell-versions/task new file mode 100755 index 000000000..ca4da160c --- /dev/null +++ b/tasks/check-stemcell-versions/task @@ -0,0 +1,13 @@ +#!/bin/bash +set -eu + +function main() { + root_dir="$PWD" + branch_to_compare="${BRANCH_TO_COMPARE:-release-candidate}" + + pushd "$(dirname $0)" + go run main.go "${root_dir}" "${branch_to_compare}" + popd +} + +main diff --git a/tasks/check-stemcell-versions-for-ship-it/task.yml b/tasks/check-stemcell-versions/task.yml similarity index 55% rename from tasks/check-stemcell-versions-for-ship-it/task.yml rename to tasks/check-stemcell-versions/task.yml index 9508f25f4..7dc116e0e 100644 --- a/tasks/check-stemcell-versions-for-ship-it/task.yml +++ b/tasks/check-stemcell-versions/task.yml @@ -8,8 +8,13 @@ image_resource: inputs: - name: runtime-ci -- name: cf-deployment-release-candidate - name: cf-deployment-main - +- name: cf-deployment-release-candidate + optional: true +- name: cf-deployment-develop + optional: true + +params: + BRANCH_TO_COMPARE: release-candidate run: - path: runtime-ci/tasks/check-stemcell-versions-for-ship-it/task + path: runtime-ci/tasks/check-stemcell-versions/task