Fixed version resolution in releaseless context

Fixes #78
This commit is contained in:
Kir_Antipov 2024-01-02 13:46:03 +00:00
parent 86e7074aca
commit b34393cfcd
2 changed files with 21 additions and 2 deletions

View file

@ -63,8 +63,27 @@ export class GitHubContext {
* Gets the tag associated with the context, if available. * Gets the tag associated with the context, if available.
*/ */
get tag(): string | undefined { get tag(): string | undefined {
const payload = this.payload;
if (payload.release?.tag_name) {
return payload.release.tag_name;
}
const ref = this.ref; 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;
} }
/** /**

View file

@ -111,7 +111,7 @@ async function fillInDefaultValues<T extends McPublishInput[P], P extends Platfo
const unwrappedGameVersions = gameVersions ? GameVersionFilter.filter(gameVersions, options.gameVersionFilter).map(x => x.id) : wrappedGameVersions; const unwrappedGameVersions = gameVersions ? GameVersionFilter.filter(gameVersions, options.gameVersionFilter).map(x => x.id) : wrappedGameVersions;
(options as UnionToIntersection<McPublishInput[PlatformType]>).id ||= metadata?.getProjectId(platform) || ""; (options as UnionToIntersection<McPublishInput[PlatformType]>).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.versionType ||= VersionType.parseFromFileName(metadata?.version || primaryFile.name);
options.name ??= githubContext.payload.release?.name || options.version; options.name ??= githubContext.payload.release?.name || options.version;
options.changelog ??= githubContext.payload.release?.body || ""; options.changelog ??= githubContext.payload.release?.body || "";