Skip to content

Commit

Permalink
fix: Add more details on error message
Browse files Browse the repository at this point in the history
  • Loading branch information
uanid committed Jun 10, 2024
1 parent 52a671b commit 8d357db
Show file tree
Hide file tree
Showing 4 changed files with 13,020 additions and 13,023 deletions.
14 changes: 2 additions & 12 deletions lib/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,11 @@ export async function publish(pluginConfig: InputPluginConfig, context: PublishC
const chart = await loadHelmChart(chartDir);
if (ociRegistry) {
await publishChartToOCIRegistry(chartDirectory, ociRegistry, chart.name, chart.version);
context.logger.log(
"Chart %s:%s successfully published to %s.",
chart.name,
chart.version,
ociRegistry
);
context.logger.log("Chart %s:%s successfully published to %s.", chart.name, chart.version, ociRegistry);
}
if (chartRepository) {
await publishChartToChartRepository(chartDirectory);
context.logger.log(
"Chart %s:%s successfully published to %s.",
chart.name,
chart.version,
chartRepository
);
context.logger.log("Chart %s:%s successfully published to %s.", chart.name, chart.version, chartRepository);
}
}

Expand Down
21 changes: 13 additions & 8 deletions lib/verifyConditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import {VerifyConditionsContext} from "semantic-release";
export async function verifyConditions(pluginConfig: InputPluginConfig, context: VerifyConditionsContext): Promise<void> {
const {ociRegistry, chartRepository} = validateAndMergeConfig(pluginConfig);
if (ociRegistry) {
const {username, password} = resolveOCIRegistryCredentials(context.env);
const {username, password} = resolveOCIRegistryCredentials(context);
await verifyOCIRegistry(ociRegistry, username, password);
}
if (chartRepository) {
const {username, password} = resolveChartRepositoryCredentials(context.env);
const {username, password} = resolveChartRepositoryCredentials(context);
await verifyChartRepository(chartRepository, username, password);
}
if (!ociRegistry && !chartRepository) {
throw new Error("Either `ociRegistry` or `chartRepository` must be set.");
}
}

async function installHelmPushPlugin() {
Expand Down Expand Up @@ -63,23 +66,25 @@ interface BasicAuth {
password: string;
}

function resolveOCIRegistryCredentials(env: Record<string, string>): BasicAuth {
const {HELM_REGISTRY_USERNAME, HELM_REGISTRY_PASSWORD} = env;
function resolveOCIRegistryCredentials(context: VerifyConditionsContext): BasicAuth {
const {HELM_REGISTRY_USERNAME, HELM_REGISTRY_PASSWORD} = context.env;
if (HELM_REGISTRY_USERNAME && HELM_REGISTRY_PASSWORD) {
return {
username: HELM_REGISTRY_USERNAME,
password: HELM_REGISTRY_PASSWORD,
};
}

context.logger.log("Environment variables HELM_REGISTRY_USERNAME and HELM_REGISTRY_PASSWORD are not set. fallback to use HELM_REPOSITORY_USERNAME and HELM_REPOSITORY_PASSWORD.");

// fallback to resolve repository credentials
return resolveChartRepositoryCredentials(env);
return resolveChartRepositoryCredentials(context);
}

function resolveChartRepositoryCredentials(env: Record<string, string>): BasicAuth {
const {HELM_REPOSITORY_USERNAME, HELM_REPOSITORY_PASSWORD} = env;
function resolveChartRepositoryCredentials(context: VerifyConditionsContext): BasicAuth {
const {HELM_REPOSITORY_USERNAME, HELM_REPOSITORY_PASSWORD} = context.env;
if (!HELM_REPOSITORY_USERNAME || !HELM_REPOSITORY_PASSWORD) {
throw new Error("Missing chart repository credentials");
throw new Error("Environment variables HELM_REPOSITORY_USERNAME and HELM_REPOSITORY_PASSWORD are required.");
}
return {
username: HELM_REPOSITORY_USERNAME,
Expand Down
Loading

0 comments on commit 8d357db

Please sign in to comment.