Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/warm-actors-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"lingo.dev": minor
---

add "ci" command
2 changes: 2 additions & 0 deletions action/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"name": "@lingo.dev/~action",
"private": true,
"type": "module",
"main": "build/main.js",
"types": "build/main.d.ts",
"scripts": {
"build": "tsc"
},
Expand Down
31 changes: 2 additions & 29 deletions action/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
import createOra from "ora";
import main from "./main.js";

import { IIntegrationFlow } from "./flows/_base.js";
import { PullRequestFlow } from "./flows/pull-request.js";
import { InBranchFlow } from "./flows/in-branch.js";
import { getPlatformKit } from "./platforms/index.js";

(async function main() {
const ora = createOra();
const platformKit = getPlatformKit();
const { isPullRequestMode } = platformKit.config;

ora.info(`Pull request mode: ${isPullRequestMode ? "on" : "off"}`);

const flow: IIntegrationFlow = isPullRequestMode
? new PullRequestFlow(ora, platformKit)
: new InBranchFlow(ora, platformKit);

const canRun = await flow.preRun?.();
if (canRun === false) {
return;
}

const hasChanges = await flow.run();
if (!hasChanges) {
return;
}

await flow.postRun?.();
})();
main();
3 changes: 3 additions & 0 deletions action/src/main.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module "@lingo.dev/~action" {
export default function main(): Promise<void>;
}
30 changes: 30 additions & 0 deletions action/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import createOra from "ora";

import { IIntegrationFlow } from "./flows/_base.js";
import { PullRequestFlow } from "./flows/pull-request.js";
import { InBranchFlow } from "./flows/in-branch.js";
import { getPlatformKit } from "./platforms/index.js";

export default async function main() {
const ora = createOra();
const platformKit = getPlatformKit();
const { isPullRequestMode } = platformKit.config;

ora.info(`Pull request mode: ${isPullRequestMode ? "on" : "off"}`);

const flow: IIntegrationFlow = isPullRequestMode
? new PullRequestFlow(ora, platformKit)
: new InBranchFlow(ora, platformKit);

const canRun = await flow.preRun?.();
if (canRun === false) {
return;
}

const hasChanges = await flow.run();
if (!hasChanges) {
return;
}

await flow.postRun?.();
}
2 changes: 1 addition & 1 deletion action/src/platforms/bitbucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface BitbucketConfig {
export class BitbucketPlatformKit extends PlatformKit<BitbucketConfig> {
private _bb?: ReturnType<typeof Bitbucket>;

get bb() {
private get bb() {
if (!this._bb) {
this._bb = new Bitbucket({
auth: { token: this.platformConfig.bbToken || "" },
Expand Down
2 changes: 1 addition & 1 deletion action/src/platforms/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { execSync } from "child_process";
export class GitHubPlatformKit extends PlatformKit {
private _octokit?: Octokit;

get octokit() {
private get octokit(): Octokit {
if (!this._octokit) {
this._octokit = new Octokit({ auth: this.platformConfig.ghToken });
}
Expand Down
2 changes: 1 addition & 1 deletion action/src/platforms/gitlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class GitlabPlatformKit extends PlatformKit {
process.chdir(this.platformConfig.projectDir);
}

get gitlab() {
private get gitlab(): InstanceType<typeof Gitlab> {
if (!this._gitlab) {
this._gitlab = new Gitlab({
token: this.platformConfig.glToken || "",
Expand Down
4 changes: 3 additions & 1 deletion action/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"target": "ESNext",
"rootDir": "src",
"outDir": "build",
"allowUnreachableCode": true
"allowUnreachableCode": true,
"declaration": true,
"declarationMap": true
},
"include": ["src/**/*.ts", "src/**/*.tsx"],
"exclude": ["src/**/*.spec.ts", "src/**/*.spec.tsx"]
Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"@inquirer/prompts": "^7.2.3",
"@lingo.dev/_sdk": "workspace:*",
"@lingo.dev/_spec": "workspace:*",
"@lingo.dev/~action": "workspace:*",
"@modelcontextprotocol/sdk": "^1.5.0",
"@paralleldrive/cuid2": "^2.2.2",
"chalk": "^5.4.1",
Expand Down
55 changes: 55 additions & 0 deletions packages/cli/src/cli/cmd/ci.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Command } from "interactive-commander";
import { getSettings } from "../utils/settings";
import { createAuthenticator } from "../utils/auth";
import main from "@lingo.dev/~action";

interface CIOptions {
pullRequest?: boolean;
commitMessage?: string;
pullRequestTitle?: string;
workingDirectory?: string;
processOwnCommits?: boolean;
}

export default new Command()
.command("ci")
.description("Run Lingo.dev CI/CD action")
.helpOption("-h, --help", "Show help")
.option("--pull-request", "Create a pull request with the changes", false)
.option("--commit-message <message>", "Commit message")
.option("--pull-request-title <title>", "Pull request title")
.option("--working-directory <dir>", "Working directory")
.option("--process-own-commits", "Process commits made by this action", false)
.action(async (options: CIOptions, program) => {
const apiKey = program.args[0];
const settings = getSettings(apiKey);

if (!settings.auth.apiKey) {
console.error("No API key provided");
return;
}

const authenticator = createAuthenticator({
apiUrl: settings.auth.apiUrl,
apiKey: settings.auth.apiKey,
});
const auth = await authenticator.whoami();

if (!auth) {
console.error("Not authenticated");
return;
}

const env = {
LINGODOTDEV_API_KEY: settings.auth.apiKey,
LINGODOTDEV_PULL_REQUEST: options.pullRequest?.toString() || "false",
...(options.commitMessage && { LINGODOTDEV_COMMIT_MESSAGE: options.commitMessage }),
...(options.pullRequestTitle && { LINGODOTDEV_PULL_REQUEST_TITLE: options.pullRequestTitle }),
...(options.workingDirectory && { LINGODOTDEV_WORKING_DIRECTORY: options.workingDirectory }),
...(options.processOwnCommits && { LINGODOTDEV_PROCESS_OWN_COMMITS: options.processOwnCommits.toString() }),
};

process.env = { ...process.env, ...env };

main();
});
2 changes: 2 additions & 0 deletions packages/cli/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import i18nCmd from "./cmd/i18n";
import lockfileCmd from "./cmd/lockfile";
import cleanupCmd from "./cmd/cleanup";
import mcpCmd from "./cmd/mcp";
import ciCmd from "./cmd/ci";

import packageJson from "../../package.json";

Expand Down Expand Up @@ -42,6 +43,7 @@ Website: https://lingo.dev
.addCommand(lockfileCmd)
.addCommand(cleanupCmd)
.addCommand(mcpCmd)
.addCommand(ciCmd)
.exitOverride((err) => {
// Exit with code 0 when help or version is displayed
if (err.code === "commander.helpDisplayed" || err.code === "commander.version" || err.code === "commander.help") {
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.