Skip to content

Commit dafd644

Browse files
authored
chore(release): ensure correct vermoji baked into distributable (#4836)
this commit fixes a bug in our release scripts where the vermoji generated in the prerelease step of the process would not be properly propagated to the release step. when the entire process was manual, we'd do it all in one fell swooop, writing a tiny file to disk and reading that. in lieu of that, we can pull the vermoji off of the head of the CHANGELOG.md! this ensures consistency between the two - running `stencil info` and looking at the changelog should show the same emoji. note that this change intentionally does not get applied to the `getOptions` function for releases. since we still technically support manual releases, adding the change there for vermoji generation would negatively impact vermoji generation
1 parent 9f734df commit dafd644

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

scripts/release.ts

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { promptRelease } from './release-prompts';
77
import { runReleaseTasks } from './release-tasks';
88
import { BuildOptions, getOptions } from './utils/options';
99
import { getNewVersion } from './utils/release-utils';
10+
import { getLatestVermoji } from './utils/vermoji';
1011

1112
/**
1213
* Runner for creating a release of Stencil
@@ -88,6 +89,9 @@ export async function release(rootDir: string, args: ReadonlyArray<string>): Pro
8889
// this was bumped already, we just need to copy it from package.json into this field
8990
prepareOpts.version = prepareOpts.packageJson.version;
9091

92+
// we generated a vermoji during the preparation step, let's grab it from the changelog
93+
prepareOpts.vermoji = getLatestVermoji(prepareOpts.changelogPath);
94+
9195
const tagIdx = args.indexOf('--tag');
9296
let newTag = null;
9397
if (tagIdx === -1 || tagIdx === args.length) {

scripts/utils/vermoji.ts

+31
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,34 @@ export function getVermoji(changelogPath: string) {
338338
}
339339
}
340340
}
341+
342+
/**
343+
* Pull the most recently used vermoji for the provided changelog path
344+
* @param changelogPath the path to the changelog to parse
345+
* @returns the vermoji found in the changelog, otherwise use a default value.
346+
*/
347+
export function getLatestVermoji(changelogPath: string) {
348+
let changelogContents = null;
349+
try {
350+
changelogContents = fs.readFileSync(changelogPath, 'utf8');
351+
} catch (err: unknown) {
352+
console.error(`Unable to read the changelog at path '${changelogPath}' - ${err}.`);
353+
console.error(`Defaulting to ${UNKNOWN_VERMOJI}`);
354+
return UNKNOWN_VERMOJI;
355+
}
356+
357+
if (!changelogContents) {
358+
console.error(`The changelog at '${changelogPath}' was empty!`);
359+
console.error(`Defaulting to ${UNKNOWN_VERMOJI}`);
360+
return UNKNOWN_VERMOJI;
361+
}
362+
363+
// grab the first line of the changelog
364+
const firstLine = changelogContents.trimStart().split('\n')[0];
365+
// match the first line of the changelog with a string that has:
366+
// - one or more pound signs (#), followed by a space
367+
// - capture the first non-space character(s)
368+
const match = firstLine.match(/^#+\s(\S+)/);
369+
// if a match was found, return the value in the first capture group. otherwise, use the default vermoji
370+
return match ? match[1] : UNKNOWN_VERMOJI;
371+
}

0 commit comments

Comments
 (0)