Files
Heimdall/scripts/ci/renovate-preflight.mjs
T
arnaud.dartois 636154572b
Heimdall Gitea / Detect CI scope (push) Successful in 6s
Heimdall Gitea / Build and tests (push) Successful in 19m19s
Heimdall Gitea / Publish versioned release (push) Skipped
Heimdall Gitea / Build and scan server image (push) Successful in 6m13s
Heimdall Gitea / Build and scan agent image (push) Successful in 14m44s
Heimdall Gitea / Publish Docker Hub latest tags (push) Successful in 1m48s
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Successful in 19m9s
Heimdall Gitea / CI policy (push) Successful in 10s
Complete remaining Heimdall features and acceptance
Merge pull request #138

Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2026-11-06 11:14:49 +01:00

61 lines
2.1 KiB
JavaScript

import { pathToFileURL } from 'node:url';
const endpoint = process.env.RENOVATE_ENDPOINT;
const token = process.env.RENOVATE_TOKEN;
const repository = 'arnaud.dartois/Heimdall';
export function validateEndpoint(value) {
let parsed;
try {
parsed = new URL(value);
} catch {
throw new Error('GITEA_API_ENDPOINT must be a valid HTTPS URL ending in /api/v1.');
}
if (parsed.protocol !== 'https:' || parsed.username || parsed.password ||
parsed.search || parsed.hash || !parsed.pathname.replace(/\/$/, '').endsWith('/api/v1')) {
throw new Error('GITEA_API_ENDPOINT must be a valid HTTPS URL ending in /api/v1.');
}
return parsed.href.replace(/\/$/, '');
}
export async function checkGiteaAccess(apiEndpoint, accessToken, fetchImpl = fetch) {
const root = `${validateEndpoint(apiEndpoint)}/`;
const urls = [new URL('user', root), new URL(`repos/${repository}`, root)];
for (const url of urls) {
let response;
try {
response = await fetchImpl(url, {
headers: { Authorization: `token ${accessToken}`, Accept: 'application/json' },
signal: AbortSignal.timeout(10_000),
});
} catch (error) {
throw new Error(`Gitea API preflight could not connect (${error?.name ?? 'network error'}).`);
}
if (!response.ok) {
const detail = response.status === 401 || response.status === 403
? 'Check that RENOVATE_TOKEN is active and has repository read and write access.'
: 'Check GITEA_API_ENDPOINT and the Gitea API availability.';
throw new Error(`Gitea API preflight failed with HTTP ${response.status}. ${detail}`);
}
}
}
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
if (!token) {
console.error('RENOVATE_TOKEN is missing. Configure it as a Gitea Actions secret.');
process.exitCode = 1;
} else {
try {
await checkGiteaAccess(endpoint, token);
console.log('Renovate token authenticated with Gitea and can read the target repository.');
} catch (error) {
console.error(error.message);
process.exitCode = 1;
}
}
}