package file→ .shtukbase/packages/std-semver/checks/version.ts
checks/version.ts
23 lines, 1.6 KB.
- // Action `next`: prints the project's version, the last release tag and the bump the commits since it ask for
- // (major for a breaking change, minor for feat, patch for the rest). Not a check: always exits 0.
- import { compare, config, parse, projectVersion, releaseTags } from './semverlib.ts';
- import { git } from './lib/std.ts';
- const cfg = config();
- const cur = projectVersion(cfg);
- const tags = releaseTags(cfg).filter((t) => t.ver).sort((a, b) => compare(b.ver!, a.ver!));
- console.log(`project version: ${cur ? `${cur.version} (${cur.file})` : 'not found'}`);
- if (!tags.length) {
- console.log('there are no releases (tags)');
- process.exit(0);
- }
- const last = tags[0];
- const msgs = (git(['log', '--no-merges', '--format=%B%x1e', `${last.tag}..HEAD`]) ?? '').split('\x1e').map((s) => s.trim()).filter(Boolean);
- const breaking = msgs.some((m) => /^[A-Za-z][\w-]*(\([^()\n]*\))?!: /.test(m) || /^BREAKING[ -]CHANGE: /m.test(m));
- const feat = msgs.some((m) => /^feat(\([^()\n]*\))?: /i.test(m));
- const v = last.ver!;
- const zero = v.major === 0 && cfg.zeroMajor === 'minor';
- const next = !msgs.length ? null : breaking ? (zero ? `${v.major}.${v.minor + 1}.0` : `${v.major + 1}.0.0`) : feat ? `${v.major}.${v.minor + 1}.0` : `${v.major}.${v.minor}.${v.patch + 1}`;
- console.log(`last release: ${last.tag}; commits after it: ${msgs.length}${breaking ? ', there are breaking ones' : ''}${feat ? ', there is a feat' : ''}`);
- console.log(next ? `next version by the commits: ${next}` : 'there are no commits after the release');
- if (cur && parse(cur.version) === null) console.log(`attention: ${cur.version} is not SemVer`);