Skip to content

Commit

Permalink
ci: fix release candidate workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed Jul 8, 2022
1 parent 8097e1b commit 762ad05
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ on:
workflow_dispatch:
inputs:
ref:
description: "A valid branch or commit hash, eg: v2.14, master"
description: 'A valid branch or commit hash, eg: v2.14, master'
required: true
default: 'master'

distTag:
description: '要发布的 dist tag,仅可以为 alpha 或 beta'
required: true
default: 'beta'

jobs:
rc-version:
name: RC Version
Expand All @@ -20,10 +25,10 @@ jobs:

steps:
# 判断用户是否有写权限
- name: "Check if user has write access"
uses: "lannonbr/repo-permission-check-action@2.0.0"
- name: 'Check if user has write access'
uses: 'lannonbr/repo-permission-check-action@2.0.0'
with:
permission: "write"
permission: 'write'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -47,12 +52,12 @@ jobs:
- name: Publish version
run: |
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
node ./scripts/publishInCI
node ./scripts/publishRC
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
DIST_TAG: 'beta'
DIST_TAG: ${{ github.event.inputs.distTag }}

- name: Adding markdown
if: success()
Expand Down
2 changes: 1 addition & 1 deletion scripts/publishInCI.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const {
doPublish,
generateSematicVersion,
writePkgJson,
PKG_JSON_PATH
PKG_JSON_PATH,
} = require('./publishUtils');

let distTag = process.env.DIST_TAG;
Expand Down
53 changes: 53 additions & 0 deletions scripts/publishRC.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const { doPublish, PKG_JSON_PATH, getVersion } = require('./publishUtils');

const semver = require('semver');

async function main() {
let distTag = process.env.DIST_TAG;
let prereleaseText = undefined;
let releaseType = undefined;
if (distTag === 'beta') {
releaseType = 'prerelease';
prereleaseText = 'beta';
} else if (distTag === 'alpha') {
releaseType = 'prerelease';
prereleaseText = 'alpha';
}

if (!releaseType) {
console.log('distTag only allow `alpha` and `beta`');
return;
}

console.log('dist tag:', distTag);

const currentVersion = require(PKG_JSON_PATH).version;
console.log(`currentVersion`, currentVersion);

let baseVersion = currentVersion;
// 如果需要获取到最新的可用版本,要做一下检测
const latestVersions = await getVersion();
console.log(`latestVersions`, latestVersions);
if (distTag) {
const latestVersion = latestVersions[distTag];
if (latestVersion) {
// 如果查到的 npm 上的最新版比当前版本要大,那就用
if (semver.gte(latestVersion, currentVersion)) {
console.log(
`${latestVersion} >= ${currentVersion}, use ${baseVersion}`
);
baseVersion = latestVersion;
} else {
console.log(`${latestVersion} < ${currentVersion}, use ${baseVersion}`);
}
}
}
console.log('use base version: ', baseVersion);
const version = semver.inc(baseVersion, releaseType, prereleaseText);

console.log('version:', version);

doPublish(distTag, version);
}

main();

0 comments on commit 762ad05

Please sign in to comment.