Skip to content

Commit

Permalink
fix: better version parsing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
b12k committed Feb 27, 2023
1 parent 62153a4 commit 78a26bb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 42 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@
"@swc/core": "1.3.36",
"@swc/helpers": "0.4.14",
"@types/fs-extra": "11.0.1",
"@types/git-raw-commits": "2.0.1",
"@types/glob": "8.0.1",
"@types/node": "18.14.0",
"@types/semver-sort": "0.0.1",
"@typescript-eslint/eslint-plugin": "5.53.0",
"@typescript-eslint/parser": "5.53.0",
"chokidar": "3.5.3",
Expand Down Expand Up @@ -81,6 +79,6 @@
"commander": "10.0.0",
"fs-extra": "11.1.0",
"glob": "8.1.0",
"semver-sort": "1.0.0"
"to-semver": "4.0.0"
}
}
50 changes: 18 additions & 32 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 20 additions & 7 deletions src/skip.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { execSync } from 'node:child_process';
import semverSort from 'semver-sort';
import toSemver from 'to-semver';

import { Logger, doNothing } from './utils';

Expand All @@ -15,18 +15,31 @@ export const skip = (config: SkipConfig) => {

log({ config });

const tags = execSync('git tag')
const relatedTags = execSync('git tag')
.toString()
.split('\n')
.filter((tag) => tag.includes(name))
.map((tag) => tag.split('-v')[1]);
.filter((tag) => tag.includes(name));

if (tags.length === 0) {
log({ message: 'tags not found', skip: false });
if (relatedTags.length === 0) {
log({ message: 'no related tags found', skip: false });
return false;
}

const latestTag = `${name}-v${semverSort.desc(tags)[0]}`;
const latestVersion = toSemver(relatedTags)[0];

if (!latestVersion) {
log({ message: 'no latest version found', skip: false });
return false;
}

log({ latestVersion });

const latestTag = relatedTags.find((tag) => tag.includes(latestVersion));

if (!latestTag) {
log({ message: 'no latest tag found', skip: false });
return false;
}

log({ latestTag });

Expand Down

0 comments on commit 78a26bb

Please sign in to comment.