Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/clean-jobs-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@alauda/ui": patch
---

fix: configure v9 release workflow

Fix the `release/v9` release workflow so v9 stable releases publish with the `v9` tag and v9 pull request prereleases publish with the `v9-beta` tag.
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"commit": false,
"linked": [],
"access": "restricted",
"baseBranch": "master",
"baseBranch": "release/v9",
"updateInternalDependencies": "minor",
"ignore": []
}
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Release
on:
push:
branches:
- master
- release/v9
pull_request:
branches:
- master
- release/v9
workflow_dispatch:
inputs:
version:
Expand Down Expand Up @@ -44,8 +44,8 @@ jobs:
id: changesets
uses: changesets/action@v1
with:
commit: 'chore: release @alauda/ui'
title: 'chore: release @alauda/ui'
commit: 'chore: release @alauda/ui v9'
title: 'chore: release @alauda/ui v9'
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: yarn release
env:
Expand All @@ -55,7 +55,7 @@ jobs:
if: github.event_name == 'pull_request'
run: sh scripts/release.sh
env:
PUBLISH_VERSION: beta
PUBLISH_VERSION: v9-beta

- name: Set git info
if: github.event_name == 'workflow_dispatch'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"lint:tsc": "tsc -p . --noEmit",
"prepare": "patch-package && simple-git-hooks && touch documentation.json && yarn-deduplicate --strategy fewer || exit 0",
"prerelease": "yarn build",
"release": "changeset publish",
"release": "changeset publish --tag v9",
"start": "yarn storybook",
"storybook": "ng run storybook:storybook",
"storybook:build": "ng run storybook:build-storybook",
Expand Down
4 changes: 3 additions & 1 deletion scripts/npm-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ const { getProdVersion } = require('./utils');

const version = process.env.PUBLISH_VERSION;

if (version.includes('-prod-')) {
if (version === 'v9-beta') {
process.stdout.write('v9-beta');
} else if (version.includes('-prod-')) {
process.stdout.write(getProdVersion(version));
} else if (version === 'beta' || /-beta[._-]?\d*$/.test(version)) {
process.stdout.write('beta');
Expand Down
58 changes: 45 additions & 13 deletions scripts/publish-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,56 @@ const { execSync } = require('node:child_process');

const semver = require('semver');

let version = process.env.PUBLISH_VERSION || 'patch';
const { version: packageVersion } = require('../package.json');

if (version.startsWith('v')) {
version = version.slice(1);
} else if (version === 'beta') {
const distTags = JSON.parse(
execSync('yarn info @alauda/ui dist-tags --json').toString(),
const PACKAGE_NAME = '@alauda/ui';

function getNpmInfo(field) {
const info = JSON.parse(
execSync(`yarn info ${PACKAGE_NAME} ${field} --json`).toString(),
);

const { beta, latest } = distTags.data || distTags;
return info.data || info;
}

function getNextBetaVersion(stable, versions) {
const nextBeta = semver.minVersion(`>${stable}`) + '-beta';
const nextVersion = semver.parse(nextBeta);
const candidates = versions
.filter(Boolean)
.filter(candidate => {
const parsed = semver.parse(candidate);

return (
parsed &&
parsed.major === nextVersion.major &&
parsed.minor === nextVersion.minor &&
parsed.patch === nextVersion.patch &&
parsed.prerelease[0] === 'beta'
);
})
.sort(semver.rcompare);

const latestBeta = candidates[0];

if (semver.gt(beta, latest)) {
version = beta.endsWith('-beta')
? beta + '.0'
: beta.replace(/(-beta\.)(\d+)$/, (_, $0, $1) => $0 + (+$1 + 1));
} else {
version = semver.minVersion(`>${latest}`) + '-beta';
if (!latestBeta) {
return nextBeta;
}

return latestBeta.endsWith('-beta')
? latestBeta + '.0'
: latestBeta.replace(/(-beta\.)(\d+)$/, (_, $0, $1) => $0 + (+$1 + 1));
}

let version = process.env.PUBLISH_VERSION || 'patch';

if (version === 'beta' || version === 'v9-beta') {
const versions = getNpmInfo('versions');
const stable = process.env.PUBLISH_BETA_BASE_VERSION || packageVersion;

version = getNextBetaVersion(stable, versions);
} else if (version.startsWith('v')) {
version = version.slice(1);
}

process.stdout.write(version);
3 changes: 2 additions & 1 deletion scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

set -e

REQUESTED_PUBLISH_VERSION=$PUBLISH_VERSION
PUBLISH_VERSION=$(node scripts/publish-version)
PUBLISH_BRANCH=$(node scripts/publish-branch)
NPM_TAG=$(node scripts/npm-tag)
NPM_TAG=$(PUBLISH_VERSION="$REQUESTED_PUBLISH_VERSION" node scripts/npm-tag)

if [ "$NPM_TAG" = "latest" ]; then
echo "Publish latest tag via this script is not permitted anymore."
Expand Down
Loading