UNPKG

18.8 kBTypeScriptView Raw
1/// <reference types="node" />
2
3// tslint:disable:no-redundant-jsdoc
4
5/**
6 * A semver release type.
7 * See https://github.com/semantic-release/commit-analyzer/blob/master/lib/default-release-types.js
8 */
9export type ReleaseType = "prerelease" | "prepatch" | "patch" | "preminor" | "minor" | "premajor" | "major";
10
11export type LoggerFunction = (...message: any[]) => void;
12
13/**
14 * semantic-release options.
15 *
16 * Can be used to set any core option or plugin options.
17 * Each option will take precedence over options configured in the
18 * configuration file and shareable configurations.
19 */
20export interface Options {
21 /**
22 * List of modules or file paths containing a
23 * [shareable configuration](https://semantic-release.gitbook.io/semantic-release/usage/shareable-configurations).
24 * If multiple shareable configurations are set, they will be imported
25 * in the order defined with each configuration option taking
26 * precedence over the options defined in a previous shareable
27 * configuration.
28 *
29 * **Note**: Options defined via CLI arguments or in the configuration
30 * file will take precedence over the ones defined in any shareable
31 * configuration.
32 */
33 extends?: readonly string[] | string | undefined;
34
35 /**
36 * The branches on which releases should happen. By default
37 * **semantic-release** will release:
38 *
39 * * regular releases to the default distribution channel from the
40 * branch `master`
41 * * regular releases to a distribution channel matching the branch
42 * name from any existing branch with a name matching a maintenance
43 * release range (`N.N.x` or `N.x.x` or `N.x` with `N` being a
44 * number)
45 * * regular releases to the `next` distribution channel from the
46 * branch `next` if it exists
47 * * regular releases to the `next-major` distribution channel from
48 * the branch `next-major` if it exists.
49 * * prereleases to the `beta` distribution channel from the branch
50 * `beta` if it exists
51 * * prereleases to the `alpha` distribution channel from the branch
52 * `alpha` if it exists
53 *
54 * **Note**: If your repository does not have a release branch, then
55 * **semantic-release** will fail with an `ERELEASEBRANCHES` error
56 * message. If you are using the default configuration, you can fix
57 * this error by pushing a `master` branch.
58 *
59 * **Note**: Once **semantic-release** is configured, any user with the
60 * permission to push commits on one of those branches will be able to
61 * publish a release. It is recommended to protect those branches, for
62 * example with [GitHub protected branches](https://help.github.com/articles/about-protected-branches).
63 *
64 * See [Workflow configuration](https://semantic-release.gitbook.io/semantic-release/usage/workflow-configuration#workflow-configuration)
65 * for more details.
66 */
67 branches?: readonly BranchSpec[] | BranchSpec | undefined;
68
69 /**
70 * The git repository URL.
71 *
72 * Any valid git url format is supported (see
73 * [git protocols](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols))
74 *
75 * Default: `repository` property in `package.json`, or git origin url.
76 */
77 repositoryUrl?: string | undefined;
78
79 /**
80 * The git tag format used by **semantic-release** to identify
81 * releases. The tag name is generated with [Lodash template](https://lodash.com/docs#template)
82 * and will be compiled with the `version` variable.
83 *
84 * **Note**: The `tagFormat` must contain the `version` variable
85 * exactly once and compile to a
86 * [valid git reference](https://git-scm.com/docs/git-check-ref-format#_description).
87 */
88 tagFormat?: string | undefined;
89
90 /**
91 * Define the list of plugins to use. Plugins will run in series, in
92 * the order defined, for each [step](https://semantic-release.gitbook.io/semantic-release/#release-steps)
93 * if they implement it.
94 *
95 * Plugins configuration can be defined by wrapping the name and an
96 * options object in an array.
97 *
98 * See [Plugins configuration](https://semantic-release.gitbook.io/semantic-release/usage/plugins#plugins)
99 * for more details.
100 *
101 * Default: `[
102 * "@semantic-release/commit-analyzer",
103 * "@semantic-release/release-notes-generator",
104 * "@semantic-release/npm",
105 * "@semantic-release/github"
106 * ]`
107 */
108 plugins?: readonly PluginSpec[] | undefined;
109
110 /**
111 * Dry-run mode, skip publishing, print next version and release notes.
112 */
113 dryRun?: boolean | undefined;
114
115 /**
116 * Set to false to skip Continuous Integration environment verifications.
117 * This allows for making releases from a local machine.
118 */
119 ci?: boolean | undefined;
120
121 /**
122 * Any other options supported by plugins.
123 */
124 [name: string]: any;
125}
126
127/**
128 * semantic-release options, after normalization and defaults have been
129 * applied.
130 */
131export interface GlobalConfig extends Options {
132 /**
133 * The branches on which releases should happen. By default
134 * **semantic-release** will release:
135 *
136 * * regular releases to the default distribution channel from the
137 * branch `master`
138 * * regular releases to a distribution channel matching the branch
139 * name from any existing branch with a name matching a maintenance
140 * release range (`N.N.x` or `N.x.x` or `N.x` with `N` being a
141 * number)
142 * * regular releases to the `next` distribution channel from the
143 * branch `next` if it exists
144 * * regular releases to the `next-major` distribution channel from
145 * the branch `next-major` if it exists.
146 * * prereleases to the `beta` distribution channel from the branch
147 * `beta` if it exists
148 * * prereleases to the `alpha` distribution channel from the branch
149 * `alpha` if it exists
150 *
151 * **Note**: If your repository does not have a release branch, then
152 * **semantic-release** will fail with an `ERELEASEBRANCHES` error
153 * message. If you are using the default configuration, you can fix
154 * this error by pushing a `master` branch.
155 *
156 * **Note**: Once **semantic-release** is configured, any user with the
157 * permission to push commits on one of those branches will be able to
158 * publish a release. It is recommended to protect those branches, for
159 * example with [GitHub protected branches](https://help.github.com/articles/about-protected-branches).
160 *
161 * See [Workflow configuration](https://semantic-release.gitbook.io/semantic-release/usage/workflow-configuration#workflow-configuration)
162 * for more details.
163 */
164 branches: readonly BranchSpec[] | BranchSpec;
165
166 /**
167 * The git repository URL.
168 *
169 * Any valid git url format is supported (see
170 * [git protocols](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols))
171 *
172 * Default: `repository` property in `package.json`, or git origin url.
173 */
174 repositoryUrl: string;
175
176 /**
177 * The git tag format used by **semantic-release** to identify
178 * releases. The tag name is generated with [Lodash template](https://lodash.com/docs#template)
179 * and will be compiled with the `version` variable.
180 *
181 * **Note**: The `tagFormat` must contain the `version` variable
182 * exactly once and compile to a
183 * [valid git reference](https://git-scm.com/docs/git-check-ref-format#_description).
184 */
185 tagFormat: string;
186
187 /**
188 * Define the list of plugins to use. Plugins will run in series, in
189 * the order defined, for each [step](https://semantic-release.gitbook.io/semantic-release/#release-steps)
190 * if they implement it.
191 *
192 * Plugins configuration can be defined by wrapping the name and an
193 * options object in an array.
194 *
195 * See [Plugins configuration](https://semantic-release.gitbook.io/semantic-release/usage/plugins#plugins)
196 * for more details.
197 *
198 * Default: `[
199 * "@semantic-release/commit-analyzer",
200 * "@semantic-release/release-notes-generator",
201 * "@semantic-release/npm",
202 * "@semantic-release/github"
203 * ]`
204 */
205 plugins: readonly PluginSpec[];
206}
207
208export interface BranchObject {
209 /**
210 * The name of git branch.
211 *
212 * A `name` is required for all types of branch. It can be defined as a
213 * [glob](https://github.com/micromatch/micromatch#matching-features)
214 * in which case the definition will be expanded to one per matching
215 * branch existing in the repository.
216 *
217 * If `name` doesn't match any branch existing in the repository, the
218 * definition will be ignored. For example, the default configuration
219 * includes the definition `next` and `next-major` which will become
220 * active only when the branches `next` and/or `next-major` are
221 * created in the repository.
222 */
223 name: string;
224
225 /**
226 * The distribution channel on which to publish releases from this
227 * branch.
228 *
229 * If this field is set to `false`, then the branch will be released
230 * on the default distribution channel (for example the `@latest`
231 * [dist-tag](https://docs.npmjs.com/cli/dist-tag) for npm). This is
232 * also the default behavior for the first
233 * [release branch](https://semantic-release.gitbook.io/semantic-release/usage/workflow-configuration#release-branches)
234 * if the channel property is not set.
235 *
236 * For all other branches, if the channel property is not set, then the
237 * channel name will be the same as the branch name.
238 *
239 * The value of `channel`, if defined as a string, is generated with
240 * [Lodash template](https://lodash.com/docs#template) with the
241 * variable `name` set to the branch name.
242 *
243 * For example `{name: 'next', channel: 'channel-${name}'}` will be
244 * expanded to `{name: 'next', channel: 'channel-next'}`.
245 */
246 channel?: string | false | undefined;
247
248 /**
249 * The range of [semantic versions](https://semver.org/) to support on
250 * this branch.
251 *
252 * A `range` only applies to maintenance branches and must be formatted
253 * like `N.N.x` or `N.x` (`N` is a number). If no range is specified
254 * but the `name` is formatted as a range, then the branch will be
255 * considered a maintenance branch and the `name` value will be used
256 * for the `range`.
257 *
258 * Required for maintenance branches, unless `name` is formatted like
259 * `N.N.x` or `N.x` (`N` is a number).
260 */
261 range?: string | undefined;
262
263 /**
264 * The pre-release identifier to append to [semantic versions](https://semver.org/)
265 * released from this branch.
266 *
267 * A `prerelease` property applies only to pre-release branches and
268 * the `prerelease` value must be valid per the [Semantic Versioning
269 * Specification](https://semver.org/#spec-item-9). It will determine
270 * the name of versions. For example if `prerelease` is set to
271 * `"beta"`, the version will be formatted like `2.0.0-beta.1`,
272 * `2.0.0-beta.2`, etc.
273 *
274 * The value of `prerelease`, if defined as a string, is generated with
275 * [Lodash template](https://lodash.com/docs#template) with the
276 * variable `name` set to the name of the branch.
277 *
278 * If the `prerelease property is set to `true` then the name of the
279 * branch is used as the pre-release identifier.
280 *
281 * Required for pre-release branches.
282 */
283 prerelease?: string | boolean | undefined;
284}
285
286/**
287 * Specifies a git branch holding commits to analyze and code to release.
288 *
289 * Each branch may be defined either by a string or an object. Specifying
290 * a string is a shortcut for specifying that string as the `name` field,
291 * for example `"master"` expands to `{name: "master"}`.
292 */
293export type BranchSpec = string | BranchObject;
294/**
295 * Specifies a plugin to use.
296 *
297 * The plugin is specified by its module name.
298 *
299 * To pass options to a plugin, specify an array containing the plugin module
300 * name and an options object.
301 */
302export type PluginSpec = string | [string, any];
303
304/** semantic-release configuration specific for API usage. */
305export interface Config {
306 /**
307 * The current working directory to use. It should be configured to
308 * the root of the Git repository to release from.
309 *
310 * It allows to run semantic-release from a specific path without
311 * having to change the local process cwd with process.chdir().
312 *
313 * @default process.cwd
314 */
315 cwd?: string | undefined;
316
317 /**
318 * The environment variables to use.
319 *
320 * It allows to run semantic-release with specific environment
321 * variables without having to modify the local process.env.
322 *
323 * @default process.env
324 */
325 env?: { [name: string]: string } | undefined;
326
327 /**
328 * The writable stream used to log information.
329 *
330 * It allows to configure semantic-release to write logs to a specific
331 * stream rather than the local process.stdout.
332 *
333 * @default process.stdout
334 */
335 stdout?: NodeJS.WriteStream | undefined;
336
337 /**
338 * The writable stream used to log errors.
339 *
340 * It allows to configure semantic-release to write errors to a
341 * specific stream rather than the local process.stderr.
342 *
343 * @default process.stderr
344 */
345 stderr?: NodeJS.WriteStream | undefined;
346}
347
348export interface LastRelease {
349 /**
350 * The version name of the release.
351 */
352 version: string;
353
354 /**
355 * The Git tag of the release.
356 */
357 gitTag: string;
358
359 /**
360 * The Git checksum of the last commit of the release.
361 */
362 gitHead: string;
363}
364
365export interface NextRelease extends LastRelease {
366 /**
367 * The semver export type of the release.
368 */
369 type: ReleaseType;
370
371 /**
372 * The release channel of the release.
373 */
374 channel?: string | undefined;
375
376 /**
377 * The git hash of the release.
378 */
379 gitHead: string;
380
381 /**
382 * The version without v
383 */
384 version: string;
385
386 /**
387 * The version with v prefix
388 */
389 gitTag: string;
390
391 /**
392 * The release name
393 */
394 name?: string;
395
396 /**
397 * The release notes of the next release.
398 */
399 notes: string;
400}
401
402export interface Context {
403 /**
404 * The semantic release configuration itself.
405 */
406 options?: GlobalConfig | undefined;
407
408 /**
409 * The previous release details.
410 */
411 lastRelease?: LastRelease | undefined;
412
413 /**
414 * The next release details.
415 */
416 nextRelease?: NextRelease | undefined;
417
418 /**
419 * The shared logger instance of semantic release.
420 */
421 logger: {
422 await: LoggerFunction;
423 complete: LoggerFunction;
424 debug: LoggerFunction;
425 error: LoggerFunction;
426 fatal: LoggerFunction;
427 fav: LoggerFunction;
428 info: LoggerFunction;
429 log: LoggerFunction;
430 note: LoggerFunction;
431 pause: LoggerFunction;
432 pending: LoggerFunction;
433 star: LoggerFunction;
434 start: LoggerFunction;
435 success: LoggerFunction;
436 wait: LoggerFunction;
437 warn: LoggerFunction;
438 watch: LoggerFunction;
439 };
440
441 /**
442 * Environment variables.
443 */
444 env: {
445 [key: string]: string;
446 };
447
448 /**
449 * Commits to analyze.
450 */
451 commits?: Commit[];
452
453 /**
454 * Current branch being published.
455 */
456 branch: BranchObject;
457}
458
459export interface Commit {
460 /**
461 * The commit abbreviated and full hash.
462 */
463 commit: {
464 /**
465 * The commit hash.
466 */
467 long: string;
468
469 /**
470 * The commit abbreviated hash.
471 */
472 short: string;
473 };
474
475 /**
476 * The commit abbreviated and full tree hash.
477 */
478 tree: {
479 /**
480 * The commit tree hash.
481 */
482 long: string;
483
484 /**
485 * The commit abbreviated tree hash.
486 */
487 short: string;
488 };
489
490 /**
491 * The commit author information.
492 */
493 author: {
494 /**
495 * The commit author name.
496 */
497 name: string;
498
499 /**
500 * The commit author email.
501 */
502 email: string;
503
504 /**
505 * The commit author date.
506 */
507 short: string;
508 };
509
510 /**
511 * The committer information.
512 */
513 committer: {
514 /**
515 * The committer name.
516 */
517 name: string;
518
519 /**
520 * The committer email.
521 */
522 email: string;
523
524 /**
525 * The committer date.
526 */
527 short: string;
528 };
529
530 /**
531 * The commit subject.
532 */
533 subject: string;
534
535 /**
536 * The commit body.
537 */
538 body: string;
539
540 /**
541 * The commit full message (subject and body).
542 */
543 message: string;
544
545 /**
546 * The commit hash.
547 */
548 hash: string;
549
550 /**
551 * The committer date.
552 */
553 committerDate: string;
554}
555
556/**
557 * Details of a release published by a publish plugin.
558 */
559export interface Release {
560 /**
561 * The release name, only if set by the corresponding publish plugin.
562 */
563 name?: string | undefined;
564
565 /**
566 * The release URL, only if set by the corresponding publish plugin.
567 */
568 url?: string | undefined;
569
570 /**
571 * The semver export type of the release.
572 */
573 type: ReleaseType;
574
575 /**
576 * The version of the release.
577 */
578 version: string;
579
580 /**
581 * The sha of the last commit being part of the release.
582 */
583 gitHead: string;
584
585 /**
586 * The Git tag associated with the release.
587 */
588 gitTag: string;
589
590 /**
591 * The release notes for the release.
592 */
593 notes: string;
594
595 /**
596 * The name of the plugin that published the release.
597 */
598 pluginName: string;
599}
600
601/**
602 * An object with details of the release if a release was published, or
603 * false if no release was published.
604 */
605export type Result =
606 | false
607 | {
608 /**
609 * Information related to the last release found.
610 */
611 lastRelease: LastRelease;
612
613 /**
614 * The list of commits included in the new release.
615 */
616 commits: Commit[];
617
618 /**
619 * Information related to the newly published release.
620 */
621 nextRelease: NextRelease;
622
623 /**
624 * The list of releases published, one release per publish plugin.
625 */
626 releases: Release[];
627 };
628
629/**
630 * Run semantic-release and returns a Promise that resolves to a Result
631 * object.
632 * @async
633 */
634export default function(options: Options, environment?: Config): Promise<Result>;