@redpanda-data/docs-extensions-and-macros 4.2.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.
@@ -1,10 +1,12 @@
1
1
  /**
2
- * Fetches the latest version tag from Docker Hub for a given repository.
2
+ * Fetches the latest stable and beta version tags from Docker Hub for a given repository.
3
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.
4
6
  *
5
7
  * @param {string} dockerNamespace - The Docker Hub namespace (organization or username)
6
8
  * @param {string} dockerRepo - The repository name on Docker Hub
7
- * @returns {Promise<string|null>} The latest version tag or null if none is found.
9
+ * @returns {Promise<{ latestStableRelease: string|null, latestBetaRelease: string|null }>}
8
10
  */
9
11
  module.exports = async (dockerNamespace, dockerRepo) => {
10
12
  const { default: fetch } = await import('node-fetch');
@@ -20,28 +22,23 @@ module.exports = async (dockerNamespace, dockerRepo) => {
20
22
 
21
23
  const data = await response.json();
22
24
 
23
- // Define a regular expression to capture the major and minor version numbers.
24
- // The regex /^v(\d+)\.(\d+)/ matches tags that start with "v", followed by digits (major),
25
- // a period, and more digits (minor). It works for tags like "v2.3.8-24.3.6" or "v25.1-k8s4".
25
+ // Regex to capture major and minor version numbers (e.g. "v2.3")
26
26
  const versionRegex = /^v(\d+)\.(\d+)/;
27
27
 
28
- // Filter the list of tags to include only those that match our expected version pattern.
29
- // This helps ensure we work only with tags that represent valid version numbers.
30
- let versionTags = data.results.filter(tag => versionRegex.test(tag.name));
28
+ // Filter tags to include only those matching the version pattern.
29
+ let tags = data.results.filter(tag => versionRegex.test(tag.name));
31
30
 
32
- // If the repository is "redpanda-operator", ignore any tags starting with the old "v22 or "v23" versions.
31
+ // For specific repositories (e.g. "redpanda-operator"), you might want to filter out certain versions.
33
32
  if (dockerRepo === 'redpanda-operator') {
34
- versionTags = versionTags.filter(tag => !/^(v22|v23)/.test(tag.name));
33
+ tags = tags.filter(tag => !/^(v22|v23)/.test(tag.name));
35
34
  }
36
35
 
37
- if (versionTags.length === 0) {
38
- console.warn('No version tags found.');
39
- return null;
40
- }
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'));
41
39
 
42
- // Sort the filtered tags in descending order based on their major and minor version numbers.
43
- // This sorting ignores any additional patch or suffix details and focuses only on the major.minor value.
44
- versionTags.sort((a, b) => {
40
+ // Helper function to sort tags in descending order based on major and minor version numbers.
41
+ const sortTags = (a, b) => {
45
42
  const aMatch = a.name.match(versionRegex);
46
43
  const bMatch = b.name.match(versionRegex);
47
44
  const aMajor = parseInt(aMatch[1], 10);
@@ -49,18 +46,28 @@ module.exports = async (dockerNamespace, dockerRepo) => {
49
46
  const bMajor = parseInt(bMatch[1], 10);
50
47
  const bMinor = parseInt(bMatch[2], 10);
51
48
 
52
- // Compare by major version first; if equal, compare by minor version.
53
49
  if (aMajor !== bMajor) {
54
50
  return bMajor - aMajor;
55
51
  }
56
52
  return bMinor - aMinor;
57
- });
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;
58
60
 
59
- // Return the name of the tag with the highest major.minor version.
60
- return versionTags[0].name;
61
+ return {
62
+ latestStableRelease: latestStableReleaseVersion || null,
63
+ latestBetaRelease: latestBetaReleaseVersion || null
64
+ };
61
65
 
62
66
  } catch (error) {
63
- console.error('Error fetching latest Docker tag:', error);
64
- return null;
67
+ console.error('Error fetching Docker tags:', error);
68
+ return {
69
+ latestStableRelease: null,
70
+ latestBetaRelease: null
71
+ };
65
72
  }
66
73
  };
@@ -63,7 +63,7 @@ module.exports.register = function ({ config }) {
63
63
 
64
64
  // Set operator and helm chart attributes via helper function
65
65
  updateAttributes(asciidoc, [
66
- { condition: latestVersions.operator, key: 'latest-operator-version', value: latestVersions.operator },
66
+ { condition: latestVersions.operator, key: 'latest-operator-version', value: latestVersions.operator?.latestStableRelease },
67
67
  { condition: latestVersions.helmChart, key: 'latest-redpanda-helm-chart-version', value: latestVersions.helmChart }
68
68
  ]);
69
69
 
@@ -80,9 +80,14 @@ module.exports.register = function ({ config }) {
80
80
  // Special handling for Redpanda RC versions if in beta
81
81
  if (latestVersions.redpanda?.latestRcRelease?.version) {
82
82
  setVersionAndTagAttributes(asciidoc, 'redpanda-beta', latestVersions.redpanda.latestRcRelease.version, name, version);
83
- setVersionAndTagAttributes(asciidoc, 'console-beta', latestVersions.console.latestBetaRelease, name, version);
84
83
  asciidoc.attributes['redpanda-beta-commit'] = latestVersions.redpanda.latestRcRelease.commitHash;
85
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
+ }
86
91
  });
87
92
 
88
93
  if (!component.latest.asciidoc) component.latest.asciidoc = { attributes: {} };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redpanda-data/docs-extensions-and-macros",
3
- "version": "4.2.0",
3
+ "version": "4.2.1",
4
4
  "description": "Antora extensions and macros developed for Redpanda documentation.",
5
5
  "keywords": [
6
6
  "antora",