Skip to content

Commit

Permalink
Add winfs version in release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
pvaramballypivot committed Jan 11, 2024
1 parent 2051303 commit 08f72e7
Show file tree
Hide file tree
Showing 6 changed files with 309 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/acceptance/workflows/updating_releases.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Feature: As a dependabot, I want to update a BOSH Release
| find-release-version |
| --release=hello-release |
| --variable=github_token="${GITHUB_TOKEN}" |
Then stdout contains substring: "0.2.3"
Then stdout contains substring: "0.2.5"

Scenario: Find a version on bosh.io
Given I set the version constraint to "1.1.18" for release "bpm"
Expand Down
10 changes: 10 additions & 0 deletions pkg/cargo/bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ func CalculateBumps(current, previous []BOSHReleaseTarballLock) []Bump {
return bumps
}

func WinfsVersionBump(bumped bool, version string, bumps []Bump) []Bump {
if bumped {
bumps = append(bumps, Bump{
Name: "windowsfs-release",
ToVersion: version,
})
}
return bumps
}

func (bump Bump) toFrom() (to, from *semver.Version, _ error) {
var err error
from, err = semver.NewVersion(bump.FromVersion)
Expand Down
22 changes: 22 additions & 0 deletions pkg/cargo/bump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,28 @@ func TestCalculateBumps(t *testing.T) {
})
}

func TestWinfsVersionBump(t *testing.T) {
t.Parallel()
please := NewWithT(t)

t.Run("when the winfs version is not bumped", func(t *testing.T) {
please.Expect(WinfsVersionBump(false, "2.61.0", []Bump{
{Name: "b", FromVersion: "1", ToVersion: "2"},
})).To(Equal([]Bump{
{Name: "b", FromVersion: "1", ToVersion: "2"},
}))
})

t.Run("when the winfs version is bumped", func(t *testing.T) {
please.Expect(WinfsVersionBump(true, "2.61.0", []Bump{
{Name: "b", FromVersion: "1", ToVersion: "2"},
})).To(Equal([]Bump{
{Name: "b", FromVersion: "1", ToVersion: "2"},
{Name: "windowsfs-release", FromVersion: "", ToVersion: "2.61.0"},
}))
})
}

func TestInternal_addReleaseNotes(t *testing.T) {
please := NewWithT(t)

Expand Down
76 changes: 76 additions & 0 deletions pkg/notes/internal/fakes/trainstat_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ type TrainstatClient struct {
result1 []string
result2 error
}

FetchStubForWinfs func(milestone string, version string) (bool, string, error)
fetchReturnsOnCallForWinfs map[int]struct {
result1 bool
result2 string
result3 error
}
fetchArgsForCallForWinfs []struct {
ctx context.Context
arg1 string
arg2 string
}
fetchReturnsForWinfs struct {
result1 bool
result2 string
result3 error
}

invocations map[string][][]any
invocationsMutex sync.RWMutex
}
Expand All @@ -48,6 +66,27 @@ func (fake *TrainstatClient) FetchTrainstatNotes(ctx context.Context, arg1 strin
return fakeReturns.result1, fakeReturns.result2
}

func (fake *TrainstatClient) FetchTrainstatWinfsVersionInfo(ctx context.Context, arg1 string, arg2 string) (bumped bool, winfsVersion string, err error) {
fake.fetchMutex.Lock()
ret, specificReturn := fake.fetchReturnsOnCallForWinfs[len(fake.fetchArgsForCallForWinfs)]
fake.fetchArgsForCallForWinfs = append(fake.fetchArgsForCallForWinfs, struct {
ctx context.Context
arg1 string
arg2 string
}{ctx, arg1, arg2})
stub := fake.FetchStubForWinfs
fakeReturns := fake.fetchReturnsForWinfs
fake.recordInvocation("Get", []any{arg1, arg2})
fake.fetchMutex.Unlock()
if stub != nil {
return stub(arg1, arg2)
}
if specificReturn {
return ret.result1, ret.result2, ret.result3
}
return fakeReturns.result1, fakeReturns.result2, fakeReturns.result3
}

func (fake *TrainstatClient) FetchReturnsOnCall(i int, result1 []string, result2 error) {
fake.fetchMutex.Lock()
defer fake.fetchMutex.Unlock()
Expand All @@ -64,25 +103,62 @@ func (fake *TrainstatClient) FetchReturnsOnCall(i int, result1 []string, result2
}{result1, result2}
}

func (fake *TrainstatClient) FetchReturnsOnCallForWinfs(i int, result1 bool, result2 string, result3 error) {
fake.fetchMutex.Lock()
defer fake.fetchMutex.Unlock()
fake.FetchStubForWinfs = nil
if fake.fetchReturnsOnCallForWinfs == nil {
fake.fetchReturnsOnCallForWinfs = make(map[int]struct {
result1 bool
result2 string
result3 error
})
}
fake.fetchReturnsOnCallForWinfs[i] = struct {
result1 bool
result2 string
result3 error
}{result1, result2, result3}
}

