Files
api/plugin/builder/cli/common-environment.ts
Pujit Mehrotra 3cfe9fe9ee build: replace hash with build increment in slackware txz pkg (#1449)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Introduced support for specifying and propagating a build number
throughout the build process, including command-line options and
workflow inputs.
* TXZ package naming and URLs now include the build number for improved
traceability.

* **Improvements**
* Enhanced robustness in locating TXZ files with improved fallback
logic, especially in CI environments.
* Improved flexibility and validation of environment schema for plugin
builds.

* **Style**
  * Minor formatting corrections for consistency and readability.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1210677942019563
2025-07-01 10:57:39 -04:00

51 lines
1.4 KiB
TypeScript

import { Command } from "commander";
import { z } from "zod";
import { getVersion } from "../utils/version";
/**
* Common base environment fields shared between different build setups
*/
export const baseEnvSchema = z.object({
ci: z.boolean().optional().default(false),
apiVersion: z.string(),
baseUrl: z.string().url(),
tag: z.string().optional().default(""),
/** i.e. Slackware build number */
buildNumber: z.coerce.number().int().default(1),
});
export type BaseEnv = z.infer<typeof baseEnvSchema>;
/**
* Generate a default base URL for local development
*/
export const getDefaultBaseUrl = (): string => {
return process.env.CI === "true"
? "This is a CI build, please set the base URL manually"
: `http://${process.env.HOST_LAN_IP || "localhost"}:5858`;
};
/**
* Common CLI options shared across different command setups
*/
export const addCommonOptions = (program: Command) => {
return program
.option("--ci", "CI mode", process.env.CI === "true")
.requiredOption(
"--api-version <version>",
"API version",
process.env.API_VERSION || getVersion().version
)
.requiredOption(
"--base-url <url>",
"Base URL for assets",
getDefaultBaseUrl()
)
.option(
"--tag <tag>",
"Tag (used for PR and staging builds)",
process.env.TAG
)
.option("--build-number <number>", "Build number");
};