Skip to content

Commit b7995ce

Browse files
authored
Merge branch 'main' into mcp-tool
2 parents a26f9f4 + 0279df9 commit b7995ce

File tree

3 files changed

+206
-2
lines changed

3 files changed

+206
-2
lines changed

.github/workflows/publish-to-npm.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- uses: actions/checkout@v5
1919
- uses: actions/setup-node@v5
2020
with:
21-
node-version: '20'
21+
node-version: 24
2222
registry-url: 'https://registry.npmjs.org/'
2323
- run: npm install
2424
- uses: JS-DevTools/npm-publish@v4
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
const getLatestHelmVersion = require('../../../extensions/version-fetcher/get-latest-redpanda-helm-version-from-operator');
2+
3+
describe('getLatestHelmVersion', () => {
4+
let mockGithub;
5+
6+
beforeEach(() => {
7+
mockGithub = {
8+
repos: {
9+
getContent: jest.fn()
10+
}
11+
};
12+
});
13+
14+
it('should fetch stable helm chart version from release branch', async () => {
15+
// Mock the GitHub API response
16+
const mockChartYaml = `
17+
apiVersion: v2
18+
name: redpanda
19+
version: 5.9.7
20+
description: Redpanda is a streaming data platform
21+
`;
22+
23+
mockGithub.repos.getContent.mockResolvedValue({
24+
data: {
25+
content: Buffer.from(mockChartYaml).toString('base64')
26+
}
27+
});
28+
29+
const result = await getLatestHelmVersion(
30+
mockGithub,
31+
'redpanda-data',
32+
'redpanda-operator',
33+
'v25.1.3',
34+
null
35+
);
36+
37+
expect(result.latestStableRelease).toBe('5.9.7');
38+
expect(result.latestBetaRelease).toBeNull();
39+
expect(mockGithub.repos.getContent).toHaveBeenCalledWith({
40+
owner: 'redpanda-data',
41+
repo: 'redpanda-operator',
42+
path: 'charts/redpanda/chart/Chart.yaml',
43+
ref: 'release/v25.1.x'
44+
});
45+
});
46+
47+
it('should fetch both stable and beta helm chart versions', async () => {
48+
const mockStableChart = `
49+
apiVersion: v2
50+
name: redpanda
51+
version: 5.9.7
52+
`;
53+
54+
const mockBetaChart = `
55+
apiVersion: v2
56+
name: redpanda
57+
version: 5.10.0-beta1
58+
`;
59+
60+
mockGithub.repos.getContent
61+
.mockResolvedValueOnce({
62+
data: { content: Buffer.from(mockStableChart).toString('base64') }
63+
})
64+
.mockResolvedValueOnce({
65+
data: { content: Buffer.from(mockBetaChart).toString('base64') }
66+
});
67+
68+
const result = await getLatestHelmVersion(
69+
mockGithub,
70+
'redpanda-data',
71+
'redpanda-operator',
72+
'v25.1.3',
73+
'v25.2.1-beta1'
74+
);
75+
76+
expect(result.latestStableRelease).toBe('5.9.7');
77+
expect(result.latestBetaRelease).toBe('5.10.0-beta1');
78+
expect(mockGithub.repos.getContent).toHaveBeenCalledTimes(2);
79+
});
80+
81+
it('should handle older version format (v2.x.x)', async () => {
82+
const mockChartYaml = `
83+
apiVersion: v2
84+
name: redpanda
85+
version: 2.4.5
86+
`;
87+
88+
mockGithub.repos.getContent.mockResolvedValue({
89+
data: { content: Buffer.from(mockChartYaml).toString('base64') }
90+
});
91+
92+
const result = await getLatestHelmVersion(
93+
mockGithub,
94+
'redpanda-data',
95+
'redpanda-operator',
96+
'v2.4.2',
97+
null
98+
);
99+
100+
expect(result.latestStableRelease).toBe('2.4.5');
101+
expect(mockGithub.repos.getContent).toHaveBeenCalledWith({
102+
owner: 'redpanda-data',
103+
repo: 'redpanda-operator',
104+
path: 'charts/redpanda/chart/Chart.yaml',
105+
ref: 'release/v2.4.x'
106+
});
107+
});
108+
109+
it('should handle invalid docker tag format', async () => {
110+
const result = await getLatestHelmVersion(
111+
mockGithub,
112+
'redpanda-data',
113+
'redpanda-operator',
114+
'invalid-tag',
115+
null
116+
);
117+
118+
expect(result.latestStableRelease).toBeNull();
119+
expect(result.latestBetaRelease).toBeNull();
120+
expect(mockGithub.repos.getContent).not.toHaveBeenCalled();
121+
});
122+
123+
it('should handle GitHub API errors gracefully', async () => {
124+
mockGithub.repos.getContent.mockRejectedValue(
125+
new Error('Branch not found')
126+
);
127+
128+
const result = await getLatestHelmVersion(
129+
mockGithub,
130+
'redpanda-data',
131+
'redpanda-operator',
132+
'v25.1.3',
133+
null
134+
);
135+
136+
expect(result.latestStableRelease).toBeNull();
137+
expect(result.latestBetaRelease).toBeNull();
138+
});
139+
140+
it('should handle missing version in Chart.yaml', async () => {
141+
const mockChartYaml = `
142+
apiVersion: v2
143+
name: redpanda
144+
description: No version field
145+
`;
146+
147+
mockGithub.repos.getContent.mockResolvedValue({
148+
data: { content: Buffer.from(mockChartYaml).toString('base64') }
149+
});
150+
151+
const result = await getLatestHelmVersion(
152+
mockGithub,
153+
'redpanda-data',
154+
'redpanda-operator',
155+
'v25.1.3',
156+
null
157+
);
158+
159+
expect(result.latestStableRelease).toBeNull();
160+
});
161+
162+
it('should handle beta tag with -beta suffix', async () => {
163+
const mockChartYaml = `
164+
apiVersion: v2
165+
name: redpanda
166+
version: 5.10.0-beta1
167+
`;
168+
169+
mockGithub.repos.getContent.mockResolvedValue({
170+
data: { content: Buffer.from(mockChartYaml).toString('base64') }
171+
});
172+
173+
const result = await getLatestHelmVersion(
174+
mockGithub,
175+
'redpanda-data',
176+
'redpanda-operator',
177+
null,
178+
'v25.2.1-beta1'
179+
);
180+
181+
expect(result.latestStableRelease).toBeNull();
182+
expect(result.latestBetaRelease).toBe('5.10.0-beta1');
183+
expect(mockGithub.repos.getContent).toHaveBeenCalledWith({
184+
owner: 'redpanda-data',
185+
repo: 'redpanda-operator',
186+
path: 'charts/redpanda/chart/Chart.yaml',
187+
ref: 'release/v25.2.x'
188+
});
189+
});
190+
191+
it('should handle null/undefined dockerTag parameters', async () => {
192+
const result = await getLatestHelmVersion(
193+
mockGithub,
194+
'redpanda-data',
195+
'redpanda-operator',
196+
null,
197+
null
198+
);
199+
200+
expect(result.latestStableRelease).toBeNull();
201+
expect(result.latestBetaRelease).toBeNull();
202+
expect(mockGithub.repos.getContent).not.toHaveBeenCalled();
203+
});
204+
});

extensions/version-fetcher/get-latest-redpanda-helm-version-from-operator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
module.exports = async (github, owner, repo, stableDockerTag, betaDockerTag) => {
1414
const yaml = require('js-yaml');
15-
const path = 'charts/redpanda/Chart.yaml';
15+
const path = 'charts/redpanda/chart/Chart.yaml';
1616

1717
/**
1818
* Helper function to fetch chart version from a branch derived from a docker tag

0 commit comments

Comments
 (0)