|
| 1 | +import { Command } from "interactive-commander"; |
| 2 | +import { getSettings } from "../utils/settings"; |
| 3 | +import { createAuthenticator } from "../utils/auth"; |
| 4 | +import main from "../../action/src/main"; |
| 5 | + |
| 6 | +interface CIOptions { |
| 7 | + pullRequest?: boolean; |
| 8 | + commitMessage?: string; |
| 9 | + pullRequestTitle?: string; |
| 10 | + workingDirectory?: string; |
| 11 | + processOwnCommits?: boolean; |
| 12 | +} |
| 13 | + |
| 14 | +export default new Command() |
| 15 | + .command("ci") |
| 16 | + .description("Run Lingo.dev CI/CD action") |
| 17 | + .helpOption("-h, --help", "Show help") |
| 18 | + .option("--pull-request", "Create a pull request with the changes", false) |
| 19 | + .option("--commit-message <message>", "Commit message") |
| 20 | + .option("--pull-request-title <title>", "Pull request title") |
| 21 | + .option("--working-directory <dir>", "Working directory") |
| 22 | + .option("--process-own-commits", "Process commits made by this action", false) |
| 23 | + .action(async (options: CIOptions, program) => { |
| 24 | + const apiKey = program.args[0]; |
| 25 | + const settings = getSettings(apiKey); |
| 26 | + |
| 27 | + if (!settings.auth.apiKey) { |
| 28 | + console.error("No API key provided"); |
| 29 | + return; |
| 30 | + } |
| 31 | + |
| 32 | + const authenticator = createAuthenticator({ |
| 33 | + apiUrl: settings.auth.apiUrl, |
| 34 | + apiKey: settings.auth.apiKey, |
| 35 | + }); |
| 36 | + const auth = await authenticator.whoami(); |
| 37 | + |
| 38 | + if (!auth) { |
| 39 | + console.error("Not authenticated"); |
| 40 | + return; |
| 41 | + } |
| 42 | + |
| 43 | + const env = { |
| 44 | + LINGODOTDEV_API_KEY: settings.auth.apiKey, |
| 45 | + LINGODOTDEV_PULL_REQUEST: options.pullRequest?.toString() || "false", |
| 46 | + ...(options.commitMessage && { LINGODOTDEV_COMMIT_MESSAGE: options.commitMessage }), |
| 47 | + ...(options.pullRequestTitle && { LINGODOTDEV_PULL_REQUEST_TITLE: options.pullRequestTitle }), |
| 48 | + ...(options.workingDirectory && { LINGODOTDEV_WORKING_DIRECTORY: options.workingDirectory }), |
| 49 | + ...(options.processOwnCommits && { LINGODOTDEV_PROCESS_OWN_COMMITS: options.processOwnCommits.toString() }), |
| 50 | + }; |
| 51 | + |
| 52 | + process.env = { ...process.env, ...env }; |
| 53 | + |
| 54 | + main(); |
| 55 | + }); |
0 commit comments