func (fake *TrainstatClient) GetCallCount() int {
fake.fetchMutex.RLock()
defer fake.fetchMutex.RUnlock()
return len(fake.fetchArgsForCall)
}

func (fake *TrainstatClient) GetCallCountForWinfs() int {
fake.fetchMutex.RLock()
defer fake.fetchMutex.RUnlock()
return len(fake.fetchArgsForCallForWinfs)
}

func (fake *TrainstatClient) GetCalls(stub func(string, string, string) ([]string, error)) {
fake.fetchMutex.Lock()
defer fake.fetchMutex.Unlock()
fake.FetchStub = stub
}

func (fake *TrainstatClient) GetCallsForWinfs(stub func(string, string) (bool, string, error)) {
fake.fetchMutex.Lock()
defer fake.fetchMutex.Unlock()
fake.FetchStubForWinfs = stub
}

func (fake *TrainstatClient) GetArgsForCall(i int) (string, string, string) {
fake.fetchMutex.RLock()
defer fake.fetchMutex.RUnlock()
argsForCall := fake.fetchArgsForCall[i]
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
}

func (fake *TrainstatClient) GetArgsForCallForWinfs(i int) (string, string) {
fake.fetchMutex.RLock()
defer fake.fetchMutex.RUnlock()
argsForCall := fake.fetchArgsForCallForWinfs[i]
return argsForCall.arg1, argsForCall.arg2
}

func (fake *TrainstatClient) Invocations() map[string][][]any {
fake.invocationsMutex.RLock()
defer fake.invocationsMutex.RUnlock()
Expand Down
64 changes: 64 additions & 0 deletions pkg/notes/notes_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,29 @@ func (r fetchNotesData) fetch(ctx context.Context) (Data, error) {
})
}

if strings.Contains(r.kilnfilePath, "tasw") {
data, err = r.fetchWinfsReleaseNotes(ctx, data, majorMinor)
if err != nil {
return Data{}, err
}
}

return data, nil
}

func (r fetchNotesData) fetchWinfsReleaseNotes(ctx context.Context, data Data, majorMinor string) (Data, error) {
bumped, winfsVersion, err := r.trainstatClient.FetchTrainstatWinfsVersionInfo(ctx, r.issuesQuery.IssueMilestone, majorMinor)
if err != nil {
return Data{}, err
}
data.Bumps = cargo.WinfsVersionBump(bumped, winfsVersion, data.Bumps)
data.Components = append(data.Components, BOSHReleaseData{
BOSHReleaseTarballLock: cargo.BOSHReleaseTarballLock{
Name: "windowsfs-release",
Version: winfsVersion,
},
})

return data, nil
}

Expand Down Expand Up @@ -544,6 +567,7 @@ func closeAndIgnoreError(c io.Closer) { _ = c.Close() }

type TrainstatNotesFetcher interface {
FetchTrainstatNotes(ctx context.Context, milestone string, version string, tile string) ([]string, error)
FetchTrainstatWinfsVersionInfo(ctx context.Context, milestone string, version string) (bool, string, error)
}

type TrainstatClient struct {
Expand Down Expand Up @@ -602,6 +626,46 @@ func (t *TrainstatClient) FetchTrainstatNotes(ctx context.Context, milestone str
return
}

func (t *TrainstatClient) FetchTrainstatWinfsVersionInfo(ctx context.Context, milestone string, version string) (bumped bool, winfsVersion string, err error) {
baseURL := fmt.Sprintf("%s/%s", t.host, "api/v1/get_winfs_version_bump")
req, err := http.NewRequestWithContext(ctx, http.MethodGet, baseURL, nil)

if err != nil {
return false, "", err
}

req.Header.Add("Content-Type", "application/json")
q := req.URL.Query()
q.Set("milestone", milestone)
q.Set("version", version)
req.URL.RawQuery = q.Encode()

res, err := t.httpClient.Do(req)
if err != nil {
return false, "", err
}
if res.StatusCode != http.StatusOK {
return false, "", fmt.Errorf("request status code is not okkkk: got %d", res.StatusCode)
}
defer closeAndIgnoreError(res.Body)

responseData, err := io.ReadAll(res.Body)
if err != nil {
return false, "", err
}

winfsVersionInfo := struct {
Bumped bool `json:"bumped"`
Version string `json:"version"`
}{}

err = json.Unmarshal(responseData, &winfsVersionInfo)
if err != nil {
return false, "", err
}
return winfsVersionInfo.Bumped, winfsVersionInfo.Version, err
}

func (t *TrainstatClient) tileSupported(tile string) bool {
switch tile {
case "elastic-runtime", "p-isolation-segment", "pas-windows":
Expand Down
Loading

0 comments on commit 08f72e7

Please sign in to comment.