@redpanda-data/docs-extensions-and-macros 4.1.0 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.adoc CHANGED
@@ -287,7 +287,7 @@ To enable and configure the extension, add it to the `antora.extensions` section
287
287
  ----
288
288
  antora:
289
289
  extensions:
290
- - require: '@redpanda-data/docs-extensions-and-macros/extensions/end-of-life'
290
+ - require: '@redpanda-data/docs-extensions-and-macros/extensions/compute-end-of-life'
291
291
  data:
292
292
  eol_settings:
293
293
  - component: 'ROOT'
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Fetches the latest stable and beta version tags from Docker Hub for a given repository.
3
+ *
4
+ * The function separates tags into stable (tags not including "-beta") and beta (tags including "-beta"),
5
+ * sorts each group by their major.minor version in descending order, and returns the top tag from each.
6
+ *
7
+ * @param {string} dockerNamespace - The Docker Hub namespace (organization or username)
8
+ * @param {string} dockerRepo - The repository name on Docker Hub
9
+ * @returns {Promise<{ latestStableRelease: string|null, latestBetaRelease: string|null }>}
10
+ */
11
+ module.exports = async (dockerNamespace, dockerRepo) => {
12
+ const { default: fetch } = await import('node-fetch');
13
+
14
+ try {
15
+ // Fetch a list of tags from Docker Hub.
16
+ const url = `https://hub.docker.com/v2/repositories/${dockerNamespace}/${dockerRepo}/tags?page_size=100`;
17
+ const response = await fetch(url);
18
+
19
+ if (!response.ok) {
20
+ throw new Error(`Docker Hub API responded with status ${response.status}`);
21
+ }
22
+
23
+ const data = await response.json();
24
+
25
+ // Regex to capture major and minor version numbers (e.g. "v2.3")
26
+ const versionRegex = /^v(\d+)\.(\d+)/;
27
+
28
+ // Filter tags to include only those matching the version pattern.
29
+ let tags = data.results.filter(tag => versionRegex.test(tag.name));
30
+
31
+ // For specific repositories (e.g. "redpanda-operator"), you might want to filter out certain versions.
32
+ if (dockerRepo === 'redpanda-operator') {
33
+ tags = tags.filter(tag => !/^(v22|v23)/.test(tag.name));
34
+ }
35
+
36
+ // Separate stable and beta tags.
37
+ const stableTags = tags.filter(tag => !tag.name.includes('-beta'));
38
+ const betaTags = tags.filter(tag => tag.name.includes('-beta'));
39
+
40
+ // Helper function to sort tags in descending order based on major and minor version numbers.
41
+ const sortTags = (a, b) => {
42
+ const aMatch = a.name.match(versionRegex);
43
+ const bMatch = b.name.match(versionRegex);
44
+ const aMajor = parseInt(aMatch[1], 10);
45
+ const aMinor = parseInt(aMatch[2], 10);
46
+ const bMajor = parseInt(bMatch[1], 10);
47
+ const bMinor = parseInt(bMatch[2], 10);
48
+
49
+ if (aMajor !== bMajor) {
50
+ return bMajor - aMajor;
51
+ }
52
+ return bMinor - aMinor;
53
+ };
54
+
55
+ const sortedStable = stableTags.sort(sortTags);
56
+ const sortedBeta = betaTags.sort(sortTags);
57
+
58
+ const latestStableReleaseVersion = sortedStable.length ? sortedStable[0].name : null;
59
+ const latestBetaReleaseVersion = sortedBeta.length ? sortedBeta[0].name : null;
60
+
61
+ return {
62
+ latestStableRelease: latestStableReleaseVersion || null,
63
+ latestBetaRelease: latestBetaReleaseVersion || null
64
+ };
65
+
66
+ } catch (error) {
67
+ console.error('Error fetching Docker tags:', error);
68
+ return {
69
+ latestStableRelease: null,
70
+ latestBetaRelease: null
71
+ };
72
+ }
73
+ };
@@ -3,7 +3,7 @@
3
3
  module.exports.register = function ({ config }) {
4
4
  const GetLatestRedpandaVersion = require('./get-latest-redpanda-version');
5
5
  const GetLatestConsoleVersion = require('./get-latest-console-version');
6
- const GetLatestOperatorVersion = require('./get-latest-operator-version');
6
+ const GetLatestOperatorVersion = require('./fetch-latest-docker-tag');
7
7
  const GetLatestHelmChartVersion = require('./get-latest-redpanda-helm-version');
8
8
  const GetLatestConnectVersion = require('./get-latest-connect');
9
9
  const logger = this.getLogger('set-latest-version-extension');
@@ -25,6 +25,7 @@ module.exports.register = function ({ config }) {
25
25
  auth: process.env.REDPANDA_GITHUB_TOKEN || undefined,
26
26
  };
27
27
  const github = new OctokitWithRetries(githubOptions);
28
+ const dockerNamespace = 'redpandadata'
28
29
 
29
30
  try {
30
31
  const [
@@ -36,7 +37,7 @@ module.exports.register = function ({ config }) {
36
37
  ] = await Promise.allSettled([
37
38
  GetLatestRedpandaVersion(github, owner, 'redpanda'),
38
39
  GetLatestConsoleVersion(github, owner, 'console'),
39
- GetLatestOperatorVersion(github, owner, 'redpanda-operator'),
40
+ GetLatestOperatorVersion(dockerNamespace, 'redpanda-operator'),
40
41
  GetLatestHelmChartVersion(github, owner, 'helm-charts', 'charts/redpanda/Chart.yaml'),
41
42
  GetLatestConnectVersion(github, owner, 'connect'),
42
43
  ]);
@@ -49,6 +50,8 @@ module.exports.register = function ({ config }) {
49
50
  connect: latestConnectResult.status === 'fulfilled' ? latestConnectResult.value : undefined,
50
51
  };
51
52
 
53
+ console.log(latestVersions)
54
+
52
55
  const components = await contentCatalog.getComponents();
53
56
  components.forEach(component => {
54
57
  const prerelease = component.latestPrerelease;
@@ -58,27 +61,33 @@ module.exports.register = function ({ config }) {
58
61
  asciidoc.attributes['page-component-version-is-prerelease'] = 'true';
59
62
  }
60
63
 
61
- // Set operator and helm chart attributes
62
- if (latestVersions.operator) {
63
- asciidoc.attributes['latest-operator-version'] = latestVersions.operator;
64
- }
65
- if (latestVersions.helmChart) {
66
- asciidoc.attributes['latest-redpanda-helm-chart-version'] = latestVersions.helmChart;
67
- }
64
+ // Set operator and helm chart attributes via helper function
65
+ updateAttributes(asciidoc, [
66
+ { condition: latestVersions.operator, key: 'latest-operator-version', value: latestVersions.operator?.latestStableRelease },
67
+ { condition: latestVersions.helmChart, key: 'latest-redpanda-helm-chart-version', value: latestVersions.helmChart }
68
+ ]);
68
69
 
69
70
  // Set attributes for console and connect versions
70
- if (latestVersions.console) {
71
- setVersionAndTagAttributes(asciidoc, 'latest-console', latestVersions.console.latestStableRelease, name, version);
72
- }
73
- if (latestVersions.connect) {
74
- setVersionAndTagAttributes(asciidoc, 'latest-connect', latestVersions.connect, name, version);
75
- }
71
+ [
72
+ { condition: latestVersions.console, baseName: 'latest-console', value: latestVersions.console?.latestStableRelease },
73
+ { condition: latestVersions.connect, baseName: 'latest-connect', value: latestVersions.connect }
74
+ ].forEach(mapping => {
75
+ if (mapping.condition && mapping.value) {
76
+ setVersionAndTagAttributes(asciidoc, mapping.baseName, mapping.value, name, version);
77
+ }
78
+ });
79
+
76
80
  // Special handling for Redpanda RC versions if in beta
77
81
  if (latestVersions.redpanda?.latestRcRelease?.version) {
78
- setVersionAndTagAttributes(asciidoc, 'redpanda-beta', latestVersions.redpanda.latestRcRelease.version, name, version)
79
- setVersionAndTagAttributes(asciidoc, 'console-beta', latestVersions.console.latestBetaRelease, name, version);
82
+ setVersionAndTagAttributes(asciidoc, 'redpanda-beta', latestVersions.redpanda.latestRcRelease.version, name, version);
80
83
  asciidoc.attributes['redpanda-beta-commit'] = latestVersions.redpanda.latestRcRelease.commitHash;
81
84
  }
85
+ if (latestVersions.console?.latestBetaRelease) {
86
+ setVersionAndTagAttributes(asciidoc, 'console-beta', latestVersions.console.latestBetaRelease, name, version);
87
+ }
88
+ if (latestVersions.operator?.latestBetaRelease) {
89
+ setVersionAndTagAttributes(asciidoc, 'operator-beta', latestVersions.operator.latestBetaRelease, name, version);
90
+ }
82
91
  });
83
92
 
84
93
  if (!component.latest.asciidoc) component.latest.asciidoc = { attributes: {} };
@@ -127,4 +136,13 @@ module.exports.register = function ({ config }) {
127
136
  function sanitizeVersion(version) {
128
137
  return version.replace(/^v/, '');
129
138
  }
130
- };
139
+
140
+ // Helper function to update multiple attributes based on a list of mappings
141
+ function updateAttributes(asciidoc, mappings) {
142
+ mappings.forEach(({ condition, key, value }) => {
143
+ if (condition) {
144
+ asciidoc.attributes[key] = value;
145
+ }
146
+ });
147
+ }
148
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redpanda-data/docs-extensions-and-macros",
3
- "version": "4.1.0",
3
+ "version": "4.2.1",
4
4
  "description": "Antora extensions and macros developed for Redpanda documentation.",
5
5
  "keywords": [
6
6
  "antora",
@@ -75,6 +75,7 @@
75
75
  "js-yaml": "^4.1.0",
76
76
  "lodash": "^4.17.21",
77
77
  "micromatch": "^4.0.8",
78
+ "node-fetch": "^3.3.2",
78
79
  "node-html-parser": "5.4.2-0",
79
80
  "papaparse": "^5.4.1",
80
81
  "semver": "^7.6.0",
@@ -1,10 +0,0 @@
1
- module.exports = async (github, owner, repo) => {
2
- try {
3
- const release = await github.rest.repos.getLatestRelease({ owner, repo });
4
- latestOperatorReleaseVersion = release.data.tag_name;
5
- return latestOperatorReleaseVersion;
6
- } catch (error) {
7
- console.error(error);
8
- return null;
9
- }
10
- };