diff --git a/.craft.yml b/.craft.yml index 12b8e72b..10759f3a 100644 --- a/.craft.yml +++ b/.craft.yml @@ -1,5 +1,5 @@ minVersion: '2.14.0' -changelogPolicy: auto +changelog: auto preReleaseCommand: >- node -p " const {execSync} = require('child_process'); diff --git a/src/commands/prepare.ts b/src/commands/prepare.ts index a508deed..12451551 100644 --- a/src/commands/prepare.ts +++ b/src/commands/prepare.ts @@ -34,7 +34,11 @@ import { isBumpType, type BumpType, } from '../utils/autoVersion'; -import { isDryRun, promptConfirmation } from '../utils/helpers'; +import { + isDryRun, + promptConfirmation, + setGitHubActionsOutput, +} from '../utils/helpers'; import { formatJson } from '../utils/strings'; import { spawnProcess } from '../utils/system'; import { isValidVersion } from '../utils/version'; @@ -549,6 +553,9 @@ export async function prepareMain(argv: PrepareOptions): Promise { logger.info(`Version bump: ${currentVersion} -> ${newVersion} (${bumpType} bump)`); } + // Emit resolved version for GitHub Actions + setGitHubActionsOutput('version', newVersion); + logger.info(`Releasing version ${newVersion} from ${rev}`); if (!argv.rev && rev !== defaultBranch) { logger.warn("You're not on your default branch, so I have to ask..."); diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 6df104f7..4393df63 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -1,3 +1,5 @@ +import { appendFileSync } from 'fs'; + import prompts from 'prompts'; import { logger, LogLevel, setLevel } from '../logger'; @@ -59,3 +61,14 @@ export async function promptConfirmation(): Promise { export function hasInput(): boolean { return !GLOBAL_FLAGS['no-input']; } + +/** + * Sets a GitHub Actions output variable. + * No-op when not running in GitHub Actions. + */ +export function setGitHubActionsOutput(name: string, value: string): void { + const outputFile = process.env.GITHUB_OUTPUT; + if (outputFile) { + appendFileSync(outputFile, `${name}=${value}\n`); + } +}