Skip to content

Commit e8fd957

Browse files
committed
chore: update CI workflows and enhance version retrieval logic
- Modified CI workflow to trigger on all branches instead of just main. - Added names to npm release workflows for better clarity. - Refactored version retrieval logic in get-next-version.js to improve handling of tagged versions and ensure fallback to "0.0.0" when no tags are found.
1 parent a3ab3d1 commit e8fd957

File tree

4 files changed

+66
-13
lines changed

4 files changed

+66
-13
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
name: CI
2-
32
on:
43
push:
5-
branches:
6-
- main
4+
branches: '*'
75
pull_request:
86

97
jobs:

.github/workflows/npm_napi_release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
name: NPM Node-API Release
12
on:
23
push:
34
branches:

.github/workflows/npm_release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
name: NPM Release iOS & macOS
12
on:
23
push:
34
branches:

scripts/get-next-version.js

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,71 @@ if (currentTag === "pr" && process.env.GITHUB_EVENT_PATH) {
2727

2828
const preRelease = `${currentTag}.${prPrerelease}${dayjs().format("YYYY-MM-DD")}-${runID}`;
2929

30-
let lastTagVersion = (
31-
process.env.LAST_TAGGED_VERSION ||
32-
child_process
33-
.spawnSync("git", ["describe", "--tags", "--abbrev=0", "--match=v*"])
34-
.stdout.toString()
35-
)
36-
.trim()
37-
.substring(1);
38-
if (!semver.parse(lastTagVersion)) {
39-
throw new Error("Invalid last tag version");
30+
function normalizeVersionCandidate(candidate) {
31+
if (!candidate) {
32+
return null;
33+
}
34+
35+
const trimmed = candidate.trim();
36+
if (!trimmed) {
37+
return null;
38+
}
39+
40+
const parsedDirect = semver.parse(trimmed);
41+
if (parsedDirect) {
42+
return parsedDirect.version;
43+
}
44+
45+
const withoutLeadingV = trimmed.replace(/^v/, "");
46+
const parsedWithoutV = semver.parse(withoutLeadingV);
47+
if (parsedWithoutV) {
48+
return parsedWithoutV.version;
49+
}
50+
51+
// Supports tag formats such as refs/tags/v1.2.3, pkg@1.2.3, etc.
52+
const extracted = trimmed.match(/\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?/);
53+
if (extracted && semver.parse(extracted[0])) {
54+
return extracted[0];
55+
}
56+
57+
return null;
4058
}
4159

60+
function getLastTagVersion() {
61+
const explicitTagVersion = normalizeVersionCandidate(process.env.LAST_TAGGED_VERSION);
62+
if (explicitTagVersion) {
63+
return explicitTagVersion;
64+
}
65+
66+
const gitDescribe = child_process.spawnSync("git", [
67+
"describe",
68+
"--tags",
69+
"--abbrev=0",
70+
"--match=v*",
71+
]);
72+
73+
const describedTag = normalizeVersionCandidate(gitDescribe.stdout.toString());
74+
if (describedTag) {
75+
return describedTag;
76+
}
77+
78+
// If v* matching tags are unavailable, try any tag name.
79+
const gitDescribeAnyTag = child_process.spawnSync("git", [
80+
"describe",
81+
"--tags",
82+
"--abbrev=0",
83+
]);
84+
85+
const anyTag = normalizeVersionCandidate(gitDescribeAnyTag.stdout.toString());
86+
if (anyTag) {
87+
return anyTag;
88+
}
89+
90+
return "0.0.0";
91+
}
92+
93+
const lastTagVersion = getLastTagVersion();
94+
4295
function setPreRelease(version) {
4396
const parsed = semver.parse(version);
4497
return semver.parse(

0 commit comments

Comments
 (0)