diff --git a/src/platforms/github/github-context.ts b/src/platforms/github/github-context.ts index 43e28b2..9e83841 100644 --- a/src/platforms/github/github-context.ts +++ b/src/platforms/github/github-context.ts @@ -63,8 +63,27 @@ export class GitHubContext { * Gets the tag associated with the context, if available. */ get tag(): string | undefined { + const payload = this.payload; + if (payload.release?.tag_name) { + return payload.release.tag_name; + } + const ref = this.ref; - return ref?.startsWith(GITHUB_REF_TAG_PREFIX) && ref.substring(GITHUB_REF_TAG_PREFIX.length); + if (ref?.startsWith(GITHUB_REF_TAG_PREFIX)) { + return ref.substring(GITHUB_REF_TAG_PREFIX.length); + } + + return undefined; + } + + /** + * Gets the version associated with the context, if available. + */ + get version(): string | undefined { + const tag = this.tag; + + // Remove the `v` prefix, popularized by GitHub. + return /v\d/.test(tag) ? tag.substring(1) : tag; } /** diff --git a/src/program.ts b/src/program.ts index ea6be83..4dcc1b6 100644 --- a/src/program.ts +++ b/src/program.ts @@ -111,7 +111,7 @@ async function fillInDefaultValues x.id) : wrappedGameVersions; (options as UnionToIntersection).id ||= metadata?.getProjectId(platform) || ""; - options.version ||= githubContext.payload.release?.tag_name || metadata?.version; + options.version ||= githubContext.version || metadata?.version; options.versionType ||= VersionType.parseFromFileName(metadata?.version || primaryFile.name); options.name ??= githubContext.payload.release?.name || options.version; options.changelog ??= githubContext.payload.release?.body || "";