|
88 | 88 | semver_string: ${{ github.ref_name }} |
89 | 89 | semver_pattern: '^release/(.*)$' |
90 | 90 |
|
91 | | - - name: update nextBump (release) |
| 91 | + - name: Check version-policy version (release) |
92 | 92 | if: startsWith(github.ref_name, 'release/') |
| 93 | + id: release_version_policy |
| 94 | + env: |
| 95 | + RELEASE_VERSION: ${{ steps.semver_release.outputs.full }} |
| 96 | + run: | |
| 97 | + node <<'NODE' |
| 98 | + const fs = require('fs'); |
| 99 | + const policies = JSON.parse(fs.readFileSync('common/config/rush/version-policies.json', 'utf8')); |
| 100 | + const policyVersion = policies[0] && policies[0].version; |
| 101 | + const releaseVersion = process.env.RELEASE_VERSION; |
| 102 | +
|
| 103 | + const parseVersion = version => String(version).split('-')[0].split('.').map(Number); |
| 104 | + const compareVersion = (a, b) => { |
| 105 | + const av = parseVersion(a); |
| 106 | + const bv = parseVersion(b); |
| 107 | + for (let i = 0; i < Math.max(av.length, bv.length); i++) { |
| 108 | + const diff = (av[i] || 0) - (bv[i] || 0); |
| 109 | + if (diff !== 0) { |
| 110 | + return diff; |
| 111 | + } |
| 112 | + } |
| 113 | + return 0; |
| 114 | + }; |
| 115 | +
|
| 116 | + if (!releaseVersion || !policyVersion) { |
| 117 | + console.error('Missing release version or version-policy version.', { releaseVersion, policyVersion }); |
| 118 | + process.exit(1); |
| 119 | + } |
| 120 | +
|
| 121 | + const result = compareVersion(releaseVersion, policyVersion); |
| 122 | + if (result < 0) { |
| 123 | + console.error( |
| 124 | + `Release version ${releaseVersion} is lower than version-policy version ${policyVersion}.` |
| 125 | + ); |
| 126 | + process.exit(1); |
| 127 | + } |
| 128 | +
|
| 129 | + const shouldSkip = result === 0 ? 'true' : 'false'; |
| 130 | + fs.appendFileSync(process.env.GITHUB_OUTPUT, `skip_next_bump=${shouldSkip}\n`); |
| 131 | + console.log( |
| 132 | + result === 0 |
| 133 | + ? `Release version ${releaseVersion} equals version-policy version ${policyVersion}, skip nextBump update.` |
| 134 | + : `Release version ${releaseVersion} is greater than version-policy version ${policyVersion}, update nextBump.` |
| 135 | + ); |
| 136 | + NODE |
| 137 | +
|
| 138 | + - name: update nextBump (release) |
| 139 | + if: startsWith(github.ref_name, 'release/') && steps.release_version_policy.outputs.skip_next_bump != 'true' |
93 | 140 | uses: xile611/set-next-bump-of-rush@main |
94 | 141 | with: |
95 | 142 | release_version: ${{ steps.semver_release.outputs.full }} |
@@ -309,8 +356,23 @@ jobs: |
309 | 356 | echo "Build packages: ${package_names[*]}" |
310 | 357 | node common/scripts/install-run-rush.js build "${build_args[@]}" |
311 | 358 |
|
312 | | - - name: Publish to npm (release) |
| 359 | + - name: Check npm version (release) |
313 | 360 | if: startsWith(github.ref_name, 'release/') |
| 361 | + id: npm_version_release |
| 362 | + env: |
| 363 | + PACKAGE_VERSION: ${{ steps.semver_release.outputs.main }} |
| 364 | + run: | |
| 365 | + set -euo pipefail |
| 366 | + if npm view "@visactor/vtable@$PACKAGE_VERSION" version --registry=https://registry.npmjs.org >/dev/null 2>&1; then |
| 367 | + echo "Version $PACKAGE_VERSION already exists on npm, skip publish." |
| 368 | + echo "skip_publish=true" >> "$GITHUB_OUTPUT" |
| 369 | + else |
| 370 | + echo "Version $PACKAGE_VERSION does not exist on npm, continue publish." |
| 371 | + echo "skip_publish=false" >> "$GITHUB_OUTPUT" |
| 372 | + fi |
| 373 | +
|
| 374 | + - name: Publish to npm (release) |
| 375 | + if: startsWith(github.ref_name, 'release/') && steps.npm_version_release.outputs.skip_publish != 'true' |
314 | 376 | run: node common/scripts/install-run-rush.js publish --publish --include-all --tag latest |
315 | 377 |
|
316 | 378 | - name: Update shrinkwrap |
|
0 commit comments