Skip to content

Commit a442d5a

Browse files
committed
chore: react-version worklow change
1 parent 8f92f41 commit a442d5a

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

.github/workflows/react-versions.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ jobs:
7272

7373
steps:
7474
- uses: actions/checkout@v4
75+
with:
76+
ref: ${{ github.head_ref || github.ref_name }}
77+
run: echo "branch=${{ github.head_ref || github.ref_name }}"
78+
7579

7680
- name: Setup Node.js
7781
uses: actions/setup-node@v4

scripts/version.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ const findLatestVersion = (versionSet) => {
66
};
77

88
const getAlphaVersion = (versionSet) => {
9-
let latestVersion = findLatestVersion(versionSet);
10-
const nextBetaVersion = semver.inc(latestVersion, 'preminor', 'beta');
11-
// 如果已经有beta版本了,那么就得发下个版本的alpla版
12-
if (versionSet.has(nextBetaVersion)) {
13-
latestVersion = semver.inc(latestVersion, 'minor');
9+
// 1. 找到最新的正式版(不带 pre-release 的)
10+
const arr = Array.isArray(versionSet) ? versionSet : [...versionSet];
11+
const validVersions = arr.filter(v => semver.valid(v));
12+
validVersions.sort(semver.rcompare);
13+
const latestStable = validVersions.find(v => !semver.prerelease(v));
14+
// 2. 计算下一个 minor 的 alpha.0
15+
const nextMinor = semver.inc(latestStable, 'minor');
16+
let nextAlpha = `${nextMinor}-alpha.0`;
17+
// 3. 如果已存在,则递增 alpha 号
18+
while (versionSet.has(nextAlpha)) {
19+
// 取当前 alpha 号,递增
20+
nextAlpha = semver.inc(nextAlpha, 'prerelease', 'alpha');
1421
}
15-
let nextVersion = semver.inc(latestVersion, 'preminor', 'alpha');
16-
while (versionSet.has(nextVersion)) {
17-
nextVersion = semver.inc(nextVersion, 'prerelease', 'alpha');
18-
}
19-
return nextVersion;
22+
return nextAlpha;
2023
};
2124

2225
const getBetaVersion = (versionSet) => {

0 commit comments

Comments
 (0)