Skip to content

Commit e40c985

Browse files
committed
feat(cli): add "ci" command (#598)
Execute CI/CD action via `npx lingo.dev ci`
1 parent a4617e0 commit e40c985

File tree

13 files changed

+111
-34
lines changed

13 files changed

+111
-34
lines changed

.changeset/warm-actors-confess.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"lingo.dev": minor
3+
"@lingo.dev/_action": patch
4+
---
5+
6+
add "ci" command

action/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
2-
"name": "@lingo.dev/~action",
2+
"name": "@lingo.dev/_action",
33
"private": true,
44
"type": "module",
5+
"main": "build/main.js",
6+
"types": "build/main.d.ts",
57
"scripts": {
68
"build": "tsc"
79
},

action/src/index.ts

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,3 @@
1-
import createOra from "ora";
1+
import main from "./main.js";
22

3-
import { IIntegrationFlow } from "./flows/_base.js";
4-
import { PullRequestFlow } from "./flows/pull-request.js";
5-
import { InBranchFlow } from "./flows/in-branch.js";
6-
import { getPlatformKit } from "./platforms/index.js";
7-
8-
(async function main() {
9-
const ora = createOra();
10-
const platformKit = getPlatformKit();
11-
const { isPullRequestMode } = platformKit.config;
12-
13-
ora.info(`Pull request mode: ${isPullRequestMode ? "on" : "off"}`);
14-
15-
const flow: IIntegrationFlow = isPullRequestMode
16-
? new PullRequestFlow(ora, platformKit)
17-
: new InBranchFlow(ora, platformKit);
18-
19-
const canRun = await flow.preRun?.();
20-
if (canRun === false) {
21-
return;
22-
}
23-
24-
const hasChanges = await flow.run();
25-
if (!hasChanges) {
26-
return;
27-
}
28-
29-
await flow.postRun?.();
30-
})();
3+
main();

action/src/main.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module "@lingo.dev/_action" {
2+
export default function main(): Promise<void>;
3+
}

action/src/main.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import createOra from "ora";
2+
3+
import { IIntegrationFlow } from "./flows/_base.js";
4+
import { PullRequestFlow } from "./flows/pull-request.js";
5+
import { InBranchFlow } from "./flows/in-branch.js";
6+
import { getPlatformKit } from "./platforms/index.js";
7+
8+
export default async function main() {
9+
const ora = createOra();
10+
const platformKit = getPlatformKit();
11+
const { isPullRequestMode } = platformKit.config;
12+
13+
ora.info(`Pull request mode: ${isPullRequestMode ? "on" : "off"}`);
14+
15+
const flow: IIntegrationFlow = isPullRequestMode
16+
? new PullRequestFlow(ora, platformKit)
17+
: new InBranchFlow(ora, platformKit);
18+
19+
const canRun = await flow.preRun?.();
20+
if (canRun === false) {
21+
return;
22+
}
23+
24+
const hasChanges = await flow.run();
25+
if (!hasChanges) {
26+
return;
27+
}
28+
29+
await flow.postRun?.();
30+
}

action/src/platforms/bitbucket.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface BitbucketConfig {
1515
export class BitbucketPlatformKit extends PlatformKit<BitbucketConfig> {
1616
private _bb?: ReturnType<typeof Bitbucket>;
1717

18-
get bb() {
18+
private get bb() {
1919
if (!this._bb) {
2020
this._bb = new Bitbucket({
2121
auth: { token: this.platformConfig.bbToken || "" },

action/src/platforms/github.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { execSync } from "child_process";
77
export class GitHubPlatformKit extends PlatformKit {
88
private _octokit?: Octokit;
99

10-
get octokit() {
10+
private get octokit(): Octokit {
1111
if (!this._octokit) {
1212
this._octokit = new Octokit({ auth: this.platformConfig.ghToken });
1313
}

action/src/platforms/gitlab.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class GitlabPlatformKit extends PlatformKit {
1515
process.chdir(this.platformConfig.projectDir);
1616
}
1717

18-
get gitlab() {
18+
private get gitlab(): InstanceType<typeof Gitlab> {
1919
if (!this._gitlab) {
2020
this._gitlab = new Gitlab({
2121
token: this.platformConfig.glToken || "",

action/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"target": "ESNext",
1313
"rootDir": "src",
1414
"outDir": "build",
15-
"allowUnreachableCode": true
15+
"allowUnreachableCode": true,
16+
"declaration": true,
17+
"declarationMap": true
1618
},
1719
"include": ["src/**/*.ts", "src/**/*.tsx"],
1820
"exclude": ["src/**/*.spec.ts", "src/**/*.spec.tsx"]

packages/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"@inquirer/prompts": "^7.2.3",
6262
"@lingo.dev/_sdk": "workspace:*",
6363
"@lingo.dev/_spec": "workspace:*",
64+
"@lingo.dev/_action": "workspace:*",
6465
"@modelcontextprotocol/sdk": "^1.5.0",
6566
"@paralleldrive/cuid2": "^2.2.2",
6667
"chalk": "^5.4.1",

0 commit comments

Comments
 (0)