@redpanda-data/docs-extensions-and-macros 3.2.7 → 3.2.9

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.
@@ -0,0 +1,9 @@
1
+ module.exports.register = function () {
2
+ this.on('documentsConverted', ({ contentCatalog }) => {
3
+ contentCatalog.getPages((page) => page.out).forEach((page) => {
4
+ if (page.asciidoc?.attributes['page-unpublish'] != null || page.asciidoc?.attributes['page-layout'] === 'api-partial') {
5
+ delete page.out
6
+ }
7
+ })
8
+ })
9
+ }
@@ -18,11 +18,11 @@ const github = new OctokitWithRetries(githubOptions);
18
18
 
19
19
  module.exports = async () => {
20
20
  try {
21
- // Fetch the latest 10 releases
22
21
  const releases = await github.rest.repos.listReleases({
23
22
  owner,
24
23
  repo,
25
- per_page: 10,
24
+ page: 1,
25
+ per_page: 50
26
26
  });
27
27
 
28
28
  // Filter valid semver tags and sort them
@@ -0,0 +1,33 @@
1
+ const { Octokit } = require("@octokit/rest");
2
+ const { retry } = require("@octokit/plugin-retry");
3
+ const yaml = require('js-yaml');
4
+ const OctokitWithRetries = Octokit.plugin(retry);
5
+
6
+ const githubOptions = {
7
+ userAgent: 'Redpanda Docs',
8
+ baseUrl: 'https://api.github.com',
9
+ auth: process.env.REDPANDA_GITHUB_TOKEN
10
+ };
11
+
12
+ const github = new OctokitWithRetries(githubOptions);
13
+ const owner = 'redpanda-data';
14
+ const repo = 'helm-charts';
15
+ const path = 'charts/redpanda/Chart.yaml';
16
+
17
+ module.exports = async () => {
18
+ try {
19
+ const response = await github.repos.getContent({
20
+ owner: owner,
21
+ repo: repo,
22
+ path: path,
23
+ });
24
+
25
+ const contentBase64 = response.data.content;
26
+ const contentDecoded = Buffer.from(contentBase64, 'base64').toString('utf8');
27
+ const chartYaml = yaml.load(contentDecoded);
28
+ return chartYaml.version;
29
+ } catch (error) {
30
+ console.error('Failed to fetch chart version:', error.message);
31
+ return null
32
+ }
33
+ };
@@ -1,7 +1,8 @@
1
- // Fetch the latest release version from GitHub
2
1
  const { Octokit } = require("@octokit/rest");
3
2
  const { retry } = require("@octokit/plugin-retry");
3
+ const semver = require("semver");
4
4
  const OctokitWithRetries = Octokit.plugin(retry);
5
+
5
6
  const owner = 'redpanda-data';
6
7
  const repo = 'redpanda';
7
8
 
@@ -18,22 +19,40 @@ const github = new OctokitWithRetries(githubOptions);
18
19
 
19
20
  module.exports = async () => {
20
21
  try {
21
- // Fetch the latest release
22
- const release = await github.rest.repos.getLatestRelease({ owner, repo });
23
- const tag = release.data.tag_name;
24
- latestRedpandaReleaseVersion = tag.replace('v', '');
22
+ // Fetch all the releases from the repository
23
+ const releases = await github.rest.repos.listReleases({
24
+ owner,
25
+ repo,
26
+ page: 1,
27
+ per_page: 50
28
+ });
29
+
30
+ // Filter valid semver tags and sort them to find the highest version
31
+ const sortedReleases = releases.data
32
+ .map(release => release.tag_name.replace(/^v/, ''))
33
+ .filter(tag => semver.valid(tag))
34
+ // Sort in descending order to get the highest version first
35
+ .sort(semver.rcompare);
36
+ console.log(sortedReleases)
25
37
 
26
- // Get reference of the tag
27
- const tagRef = await github.rest.git.getRef({ owner, repo, ref: `tags/${tag}` });
28
- const releaseSha = tagRef.data.object.sha;
38
+ if (sortedReleases.length > 0) {
39
+ const latestRedpandaReleaseVersion = sortedReleases[0];
29
40
 
30
- // Get the tag object to extract the commit hash
31
- const tagData = await github.rest.git.getTag({ owner, repo, tag_sha: releaseSha });
32
- latestRedpandaReleaseCommitHash = tagData.data.object.sha.substring(0, 7);
41
+ // Get the commit hash for the highest version tag
42
+ const commitData = await github.rest.git.getRef({
43
+ owner,
44
+ repo,
45
+ ref: `tags/v${latestRedpandaReleaseVersion}`
46
+ });
47
+ const latestRedpandaReleaseCommitHash = commitData.data.object.sha;
33
48
 
34
- return [latestRedpandaReleaseVersion, latestRedpandaReleaseCommitHash];
49
+ return [latestRedpandaReleaseVersion, latestRedpandaReleaseCommitHash.substring(0, 7)];
50
+ } else {
51
+ console.log("No valid semver releases found for Redpanda.");
52
+ return [null, null];
53
+ }
35
54
  } catch (error) {
36
- console.error(error);
55
+ console.error('Failed to fetch Redpanda release information:', error);
37
56
  return [null, null];
38
57
  }
39
- };
58
+ };
@@ -1,70 +1,70 @@
1
- /* Example:
2
- antora:
3
- extensions:
4
- - require: ./extensions/setLatestVersion.js
5
- */
6
-
7
1
  const GetLatestRedpandaVersion = require('./get-latest-redpanda-version');
8
2
  const GetLatestConsoleVersion = require('./get-latest-console-version');
9
3
  const GetLatestOperatorVersion = require('./get-latest-operator-version');
10
- const chalk = require('chalk')
11
-
4
+ const GetLatestHelmChartVersion = require('./get-latest-redpanda-helm-version');
5
+ const chalk = require('chalk');
12
6
 
13
7
  module.exports.register = function ({ config }) {
14
- const logger = this.getLogger('set-latest-version-extension')
8
+ const logger = this.getLogger('set-latest-version-extension');
15
9
  if (!process.env.REDPANDA_GITHUB_TOKEN) {
16
10
  logger.warn('REDPANDA_GITHUB_TOKEN environment variable not set. Attempting unauthenticated request.');
17
11
  }
18
- this
19
- .on('contentClassified', async ({ contentCatalog }) => {
20
- try {
21
- const LatestRedpandaVersion = await GetLatestRedpandaVersion();
22
- const LatestConsoleVersion = await GetLatestConsoleVersion();
23
- const LatestOperatorVersion = await GetLatestOperatorVersion();
24
- if (LatestRedpandaVersion.length !== 2 || !LatestRedpandaVersion[0]) {
25
- logger.warn('Failed to get the latest Redpanda version - using defaults');
26
- }
27
- if (!LatestConsoleVersion) {
28
- logger.warn(`Failed to get latest Console version from GitHub - using default`)
29
- }
30
- if (!LatestOperatorVersion) {
31
- logger.warn(`Failed to get latest Operator version from GitHub - using default`)
32
- }
33
- const components = await contentCatalog.getComponents();
34
- for (let i = 0; i < components.length; i++) {
35
- let component = components[i];
36
12
 
37
- component.versions.forEach(({name, version, asciidoc}) => {
38
- if (LatestConsoleVersion) {
39
- asciidoc.attributes['latest-console-version'] = `${LatestConsoleVersion}`;
40
- logger.info(`Set Redpanda Console version to')} ${LatestConsoleVersion} in ${name} ${version}`);
41
- }
42
- })
13
+ this.on('contentClassified', async ({ contentCatalog }) => {
14
+ try {
15
+ const results = await Promise.allSettled([
16
+ GetLatestRedpandaVersion(),
17
+ GetLatestConsoleVersion(),
18
+ GetLatestOperatorVersion(),
19
+ GetLatestHelmChartVersion()
20
+ ]);
43
21
 
44
- if (!component.latest.asciidoc) {
45
- component.latest.asciidoc = {};
46
- }
22
+ // Extracting results with fallbacks if promises were rejected
23
+ const LatestRedpandaVersion = results[0].status === 'fulfilled' ? results[0].value : null;
24
+ const LatestConsoleVersion = results[1].status === 'fulfilled' ? results[1].value : null;
25
+ const LatestOperatorVersion = results[2].status === 'fulfilled' ? results[2].value : null;
26
+ const LatestHelmChartVersion = results[3].status === 'fulfilled' ? results[3].value : null;
47
27
 
48
- if (!component.latest.asciidoc.attributes) {
49
- component.latest.asciidoc.attributes = {};
28
+ const components = await contentCatalog.getComponents();
29
+ components.forEach(component => {
30
+ component.versions.forEach(({ name, version, asciidoc }) => {
31
+ if (LatestConsoleVersion) {
32
+ asciidoc.attributes['latest-console-version'] = LatestConsoleVersion;
33
+ logger.info(`Set Redpanda Console version to ${LatestConsoleVersion} in ${name} ${version}`);
50
34
  }
35
+ });
51
36
 
52
- if (LatestRedpandaVersion.length !== 2 || !LatestRedpandaVersion[0]) continue;
37
+ if (!component.latest.asciidoc) {
38
+ component.latest.asciidoc = { attributes: {} };
39
+ }
53
40
 
54
- component.latest.asciidoc.attributes['full-version'] = `${LatestRedpandaVersion[0]}`;
55
- component.latest.asciidoc.attributes['latest-release-commit'] = `${LatestRedpandaVersion[1]}`;
56
- logger.info(`Set the latest Redpanda version to ${LatestRedpandaVersion[0]} ${LatestRedpandaVersion[1]}`)
41
+ // Handle each version setting with appropriate logging
42
+ if (LatestRedpandaVersion) {
43
+ component.latest.asciidoc.attributes['full-version'] = LatestRedpandaVersion[0];
44
+ component.latest.asciidoc.attributes['latest-release-commit'] = LatestRedpandaVersion[1];
45
+ logger.info(`Set the latest Redpanda version to ${LatestRedpandaVersion[0]} ${LatestRedpandaVersion[1]}`);
46
+ } else {
47
+ logger.warn("Failed to get the latest Redpanda version - using defaults");
48
+ }
57
49
 
58
- if (!LatestOperatorVersion) continue;
50
+ if (LatestOperatorVersion) {
51
+ component.latest.asciidoc.attributes['latest-operator-version'] = LatestOperatorVersion;
52
+ logger.info(`Set the latest Redpanda Operator version to ${LatestOperatorVersion}`);
53
+ } else {
54
+ logger.warn("Failed to get the latest Operator version from GitHub - using default");
55
+ }
59
56
 
60
- component.latest.asciidoc.attributes['latest-operator-version'] = `${LatestOperatorVersion}`;
61
- logger.info(`Set the latest Redpanda Operator version to ${LatestOperatorVersion}`)
57
+ if (LatestHelmChartVersion) {
58
+ component.latest.asciidoc.attributes['latest-redpanda-helm-chart-version'] = LatestHelmChartVersion;
59
+ logger.info(`Set the latest Redpanda Helm chart version to ${LatestHelmChartVersion}`);
60
+ } else {
61
+ logger.warn("Failed to get the latest Helm Chart version - using default");
62
62
  }
63
- console.log(`${chalk.green('Set Redpanda Console version to')} ${chalk.bold(LatestConsoleVersion)}`);
64
- console.log(`${chalk.green('Set the latest Redpanda version to')} ${chalk.bold(LatestRedpandaVersion[0])} ${chalk.bold(LatestRedpandaVersion[1])}`)
65
- console.log(`${chalk.green('Set the latest Redpanda Operator version to')} ${chalk.bold(LatestOperatorVersion)}`)
66
- } catch(error) {
67
- logger.warn(error)
68
- }
69
- })
70
- }
63
+ });
64
+
65
+ console.log(`${chalk.green('Updated Redpanda documentation versions successfully.')}`);
66
+ } catch (error) {
67
+ logger.error(`Error updating versions: ${error}`);
68
+ }
69
+ });
70
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redpanda-data/docs-extensions-and-macros",
3
- "version": "3.2.7",
3
+ "version": "3.2.9",
4
4
  "description": "Antora extensions and macros developed for Redpanda documentation.",
5
5
  "keywords": [
6
6
  "antora",
@@ -34,6 +34,7 @@
34
34
  "./extensions/version-fetcher/set-latest-version": "./extensions/version-fetcher/set-latest-version.js",
35
35
  "./extensions/validate-attributes": "./extensions/validate-attributes.js",
36
36
  "./extensions/find-related-docs": "./extensions/find-related-docs.js",
37
+ "./extensions/unpublish-pages": "./extensions/unpublish-pages.js",
37
38
  "./extensions/find-related-labs": "./extensions/find-related-labs.js",
38
39
  "./extensions/modify-redirects": "./extensions/produce-redirects.js",
39
40
  "./extensions/algolia-indexer/index": "./extensions/algolia-indexer/index.js",