From 3d6d1f0a56b6ea4f84650929821818c5d2b5cd2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20Schmitz=20von=20H=C3=BClst?= Date: Thu, 2 Sep 2021 14:15:10 +0200 Subject: [PATCH] feat: Always release when on release branch, enable use of env variables in release templates --- README.md | 4 ++-- lib/success.ts | 12 ++++++++---- lib/types.ts | 2 ++ package-lock.json | 26 +++++++++++++++++++++++--- package.json | 1 + 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index ed4bbc3..ab052d1 100644 --- a/README.md +++ b/README.md @@ -111,11 +111,11 @@ interface Config { networkConcurrency?: number; /** - * indicates if a new release created in jira should be set as released + * Indicates if a new release created in jira should be set as released. `true` if the branch is not a prerelease */ released?: boolean; /** - * include the release date when creating a release in jira + * Include the release date when creating a release in jira */ setReleaseDate?: boolean; } diff --git a/lib/success.ts b/lib/success.ts index 0278cd4..51fd681 100644 --- a/lib/success.ts +++ b/lib/success.ts @@ -52,13 +52,17 @@ async function findOrCreateVersion(config: PluginConfig, context: GenerateNotesC } as any; } else { const descriptionText = description || ''; - newVersion = await jira.projectVersions.createVersion({ + const parameters = { name, projectId: project.id as any, description: descriptionText, released: Boolean(config.released), releaseDate: config.setReleaseDate ? (new Date().toISOString()) : undefined, - }); + }; + if (!parameters.released && typeof context.branch !== 'string') { + parameters.released = !context.branch.prerelease; + } + newVersion = await jira.projectVersions.createVersion(parameters); } context.logger.info(`Made new release '${newVersion.id}'`); @@ -103,10 +107,10 @@ export async function success(config: PluginConfig, context: GenerateNotesContex context.logger.info(`Found ticket ${tickets.join(', ')}`); const versionTemplate = _.template(config.releaseNameTemplate ?? DEFAULT_VERSION_TEMPLATE); - const newVersionName = versionTemplate({ version: context.nextRelease.version }); + const newVersionName = versionTemplate({ version: context.nextRelease.version, env: context.env }); const descriptionTemplate = _.template(config.releaseDescriptionTemplate ?? DEFAULT_RELEASE_DESCRIPTION_TEMPLATE); - const newVersionDescription = descriptionTemplate({ version: context.nextRelease.version, notes: context.nextRelease.notes }); + const newVersionDescription = descriptionTemplate({ version: context.nextRelease.version, notes: context.nextRelease.notes, env: context.env }); context.logger.info(`Using jira release '${newVersionName}'`); diff --git a/lib/types.ts b/lib/types.ts index 88276a4..49274a6 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -1,3 +1,4 @@ +import { BranchSpec } from 'semantic-release'; import { Signale } from 'signale'; export interface PluginContext { @@ -9,6 +10,7 @@ export interface PluginContext { options: BaseConfig; stderr: typeof process.stderr; stdout: typeof process.stdout; + branch: BranchSpec; } export interface Person { diff --git a/package-lock.json b/package-lock.json index 96111ad..1ff1230 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,12 @@ { - "name": "semantic-release-jira-releases", - "version": "0.1.0", + "name": "@temptek/semantic-release-jira", + "version": "0.0.4", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "0.1.0", + "name": "@temptek/semantic-release-jira", + "version": "0.0.4", "license": "MIT", "dependencies": { "@semantic-release/error": "^2.2.0", @@ -22,6 +23,7 @@ "@types/jest": "^27.0.1", "@types/lodash": "^4.14.172", "@types/node": "^16.7.10", + "@types/semantic-release": "^17.2.1", "@types/signale": "^1.4.2", "jest": "^27.1.0", "madge": "^5.0.1", @@ -2501,6 +2503,15 @@ "form-data": "^2.5.0" } }, + "node_modules/@types/semantic-release": { + "version": "17.2.1", + "resolved": "https://registry.npmjs.org/@types/semantic-release/-/semantic-release-17.2.1.tgz", + "integrity": "sha512-Gw9LyDgBn3I2lP4fel7/SmsKqqon+6SfOXitNhURkJrt+oIi5q65oY5AsbYzwIduFVOasbFrJ5469dJMaSRCNw==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/signale": { "version": "1.4.2", "resolved": "https://registry.npmjs.org/@types/signale/-/signale-1.4.2.tgz", @@ -11238,6 +11249,15 @@ "form-data": "^2.5.0" } }, + "@types/semantic-release": { + "version": "17.2.1", + "resolved": "https://registry.npmjs.org/@types/semantic-release/-/semantic-release-17.2.1.tgz", + "integrity": "sha512-Gw9LyDgBn3I2lP4fel7/SmsKqqon+6SfOXitNhURkJrt+oIi5q65oY5AsbYzwIduFVOasbFrJ5469dJMaSRCNw==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/signale": { "version": "1.4.2", "resolved": "https://registry.npmjs.org/@types/signale/-/signale-1.4.2.tgz", diff --git a/package.json b/package.json index 6a697e0..1d2a414 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "@types/jest": "^27.0.1", "@types/lodash": "^4.14.172", "@types/node": "^16.7.10", + "@types/semantic-release": "^17.2.1", "@types/signale": "^1.4.2", "jest": "^27.1.0", "madge": "^5.0.1",