@release-change/ci 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present Victor Brito
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # @release-change/ci
2
+
3
+ Get environment variables related to the CI
4
+
5
+ ![License: MIT](https://img.shields.io/github/license/release-change/release-change)
6
+ [![ESM-only package](https://img.shields.io/badge/package-ESM--only-ffe536)](https://nodejs.org/api/esm.html)
7
+ [![Conventional Commits 1.0.0](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white)](https://conventionalcommits.org)
8
+ [![Formatted with Biome](https://img.shields.io/badge/Formatted_with-Biome-60a5fa?style=flat&logo=biome)](https://biomejs.dev/)
9
+ ![NPM latest version](https://img.shields.io/npm/v/%40release-change%2Fci/latest)
10
+ ![Node support](https://img.shields.io/node/v/%40release-change%2Fci)
11
+ ![Build status](https://img.shields.io/github/actions/workflow/status/release-change/release-change/run-tests.yml)
12
+
13
+ ## Properties
14
+
15
+ - `isCi`: `true` if the current environment is a CI environment, `false` otherwise;
16
+ - `isPullRequest`: `true` if the current event is triggered by a pull request, `false` otherwise.
17
+
18
+ ## Supported CI environments
19
+
20
+ - [GitHub Actions](https://docs.github.com/en/actions/reference/workflows-and-actions/variables#default-environment-variables).
21
+
22
+ ## Copyright & licence
23
+
24
+ © 2025-present Victor Brito — Released under the [MIT licence](./LICENSE).
@@ -0,0 +1,8 @@
1
+ import type { CiConfig } from "@release-change/shared";
2
+ /**
3
+ * Configures CI environment.
4
+ * @param env - The whole available environment variables.
5
+ * @return An object with `isCi` and `isPullRequest` properties set to the boolean suiting the context.
6
+ */
7
+ export declare const configureCiEnvironment: (env: NodeJS.ProcessEnv) => CiConfig;
8
+ //# sourceMappingURL=configure-ci-environment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configure-ci-environment.d.ts","sourceRoot":"","sources":["../src/configure-ci-environment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAIvD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAI,KAAK,MAAM,CAAC,UAAU,KAAG,QAa/D,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { isCiToolDetected } from "./is-ci-tool-detected.js";
2
+ /**
3
+ * Configures CI environment.
4
+ * @param env - The whole available environment variables.
5
+ * @return An object with `isCi` and `isPullRequest` properties set to the boolean suiting the context.
6
+ */
7
+ export const configureCiEnvironment = (env) => {
8
+ if (isCiToolDetected(env, "GITHUB_ACTIONS")) {
9
+ const isPullRequest = env.GITHUB_EVENT_NAME === "pull_request" || env.GITHUB_EVENT_NAME === "pull_request_target";
10
+ return {
11
+ isCi: Boolean(env.CI),
12
+ isPullRequest
13
+ };
14
+ }
15
+ return {
16
+ isCi: false,
17
+ isPullRequest: false
18
+ };
19
+ };
20
+ //# sourceMappingURL=configure-ci-environment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configure-ci-environment.js","sourceRoot":"","sources":["../src/configure-ci-environment.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,GAAsB,EAAY,EAAE;IACzE,IAAI,gBAAgB,CAAC,GAAG,EAAE,gBAAgB,CAAC,EAAE,CAAC;QAC5C,MAAM,aAAa,GACjB,GAAG,CAAC,iBAAiB,KAAK,cAAc,IAAI,GAAG,CAAC,iBAAiB,KAAK,qBAAqB,CAAC;QAC9F,OAAO;YACL,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YACrB,aAAa;SACd,CAAC;IACJ,CAAC;IACD,OAAO;QACL,IAAI,EAAE,KAAK;QACX,aAAa,EAAE,KAAK;KACrB,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Gets the token used to interact with issues and pull requests from the environment variables.
3
+ * @param env - The whole available environment variables.
4
+ * @return The token if the `ISSUE_PR_TOKEN` environment variable is defined.
5
+ */
6
+ export declare const getIssueAndPullRequestToken: (env: NodeJS.ProcessEnv) => string;
7
+ //# sourceMappingURL=get-issue-and-pull-request-token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-issue-and-pull-request-token.d.ts","sourceRoot":"","sources":["../src/get-issue-and-pull-request-token.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,GAAI,KAAK,MAAM,CAAC,UAAU,KAAG,MAYpE,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { formatDetailedError } from "@release-change/shared";
2
+ /**
3
+ * Gets the token used to interact with issues and pull requests from the environment variables.
4
+ * @param env - The whole available environment variables.
5
+ * @return The token if the `ISSUE_PR_TOKEN` environment variable is defined.
6
+ */
7
+ export const getIssueAndPullRequestToken = (env) => {
8
+ const { ISSUE_PR_TOKEN } = env;
9
+ if (ISSUE_PR_TOKEN)
10
+ return ISSUE_PR_TOKEN;
11
+ process.exitCode = 1;
12
+ throw formatDetailedError({
13
+ title: "Failed to get issue and pull request token",
14
+ message: "The token used to interact with issues and pull requests (comments, state and tags) is not defined.",
15
+ details: {
16
+ output: "env.ISSUE_PR_TOKEN: undefined"
17
+ }
18
+ });
19
+ };
20
+ //# sourceMappingURL=get-issue-and-pull-request-token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-issue-and-pull-request-token.js","sourceRoot":"","sources":["../src/get-issue-and-pull-request-token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D;;;;GAIG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,GAAsB,EAAU,EAAE;IAC5E,MAAM,EAAE,cAAc,EAAE,GAAG,GAAG,CAAC;IAC/B,IAAI,cAAc;QAAE,OAAO,cAAc,CAAC;IAC1C,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACrB,MAAM,mBAAmB,CAAC;QACxB,KAAK,EAAE,4CAA4C;QACnD,OAAO,EACL,qGAAqG;QACvG,OAAO,EAAE;YACP,MAAM,EAAE,+BAA+B;SACxC;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Get the release token from the environment variables.
3
+ * @param env - The whole available environment variables.
4
+ * @return The token if the `RELEASE_TOKEN` environment variable is defined.
5
+ */
6
+ export declare const getReleaseToken: (env: NodeJS.ProcessEnv) => string;
7
+ //# sourceMappingURL=get-release-token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-release-token.d.ts","sourceRoot":"","sources":["../src/get-release-token.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,MAAM,CAAC,UAAU,KAAG,MAaxD,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { formatDetailedError } from "@release-change/shared";
2
+ /**
3
+ * Get the release token from the environment variables.
4
+ * @param env - The whole available environment variables.
5
+ * @return The token if the `RELEASE_TOKEN` environment variable is defined.
6
+ */
7
+ export const getReleaseToken = (env) => {
8
+ const releaseToken = env.RELEASE_TOKEN;
9
+ if (!releaseToken) {
10
+ process.exitCode = 1;
11
+ throw formatDetailedError({
12
+ title: "Failed to get the release token",
13
+ message: "The release token is not defined.",
14
+ details: {
15
+ output: "env.RELEASE_TOKEN: undefined"
16
+ }
17
+ });
18
+ }
19
+ return releaseToken;
20
+ };
21
+ //# sourceMappingURL=get-release-token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-release-token.js","sourceRoot":"","sources":["../src/get-release-token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAsB,EAAU,EAAE;IAChE,MAAM,YAAY,GAAG,GAAG,CAAC,aAAa,CAAC;IACvC,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACrB,MAAM,mBAAmB,CAAC;YACxB,KAAK,EAAE,iCAAiC;YACxC,OAAO,EAAE,mCAAmC;YAC5C,OAAO,EAAE;gBACP,MAAM,EAAE,8BAA8B;aACvC;SACF,CAAC,CAAC;IACL,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { configureCiEnvironment } from "./configure-ci-environment.js";
2
+ export { getIssueAndPullRequestToken } from "./get-issue-and-pull-request-token.js";
3
+ export { getReleaseToken } from "./get-release-token.js";
4
+ export { isUsableCiEnvironment } from "./is-usable-ci-environment.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,2BAA2B,EAAE,MAAM,uCAAuC,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { configureCiEnvironment } from "./configure-ci-environment.js";
2
+ export { getIssueAndPullRequestToken } from "./get-issue-and-pull-request-token.js";
3
+ export { getReleaseToken } from "./get-release-token.js";
4
+ export { isUsableCiEnvironment } from "./is-usable-ci-environment.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,2BAA2B,EAAE,MAAM,uCAAuC,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Checks whether a CI tool is detected or not.
3
+ * @param env - The whole available environment variables.
4
+ * @param ciTool - The variable to find.
5
+ * @return `true` if a CI tool is found within the environment variables, `false` otherwise.
6
+ */
7
+ export declare const isCiToolDetected: (env: NodeJS.ProcessEnv, ciTool: string) => boolean;
8
+ //# sourceMappingURL=is-ci-tool-detected.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-ci-tool-detected.d.ts","sourceRoot":"","sources":["../src/is-ci-tool-detected.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,KAAK,MAAM,CAAC,UAAU,EAAE,QAAQ,MAAM,KAAG,OAEzE,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Checks whether a CI tool is detected or not.
3
+ * @param env - The whole available environment variables.
4
+ * @param ciTool - The variable to find.
5
+ * @return `true` if a CI tool is found within the environment variables, `false` otherwise.
6
+ */
7
+ export const isCiToolDetected = (env, ciTool) => {
8
+ return Boolean(env[ciTool]);
9
+ };
10
+ //# sourceMappingURL=is-ci-tool-detected.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-ci-tool-detected.js","sourceRoot":"","sources":["../src/is-ci-tool-detected.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAsB,EAAE,MAAc,EAAW,EAAE;IAClF,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9B,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { Context } from "@release-change/shared";
2
+ /**
3
+ * Checks whether the CI environment is usable for the run to proceed.
4
+ * A usable CI environment does not provide any context when the run is triggered by a pull request.
5
+ * An unknown CI environment does not prevent the run from proceeding but activates the dry-run mode.
6
+ * @param context - The context where the CLI is running.
7
+ * @return `true` if the CI environment is usable, `false` otherwise.
8
+ */
9
+ export declare const isUsableCiEnvironment: (context: Context) => boolean;
10
+ //# sourceMappingURL=is-usable-ci-environment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-usable-ci-environment.d.ts","sourceRoot":"","sources":["../src/is-usable-ci-environment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAMtD;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,GAAI,SAAS,OAAO,KAAG,OAsBxD,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { inspect } from "node:util";
2
+ import { setLogger } from "@release-change/logger";
3
+ /**
4
+ * Checks whether the CI environment is usable for the run to proceed.
5
+ * A usable CI environment does not provide any context when the run is triggered by a pull request.
6
+ * An unknown CI environment does not prevent the run from proceeding but activates the dry-run mode.
7
+ * @param context - The context where the CLI is running.
8
+ * @return `true` if the CI environment is usable, `false` otherwise.
9
+ */
10
+ export const isUsableCiEnvironment = (context) => {
11
+ const { config, ci } = context;
12
+ const { isCi, isPullRequest } = ci;
13
+ const logger = setLogger(config.debug);
14
+ logger.setScope("ci");
15
+ if (config.debug) {
16
+ logger.setDebugScope("ci:is-usable-ci-environment");
17
+ logger.logDebug(inspect(ci, { depth: Number.POSITIVE_INFINITY }));
18
+ }
19
+ if (isCi && isPullRequest) {
20
+ logger.logWarn("This run is triggered by a pull request; therefore, a new version will not be published.");
21
+ return false;
22
+ }
23
+ if (!isCi) {
24
+ config.dryRun = true;
25
+ logger.logWarn("This run is not triggered in a known CI environment; therefore, the dry-run mode is enabled.");
26
+ }
27
+ return true;
28
+ };
29
+ //# sourceMappingURL=is-usable-ci-environment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-usable-ci-environment.js","sourceRoot":"","sources":["../src/is-usable-ci-environment.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,OAAgB,EAAW,EAAE;IACjE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC;IAC/B,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC;IACnC,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACtB,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,MAAM,CAAC,aAAa,CAAC,6BAA6B,CAAC,CAAC;QACpD,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC;IACpE,CAAC;IACD,IAAI,IAAI,IAAI,aAAa,EAAE,CAAC;QAC1B,MAAM,CAAC,OAAO,CACZ,0FAA0F,CAC3F,CAAC;QACF,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC;QACrB,MAAM,CAAC,OAAO,CACZ,8FAA8F,CAC/F,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@release-change/ci",
3
+ "version": "0.1.0",
4
+ "description": "Get environment variables related to the CI",
5
+ "keywords": [],
6
+ "homepage": "https://github.com/release-change/release-change",
7
+ "bugs": {
8
+ "url": "https://github.com/release-change/release-change/issues"
9
+ },
10
+ "author": "Victor Brito (https://victor-brito.dev)",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/release-change/release-change.git"
14
+ },
15
+ "type": "module",
16
+ "license": "MIT",
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "exports": {
21
+ "import": "./dist/index.js",
22
+ "types": "./dist/index.d.ts"
23
+ },
24
+ "engines": {
25
+ "node": "^20.18.3 || ^22.12.0 || ^24.0.0",
26
+ "npm": ">=10.8.2",
27
+ "pnpm": ">=10.28.0"
28
+ },
29
+ "dependencies": {
30
+ "@release-change/logger": "0.1.0",
31
+ "@release-change/shared": "0.1.0",
32
+ "@release-change/config": "0.1.0"
33
+ },
34
+ "scripts": {
35
+ "build": "tsc",
36
+ "dev": "tsc --watch --preserveWatchOutput & vitest"
37
+ }
38
+ }