Skip to content

Commit b9ae384

Browse files
authored
fix(cli): skip auth when vNext is configured (#1996)
* fix(cli): skip auth when vNext is configured * chore: make api-key optional in action.yml
1 parent 466f910 commit b9ae384

File tree

4 files changed

+53
-17
lines changed

4 files changed

+53
-17
lines changed

.changeset/pink-heads-tap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"lingo.dev": patch
3+
---
4+
5+
When vNext is configured in i18n.json, the CI command no longer requires LINGODOTDEV_API_KEY or validates against the legacy endpoint. Only LINGO_API_KEY is needed. Parallel mode is automatically enabled for vNext projects.

action.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ inputs:
2929
required: false
3030
api-key:
3131
description: "Lingo.dev Platform API Key"
32-
required: true
32+
default: ""
33+
required: false
3334
pull-request:
3435
description: "Create a pull request with the changes"
3536
default: false

packages/cli/src/cli/cmd/ci/index.ts

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import path from "path";
12
import { Command } from "interactive-commander";
23
import createOra from "ora";
34
import { getSettings } from "../../utils/settings";
@@ -6,6 +7,7 @@ import { IIntegrationFlow } from "./flows/_base";
67
import { PullRequestFlow } from "./flows/pull-request";
78
import { InBranchFlow } from "./flows/in-branch";
89
import { getPlatformKit } from "./platforms";
10+
import { getConfig } from "../../utils/config";
911

1012
interface CIOptions {
1113
parallel?: boolean;
@@ -70,26 +72,54 @@ export default new Command()
7072
parseBooleanArg,
7173
)
7274
.action(async (options: CIOptions) => {
75+
const configDir = options.workingDirectory
76+
? path.resolve(process.cwd(), options.workingDirectory)
77+
: process.cwd();
78+
const originalCwd = process.cwd();
79+
let config;
80+
try {
81+
process.chdir(configDir);
82+
config = getConfig(false);
83+
} finally {
84+
process.chdir(originalCwd);
85+
}
86+
87+
const isVNext = !!config?.vNext;
88+
7389
const settings = getSettings(options.apiKey);
7490

75-
if (!settings.auth.apiKey) {
76-
console.error("No API key provided");
77-
return;
78-
}
91+
if (isVNext) {
92+
if (!settings.auth.vnext?.apiKey) {
93+
console.error(
94+
"No LINGO_API_KEY provided. vNext requires LINGO_API_KEY environment variable.",
95+
);
96+
return;
97+
}
98+
} else {
99+
if (!settings.auth.apiKey) {
100+
console.error("No API key provided");
101+
return;
102+
}
79103

80-
const authenticator = createAuthenticator({
81-
apiUrl: settings.auth.apiUrl,
82-
apiKey: settings.auth.apiKey,
83-
});
84-
const auth = await authenticator.whoami();
104+
const authenticator = createAuthenticator({
105+
apiUrl: settings.auth.apiUrl,
106+
apiKey: settings.auth.apiKey,
107+
});
85108

86-
if (!auth) {
87-
console.error("Not authenticated");
88-
return;
109+
const auth = await authenticator.whoami();
110+
if (!auth) {
111+
console.error("Not authenticated");
112+
return;
113+
}
89114
}
90115

91116
const env = {
92-
LINGODOTDEV_API_KEY: settings.auth.apiKey,
117+
...(settings.auth.apiKey && {
118+
LINGODOTDEV_API_KEY: settings.auth.apiKey,
119+
}),
120+
...(settings.auth.vnext?.apiKey && {
121+
LINGO_API_KEY: settings.auth.vnext.apiKey,
122+
}),
93123
LINGODOTDEV_PULL_REQUEST: options.pullRequest?.toString() || "false",
94124
...(options.commitMessage && {
95125
LINGODOTDEV_COMMIT_MESSAGE: options.commitMessage,
@@ -132,7 +162,7 @@ export default new Command()
132162
}
133163

134164
const hasChanges = await flow.run({
135-
parallel: options.parallel,
165+
parallel: isVNext || options.parallel,
136166
});
137167
if (!hasChanges) {
138168
return;

packages/cli/src/cli/cmd/ci/platforms/_base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export abstract class PlatformKit<
4747

4848
get config() {
4949
const env = Z.object({
50-
LINGODOTDEV_API_KEY: Z.string(),
50+
LINGODOTDEV_API_KEY: Z.string().optional(),
5151
LINGODOTDEV_PULL_REQUEST: Z.preprocess(
5252
(val) => val === "true" || val === true,
5353
Z.boolean(),
@@ -68,7 +68,7 @@ export abstract class PlatformKit<
6868
}).parse(process.env);
6969

7070
return {
71-
replexicaApiKey: env.LINGODOTDEV_API_KEY,
71+
replexicaApiKey: env.LINGODOTDEV_API_KEY || "",
7272
isPullRequestMode: env.LINGODOTDEV_PULL_REQUEST,
7373
commitMessage: env.LINGODOTDEV_COMMIT_MESSAGE || defaultMessage,
7474
pullRequestTitle: env.LINGODOTDEV_PULL_REQUEST_TITLE || defaultMessage,

0 commit comments

Comments
 (0)