@redpanda-data/docs-extensions-and-macros 5.35.0 → 5.35.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/bin/doc-tools.js +6 -6
- package/cli-utils/enterprise-sources.js +3 -3
- package/cli-utils/github-token.js +53 -13
- package/cli-utils/octokit-client.js +2 -2
- package/cli-utils/self-managed-docs-branch.js +2 -2
- package/extensions/version-fetcher/set-latest-version.js +6 -3
- package/package.json +1 -1
- package/tools/get-redpanda-version.js +2 -2
- package/tools/property-extractor/rp-util-fetch.js +2 -2
- package/tools/rpk-docs/rpk-docs-handler.js +2 -2
package/bin/doc-tools.js
CHANGED
|
@@ -122,9 +122,9 @@ programCli
|
|
|
122
122
|
* - A GitHub token with access to redpanda-data/streaming-enterprise, which is
|
|
123
123
|
* private. Redpanda releases are published there now, and the old public repo
|
|
124
124
|
* is frozen, so this command exits rather than report a stale version when it
|
|
125
|
-
* has no token. Resolved from
|
|
126
|
-
*
|
|
127
|
-
*
|
|
125
|
+
* has no token. Resolved from REDPANDA_GITHUB_TOKEN, ACTIONS_BOT_TOKEN,
|
|
126
|
+
* GITHUB_TOKEN, VBOT_GITHUB_API_TOKEN, GH_TOKEN, or GIT_CREDENTIALS, in that
|
|
127
|
+
* priority order (an API call, so the git credential is the last resort)
|
|
128
128
|
*/
|
|
129
129
|
programCli
|
|
130
130
|
.command('get-redpanda-version')
|
|
@@ -1908,7 +1908,7 @@ automation
|
|
|
1908
1908
|
*
|
|
1909
1909
|
* @requirements
|
|
1910
1910
|
* - GitHub token with access to redpanda-data/cloudv2-infra repository
|
|
1911
|
-
* - Token is resolved from
|
|
1911
|
+
* - Token is resolved from REDPANDA_GITHUB_TOKEN, ACTIONS_BOT_TOKEN, GITHUB_TOKEN, VBOT_GITHUB_API_TOKEN, GH_TOKEN, or GIT_CREDENTIALS, in that priority order (an API call, so the git credential is the last resort)
|
|
1912
1912
|
* - Internet connection to access GitHub API
|
|
1913
1913
|
*/
|
|
1914
1914
|
automation
|
|
@@ -1925,7 +1925,7 @@ automation
|
|
|
1925
1925
|
.option('--dry-run', 'Print output to stdout instead of writing file')
|
|
1926
1926
|
.action(async (options, command) => {
|
|
1927
1927
|
const { generateCloudRegions } = require('../tools/cloud-regions/generate-cloud-regions.js')
|
|
1928
|
-
const {
|
|
1928
|
+
const { getGitHubApiToken } = require('../cli-utils/github-token')
|
|
1929
1929
|
|
|
1930
1930
|
try {
|
|
1931
1931
|
// The default output path holds the unfiltered table, so a filtered run
|
|
@@ -1947,7 +1947,7 @@ automation
|
|
|
1947
1947
|
const absOutput = options.dryRun
|
|
1948
1948
|
? undefined
|
|
1949
1949
|
: resolveInsideRepo(repoRoot, options.output, '--output')
|
|
1950
|
-
const token =
|
|
1950
|
+
const token = getGitHubApiToken()
|
|
1951
1951
|
if (!token) {
|
|
1952
1952
|
throw new Error('GitHub token is required to fetch from private cloudv2-infra repo.')
|
|
1953
1953
|
}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
const fs = require('fs')
|
|
14
14
|
const path = require('path')
|
|
15
|
-
const {
|
|
15
|
+
const { getGitHubApiToken } = require('./github-token')
|
|
16
16
|
|
|
17
17
|
const RAW = 'https://raw.githubusercontent.com'
|
|
18
18
|
|
|
@@ -62,7 +62,7 @@ async function discardBody (resp) {
|
|
|
62
62
|
* check runs on a weekly cron where nobody is watching live.
|
|
63
63
|
*
|
|
64
64
|
* @param {object} [deps]
|
|
65
|
-
* @param {string|null} [deps.token] - GitHub token (defaults to
|
|
65
|
+
* @param {string|null} [deps.token] - GitHub token (defaults to getGitHubApiToken())
|
|
66
66
|
* @param {Function} [deps.fetchImpl] - fetch implementation (defaults to global fetch)
|
|
67
67
|
* @param {Function} [deps.warn] - warning sink (defaults to console.warn)
|
|
68
68
|
* @param {Function} [deps.sleep] - delay implementation, for tests
|
|
@@ -72,7 +72,7 @@ async function discardBody (resp) {
|
|
|
72
72
|
* check that never ran. Failures without a sourceName throw instead.
|
|
73
73
|
*/
|
|
74
74
|
function createSourceFetcher (deps = {}) {
|
|
75
|
-
const ghToken = deps.token !== undefined ? deps.token :
|
|
75
|
+
const ghToken = deps.token !== undefined ? deps.token : getGitHubApiToken()
|
|
76
76
|
const fetchImpl = deps.fetchImpl || ((...args) => fetch(...args))
|
|
77
77
|
const warn = deps.warn || ((msg) => console.warn(msg))
|
|
78
78
|
const sleep = deps.sleep || ((ms) => new Promise((resolve) => setTimeout(resolve, ms)))
|
|
@@ -47,9 +47,25 @@ function getTokenFromGitCredentials(credentials = process.env.GIT_CREDENTIALS) {
|
|
|
47
47
|
return null;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
const API_TOKEN_VARS = [
|
|
51
|
+
'REDPANDA_GITHUB_TOKEN',
|
|
52
|
+
'ACTIONS_BOT_TOKEN',
|
|
53
|
+
'GITHUB_TOKEN',
|
|
54
|
+
'VBOT_GITHUB_API_TOKEN',
|
|
55
|
+
'GH_TOKEN'
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
function firstApiTokenVar() {
|
|
59
|
+
for (const name of API_TOKEN_VARS) {
|
|
60
|
+
if (process.env[name]) return process.env[name];
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
50
65
|
/**
|
|
51
|
-
* Get GitHub token
|
|
52
|
-
*
|
|
66
|
+
* Get the GitHub token for git operations (clone, fetch, authenticated URLs).
|
|
67
|
+
*
|
|
68
|
+
* Checks, in priority order:
|
|
53
69
|
* 1. GIT_CREDENTIALS - Antora's credential store contents (github.com entry)
|
|
54
70
|
* 2. REDPANDA_GITHUB_TOKEN - Custom Redpanda token
|
|
55
71
|
* 3. ACTIONS_BOT_TOKEN - GitHub Actions bot token
|
|
@@ -57,21 +73,44 @@ function getTokenFromGitCredentials(credentials = process.env.GIT_CREDENTIALS) {
|
|
|
57
73
|
* 5. VBOT_GITHUB_API_TOKEN - Legacy bot token
|
|
58
74
|
* 6. GH_TOKEN - GitHub CLI default
|
|
59
75
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
76
|
+
* GIT_CREDENTIALS wins here on purpose: it is the credential Antora itself
|
|
77
|
+
* clones the content repos with, so anything else that clones in the same
|
|
78
|
+
* build should use the same identity. It is a git credential, not an API
|
|
79
|
+
* one; for REST calls use getGitHubApiToken().
|
|
64
80
|
*
|
|
65
81
|
* @returns {string|null} GitHub token or null if not found
|
|
66
82
|
*/
|
|
67
83
|
function getGitHubToken() {
|
|
68
|
-
return getTokenFromGitCredentials() ||
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
84
|
+
return getTokenFromGitCredentials() || firstApiTokenVar();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Get the GitHub token for REST API calls (Octokit, api.github.com,
|
|
89
|
+
* raw.githubusercontent.com).
|
|
90
|
+
*
|
|
91
|
+
* Same variables as getGitHubToken(), but GIT_CREDENTIALS comes LAST:
|
|
92
|
+
*
|
|
93
|
+
* 1. REDPANDA_GITHUB_TOKEN
|
|
94
|
+
* 2. ACTIONS_BOT_TOKEN
|
|
95
|
+
* 3. GITHUB_TOKEN
|
|
96
|
+
* 4. VBOT_GITHUB_API_TOKEN
|
|
97
|
+
* 5. GH_TOKEN
|
|
98
|
+
* 6. GIT_CREDENTIALS
|
|
99
|
+
*
|
|
100
|
+
* Why the different order: on the Netlify Antora sites GIT_CREDENTIALS holds
|
|
101
|
+
* a token scoped only to cloning the private docs content repos. Letting it
|
|
102
|
+
* outrank REDPANDA_GITHUB_TOKEN meant the release lookup against the private
|
|
103
|
+
* streaming-enterprise repo authenticated with a token that cannot see that
|
|
104
|
+
* repo, got a 404, and every latest-redpanda-* attribute went unset in the
|
|
105
|
+
* production build even though a token with access was sitting right there.
|
|
106
|
+
* An explicitly named API token always beats the git credential; the git
|
|
107
|
+
* credential remains a fallback so a build with only GIT_CREDENTIALS still
|
|
108
|
+
* authenticates.
|
|
109
|
+
*
|
|
110
|
+
* @returns {string|null} GitHub token or null if not found
|
|
111
|
+
*/
|
|
112
|
+
function getGitHubApiToken() {
|
|
113
|
+
return firstApiTokenVar() || getTokenFromGitCredentials();
|
|
75
114
|
}
|
|
76
115
|
|
|
77
116
|
/**
|
|
@@ -106,6 +145,7 @@ function hasGitHubToken() {
|
|
|
106
145
|
|
|
107
146
|
module.exports = {
|
|
108
147
|
getGitHubToken,
|
|
148
|
+
getGitHubApiToken,
|
|
109
149
|
getTokenFromGitCredentials,
|
|
110
150
|
getAuthenticatedGitHubUrl,
|
|
111
151
|
hasGitHubToken
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { Octokit } = require('@octokit/rest')
|
|
4
|
-
const {
|
|
4
|
+
const { getGitHubApiToken } = require('./github-token')
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Shared Octokit client instance for GitHub API access
|
|
@@ -14,7 +14,7 @@ const { getGitHubToken } = require('./github-token')
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
// Get authentication token from environment
|
|
17
|
-
const token =
|
|
17
|
+
const token = getGitHubApiToken()
|
|
18
18
|
|
|
19
19
|
// Configure Octokit options
|
|
20
20
|
const octokitOptions = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const yaml = require('js-yaml');
|
|
2
2
|
const { spawnSync } = require('child_process');
|
|
3
|
-
const {
|
|
3
|
+
const { getGitHubApiToken } = require('./github-token');
|
|
4
4
|
|
|
5
5
|
const ANTORA_URL = 'https://raw.githubusercontent.com/redpanda-data/docs/main/antora.yml'
|
|
6
6
|
|
|
@@ -23,7 +23,7 @@ const REJECTED_HINT = ' A GitHub token was sent but rejected, so it may be expir
|
|
|
23
23
|
*/
|
|
24
24
|
async function fetchRemoteAntoraVersion(deps = {}) {
|
|
25
25
|
const fetchImpl = deps.fetchImpl || fetch
|
|
26
|
-
const ghToken = 'token' in deps ? deps.token :
|
|
26
|
+
const ghToken = 'token' in deps ? deps.token : getGitHubApiToken()
|
|
27
27
|
|
|
28
28
|
let resp = await fetchImpl(ANTORA_URL, ghToken ? { headers: { Authorization: `Bearer ${ghToken}` } } : undefined)
|
|
29
29
|
const hint = ghToken ? REJECTED_HINT : TOKEN_HINT
|
|
@@ -10,10 +10,13 @@ module.exports.register = function ({ config }) {
|
|
|
10
10
|
const GetLatestConnectVersion = require('./get-latest-connect');
|
|
11
11
|
const logger = this.getLogger('set-latest-version-extension');
|
|
12
12
|
|
|
13
|
-
const {
|
|
13
|
+
const { getGitHubApiToken } = require('../../cli-utils/github-token');
|
|
14
14
|
// Shared with tools/bundle-openapi.js so there is one major.minor derivation.
|
|
15
15
|
const { toShortVersion } = require('../../cli-utils/version');
|
|
16
|
-
|
|
16
|
+
// API token, not the git one: GIT_CREDENTIALS (Antora's clone credential)
|
|
17
|
+
// is only a last resort here, because on Netlify it is scoped to the docs
|
|
18
|
+
// content repos and cannot see streaming-enterprise.
|
|
19
|
+
const token = getGitHubApiToken();
|
|
17
20
|
|
|
18
21
|
if (!token) {
|
|
19
22
|
// Unauthenticated requests still work for the public repos this
|
|
@@ -21,7 +24,7 @@ module.exports.register = function ({ config }) {
|
|
|
21
24
|
// version now comes from the private streaming-enterprise repo, whose
|
|
22
25
|
// API 404s without a token -- the latest-redpanda-* attributes are then
|
|
23
26
|
// left unset and pages fall back to their antora.yml values.
|
|
24
|
-
logger.warn('GitHub token not set (
|
|
27
|
+
logger.warn('GitHub token not set (REDPANDA_GITHUB_TOKEN, GITHUB_TOKEN, GH_TOKEN, or GIT_CREDENTIALS). The Redpanda version lookup against the private streaming-enterprise repo will fail and leave latest-redpanda-* attributes unset; other lookups proceed unauthenticated.');
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
this.on('contentClassified', async ({ contentCatalog }) => {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const GetLatestRedpandaVersion = require('../extensions/version-fetcher/get-latest-redpanda-version.js');
|
|
4
4
|
const { getPrereleaseFromAntora } = require('../cli-utils/antora-utils.js');
|
|
5
|
-
const {
|
|
5
|
+
const { getGitHubApiToken } = require('../cli-utils/github-token');
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Fetches and prints the latest Redpanda version and Docker repository.
|
|
@@ -20,7 +20,7 @@ module.exports = async function getRedpandaVersion({ beta = false, fromAntora =
|
|
|
20
20
|
const owner = 'redpanda-data';
|
|
21
21
|
const repo = 'streaming-enterprise';
|
|
22
22
|
|
|
23
|
-
if (!
|
|
23
|
+
if (!getGitHubApiToken()) {
|
|
24
24
|
console.error(`❌ redpanda-data/${repo} is a private repository.`);
|
|
25
25
|
console.error(' Set GH_TOKEN, REDPANDA_GITHUB_TOKEN, or GITHUB_TOKEN to a token with access.');
|
|
26
26
|
process.exit(1);
|
|
@@ -4,7 +4,7 @@ const { spawnSync } = require('child_process')
|
|
|
4
4
|
const fs = require('fs')
|
|
5
5
|
const os = require('os')
|
|
6
6
|
const path = require('path')
|
|
7
|
-
const { getGitHubToken } = require('../../cli-utils/github-token')
|
|
7
|
+
const { getGitHubToken, getGitHubApiToken } = require('../../cli-utils/github-token')
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* rp_util's config schema JSON, for any streaming-enterprise ref (tag,
|
|
@@ -287,7 +287,7 @@ const RELEASE_ASSET_TO_SCHEMA_KEY = {
|
|
|
287
287
|
* no release exists for this tag (caller should fall back to building)
|
|
288
288
|
*/
|
|
289
289
|
async function fetchPublishedSchema(tag) {
|
|
290
|
-
const token =
|
|
290
|
+
const token = getGitHubApiToken()
|
|
291
291
|
const headers = token ? { Authorization: `Bearer ${token}` } : {}
|
|
292
292
|
|
|
293
293
|
const releaseResp = await fetch(
|
|
@@ -1324,8 +1324,8 @@ function downloadRpkRelease(tag, destDir) {
|
|
|
1324
1324
|
// redpanda-data/redpanda. This function already has a fallback (the
|
|
1325
1325
|
// caller builds from source instead), so a missing token warns and
|
|
1326
1326
|
// returns null here rather than throwing the way the clone-only paths do.
|
|
1327
|
-
const {
|
|
1328
|
-
const token =
|
|
1327
|
+
const { getGitHubApiToken } = require('../../cli-utils/github-token')
|
|
1328
|
+
const token = getGitHubApiToken()
|
|
1329
1329
|
if (!token) {
|
|
1330
1330
|
console.warn('No GitHub token available for the private streaming-enterprise release download; falling back to a source build.')
|
|
1331
1331
|
return null
|