diff --git a/README.md b/README.md index 0596846..bbac28c 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ jobs: | `files` | NO | Multiline list of files (paths) to upload as a [GitHub Release asset](./docs/asset-management.md) | | `increment-type` | NO | Enforce a specific increment type, please refer to the [Versioning Strategies](./docs/versioning-strategies.md) for more details | | `release-notes` | NO | Path towards a file containing the release notes to include in the GitHub release (Markdown format recommended) | +| `version` | NO | Version to associate with the GitHub Release, can be OPTIONALLY set to override automatic detection or the `increment-type` parameter | | `versioning` | NO | [Versioning strategy](#versioning-strategies) to apply. MUST be one of `semver` or `calver`. Default: `semver` | ## Outputs diff --git a/action.yml b/action.yml index 713c6d7..1869db6 100644 --- a/action.yml +++ b/action.yml @@ -50,6 +50,10 @@ inputs: description: 'Increment type to apply to the version' required: false + version: + description: 'Version to associate with the GitHub Release' + required: false + create-release: description: 'Create the GitHub Release, can be set to `false` to perform a dry run (i.e. determine the previous and incremented version)' required: false diff --git a/lib/main/index.js b/lib/main/index.js index a7ceefd..04f620d 100644 --- a/lib/main/index.js +++ b/lib/main/index.js @@ -18505,44 +18505,56 @@ async function run() { core.info("📄 ReleaseMe - GitHub Release Management"); const branch = branching.getBranch(); const versionScheme = versioning.getVersionScheme(); - core.startGroup("🔍 Determining increment type"); - const latestRelease = await releasing.getLatestRelease(branch, versionScheme); - let latestRef; - let latestVersion; - if (latestRelease) { - core.info(`ℹ️ Latest release: ${latestRelease.tag_name}`); - latestRef = latestRelease.tag_name; - latestVersion = versionScheme.createVersion(latestRef); - } - else { - // NOTE: Postponed this expensive request for the case where there is no release determined yet - const initialCommit = await releasing.getInitialCommit(); - core.info(`ℹ️ Creating release based on commit SHA: ${initialCommit.hash}`); - latestRef = initialCommit.hash; - latestVersion = versionScheme.initialVersion(); - } - const increments = []; + const versionOverride = core.getInput("version"); + let newVersion; const commits = []; - if (core.getInput("increment-type")) { - increments.push(...core.getInput("increment-type").split("|").map(inc => versioning.getIncrementType(versionScheme, inc))); + core.startGroup("🔍 Determining increment type"); + if (versionOverride) { + core.info(`ℹ️ Using version override: ${versionOverride}`); + newVersion = versionScheme.createVersion(versionOverride); + core.setOutput("incremented-version", newVersion.toString()); } else { - const delta = await releasing.getChangesSince(latestRef); - core.info(`ℹ️ Changes since: ${delta.length} commits`); - commits.push(...filterConventionalCommits(delta)); - core.info(`ℹ️ Conventional Commits since: ${commits.length} commits`); - const increment = versionScheme.determineIncrementType(commits); - if (increment === undefined) { - core.info("⚠️ No increment required, skipping..."); - core.endGroup(); - return; + let latestRef; + let latestVersion; + const latestRelease = await releasing.getLatestRelease(branch, versionScheme); + if (latestRelease) { + core.info(`ℹ️ Latest release: ${latestRelease.tag_name}`); + latestRef = latestRelease.tag_name; + latestVersion = versionScheme.createVersion(latestRef); + } + else { + // NOTE: Postponed this expensive request for the case where there is no release determined yet + const initialCommit = await releasing.getInitialCommit(); + core.info(`ℹ️ Creating release based on commit SHA: ${initialCommit.hash}`); + latestRef = initialCommit.hash; + latestVersion = versionScheme.initialVersion(); + } + const increments = []; + if (core.getInput("increment-type")) { + increments.push(...core + .getInput("increment-type") + .split("|") + .map(inc => versioning.getIncrementType(versionScheme, inc))); + } + else { + const delta = await releasing.getChangesSince(latestRef); + core.info(`ℹ️ Changes since: ${delta.length} commits`); + commits.push(...filterConventionalCommits(delta)); + core.info(`ℹ️ Conventional Commits since: ${commits.length} commits`); + const increment = versionScheme.determineIncrementType(commits); + if (increment === undefined) { + core.info("⚠️ No increment required, skipping..."); + core.endGroup(); + return; + } + increments.push(increment); } - increments.push(increment); + core.setOutput("previous-version", latestVersion.toString()); + newVersion = versioning.incrementVersion(latestVersion, increments); + core.setOutput("incremented-version", newVersion.toString()); } core.endGroup(); - core.setOutput("previous-version", latestVersion.toString()); - const newVersion = versioning.incrementVersion(latestVersion, increments); - core.setOutput("incremented-version", newVersion.toString()); if (!core.getBooleanInput("create-release")) { return; } diff --git a/src/action.ts b/src/action.ts index e8b1313..c6e9ec4 100644 --- a/src/action.ts +++ b/src/action.ts @@ -41,50 +41,65 @@ export async function run(): Promise { const branch = branching.getBranch(); const versionScheme = versioning.getVersionScheme(); + const versionOverride = core.getInput("version"); + + let newVersion: versioning.Version; + const commits: commitLib.IConventionalCommit[] = []; core.startGroup("🔍 Determining increment type"); - const latestRelease = await releasing.getLatestRelease(branch, versionScheme); - let latestRef: string; - let latestVersion: versioning.Version; - - if (latestRelease) { - core.info(`ℹ️ Latest release: ${latestRelease.tag_name}`); - latestRef = latestRelease.tag_name; - latestVersion = versionScheme.createVersion(latestRef); + if (versionOverride) { + core.info(`ℹ️ Using version override: ${versionOverride}`); + newVersion = versionScheme.createVersion(versionOverride); + core.setOutput("incremented-version", newVersion.toString()); } else { - // NOTE: Postponed this expensive request for the case where there is no release determined yet - const initialCommit = await releasing.getInitialCommit(); - - core.info(`ℹ️ Creating release based on commit SHA: ${initialCommit.hash}`); - latestRef = initialCommit.hash; - latestVersion = versionScheme.initialVersion(); - } + let latestRef: string; + let latestVersion: versioning.Version; + + const latestRelease = await releasing.getLatestRelease(branch, versionScheme); + + if (latestRelease) { + core.info(`ℹ️ Latest release: ${latestRelease.tag_name}`); + latestRef = latestRelease.tag_name; + latestVersion = versionScheme.createVersion(latestRef); + } else { + // NOTE: Postponed this expensive request for the case where there is no release determined yet + const initialCommit = await releasing.getInitialCommit(); + + core.info(`ℹ️ Creating release based on commit SHA: ${initialCommit.hash}`); + latestRef = initialCommit.hash; + latestVersion = versionScheme.initialVersion(); + } - const increments: versioning.VersionIncrement[] = []; - const commits: commitLib.IConventionalCommit[] = []; - if (core.getInput("increment-type")) { - increments.push(...core.getInput("increment-type").split("|").map(inc => versioning.getIncrementType(versionScheme, inc))); - } else { - const delta = await releasing.getChangesSince(latestRef); - core.info(`ℹ️ Changes since: ${delta.length} commits`); - - commits.push(...filterConventionalCommits(delta)); - core.info(`ℹ️ Conventional Commits since: ${commits.length} commits`); - - const increment = versionScheme.determineIncrementType(commits) - if (increment === undefined) { - core.info("⚠️ No increment required, skipping..."); - core.endGroup(); - return; + const increments: versioning.VersionIncrement[] = []; + if (core.getInput("increment-type")) { + increments.push( + ...core + .getInput("increment-type") + .split("|") + .map(inc => versioning.getIncrementType(versionScheme, inc)) + ); + } else { + const delta = await releasing.getChangesSince(latestRef); + core.info(`ℹ️ Changes since: ${delta.length} commits`); + + commits.push(...filterConventionalCommits(delta)); + core.info(`ℹ️ Conventional Commits since: ${commits.length} commits`); + + const increment = versionScheme.determineIncrementType(commits); + if (increment === undefined) { + core.info("⚠️ No increment required, skipping..."); + core.endGroup(); + return; + } + increments.push(increment); } - increments.push(increment); + + core.setOutput("previous-version", latestVersion.toString()); + newVersion = versioning.incrementVersion(latestVersion, increments); + core.setOutput("incremented-version", newVersion.toString()); } core.endGroup(); - core.setOutput("previous-version", latestVersion.toString()); - const newVersion = versioning.incrementVersion(latestVersion, increments); - core.setOutput("incremented-version", newVersion.toString()); - if (!core.getBooleanInput("create-release")) { return; } diff --git a/src/versioning.ts b/src/versioning.ts index 5e50c68..5c72da7 100644 --- a/src/versioning.ts +++ b/src/versioning.ts @@ -181,7 +181,7 @@ export function incrementVersion(version: Version, incrementType: VersionIncreme return newVersion; } - + let newVersion = new CalVer(version.format, version); let previousIncrement = ""; for (const increment of incrementType) { @@ -216,7 +216,11 @@ export function incrementVersion(version: Version, incrementType: VersionIncreme let newVersion = new SemVer(version); let previousIncrement = ""; for (const increment of incrementType) { - newVersion = incrementSemVer(newVersion, increment as SemVerIncrement, ["PRERELEASE", "BUILD"].includes(previousIncrement)); + newVersion = incrementSemVer( + newVersion, + increment as SemVerIncrement, + ["PRERELEASE", "BUILD"].includes(previousIncrement) + ); previousIncrement = increment as SemVerIncrement; if (newVersion.isGreaterThan(version)) { break;