Skip to content

Commit 82cc7f7

Browse files
authored
Merge pull request #450 from cloudfoundry/remediate-automatic-stemcell-update-race-cond
Make the check stemcell version task generic
2 parents 299af29 + 4ac1008 commit 82cc7f7

File tree

5 files changed

+81
-69
lines changed

5 files changed

+81
-69
lines changed

tasks/check-stemcell-versions-for-ship-it/main.go

Lines changed: 0 additions & 55 deletions
This file was deleted.

tasks/check-stemcell-versions-for-ship-it/task

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
}

tasks/check-stemcell-versions/task

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -eu
3+
4+
function main() {
5+
root_dir="$PWD"
6+
branch_to_compare="${BRANCH_TO_COMPARE:-release-candidate}"
7+
8+
pushd "$(dirname $0)"
9+
go run main.go "${root_dir}" "${branch_to_compare}"
10+
popd
11+
}
12+
13+
main

tasks/check-stemcell-versions-for-ship-it/task.yml renamed to tasks/check-stemcell-versions/task.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ image_resource:
88

99
inputs:
1010
- name: runtime-ci
11-
- name: cf-deployment-release-candidate
1211
- name: cf-deployment-main
13-
12+
- name: cf-deployment-release-candidate
13+
optional: true
14+
- name: cf-deployment-develop
15+
optional: true
16+
17+
params:
18+
BRANCH_TO_COMPARE: release-candidate
1419
run:
15-
path: runtime-ci/tasks/check-stemcell-versions-for-ship-it/task
20+
path: runtime-ci/tasks/check-stemcell-versions/task

0 commit comments

Comments
 (0)