From 2f507e15449ac9e7a9206bc5bf48bf21bf78ebff Mon Sep 17 00:00:00 2001 From: Aftab Alam <81828613+iaftab-alam@users.noreply.github.com> Date: Tue, 26 Nov 2024 15:55:17 +0100 Subject: [PATCH 1/2] Make the check stemcell version task generic With this PR, the check stemcell version is made generic so it can accommodate develop branch. As this will be used to make comparison between either develop or release-candidate branch and main branch. --- .../main.go | 55 ------------------ .../check-stemcell-versions-for-ship-it/task | 11 ---- tasks/check-stemcell-versions/main.go | 56 +++++++++++++++++++ tasks/check-stemcell-versions/task | 12 ++++ .../task.yml | 11 +++- 5 files changed, 76 insertions(+), 69 deletions(-) delete mode 100644 tasks/check-stemcell-versions-for-ship-it/main.go delete mode 100755 tasks/check-stemcell-versions-for-ship-it/task create mode 100644 tasks/check-stemcell-versions/main.go create mode 100755 tasks/check-stemcell-versions/task rename tasks/{check-stemcell-versions-for-ship-it => check-stemcell-versions}/task.yml (55%) 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..d64ca5b85 --- /dev/null +++ b/tasks/check-stemcell-versions/main.go @@ -0,0 +1,56 @@ +package main + +import ( + "log" + "os" + "path/filepath" + + "github.com/cloudfoundry/runtime-ci/task-libs/bosh" +) + +func main() { + buildDir := os.Args[1] + branchToCompare := os.Getenv("BRANCH_TO_COMPARE") + + 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..35ba3aee8 --- /dev/null +++ b/tasks/check-stemcell-versions/task @@ -0,0 +1,12 @@ +#!/bin/bash +set -eu + +function main() { + root_dir="$PWD" + : "${BRANCH_TO_COMPARE:=release-candidate}" + pushd "$(dirname $0)" + BRANCH_TO_COMPARE=$BRANCH_TO_COMPARE go run main.go "${root_dir}" + 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 From 4ac1008b09c92490a0e6777775d53f61b75a94b3 Mon Sep 17 00:00:00 2001 From: Aftab Alam <81828613+iaftab-alam@users.noreply.github.com> Date: Thu, 5 Dec 2024 09:34:30 +0100 Subject: [PATCH 2/2] pass params via arguments --- tasks/check-stemcell-versions/main.go | 6 +++++- tasks/check-stemcell-versions/task | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tasks/check-stemcell-versions/main.go b/tasks/check-stemcell-versions/main.go index d64ca5b85..ce1903377 100644 --- a/tasks/check-stemcell-versions/main.go +++ b/tasks/check-stemcell-versions/main.go @@ -9,8 +9,12 @@ import ( ) func main() { + if len(os.Args) < 3 { + log.Fatalf("Usage: %s ", os.Args[0]) + } + buildDir := os.Args[1] - branchToCompare := os.Getenv("BRANCH_TO_COMPARE") + branchToCompare := os.Args[2] content, err := os.ReadFile(filepath.Join(buildDir, "cf-deployment-main", "cf-deployment.yml")) if err != nil { diff --git a/tasks/check-stemcell-versions/task b/tasks/check-stemcell-versions/task index 35ba3aee8..ca4da160c 100755 --- a/tasks/check-stemcell-versions/task +++ b/tasks/check-stemcell-versions/task @@ -3,9 +3,10 @@ set -eu function main() { root_dir="$PWD" - : "${BRANCH_TO_COMPARE:=release-candidate}" + branch_to_compare="${BRANCH_TO_COMPARE:-release-candidate}" + pushd "$(dirname $0)" - BRANCH_TO_COMPARE=$BRANCH_TO_COMPARE go run main.go "${root_dir}" + go run main.go "${root_dir}" "${branch_to_compare}" popd }