Skip to content

Commit

Permalink
Merge pull request #450 from cloudfoundry/remediate-automatic-stemcel…
Browse files Browse the repository at this point in the history
…l-update-race-cond

Make the check stemcell version task generic
  • Loading branch information
iaftab-alam authored Dec 9, 2024
2 parents 299af29 + 4ac1008 commit 82cc7f7
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 69 deletions.
55 changes: 0 additions & 55 deletions tasks/check-stemcell-versions-for-ship-it/main.go

This file was deleted.

11 changes: 0 additions & 11 deletions tasks/check-stemcell-versions-for-ship-it/task

This file was deleted.

60 changes: 60 additions & 0 deletions tasks/check-stemcell-versions/main.go
Original file line number Diff line number Diff line change
@@ -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 <buildDir> <branchToCompare>", 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)
}
13 changes: 13 additions & 0 deletions tasks/check-stemcell-versions/task
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 82cc7f7

Please sign in to comment.