@@ -2,6 +2,12 @@ name: Publish Package
22
33on :
44 workflow_dispatch :
5+ inputs :
6+ publish_beta :
7+ description : ' Publish as beta version?'
8+ required : false
9+ type : boolean
10+ default : false
511
612permissions :
713 id-token : write # Required for OIDC
@@ -27,17 +33,59 @@ jobs:
2733
2834 - uses : actions/checkout@v4
2935
30- - name : Display version to publish
31- run : |
32- VERSION=$(node -p "require('./package.json').version")
33- echo "📦 Publishing version: $VERSION"
34- echo "version=$VERSION" >> $GITHUB_ENV
35-
3636 - uses : actions/setup-node@v4
3737 with :
3838 node-version : ' 18'
3939 registry-url : ' https://registry.npmjs.org'
4040
41+ - name : Handle beta version
42+ if : inputs.publish_beta == true
43+ run : |
44+ BASE_VERSION=$(node -p "require('./package.json').version")
45+ PACKAGE_NAME=$(node -p "require('./package.json').name")
46+
47+ echo "🔍 Checking existing beta versions for $BASE_VERSION..."
48+
49+ # Get all published versions from npm (public packages don't need auth)
50+ VERSIONS_JSON=$(npm view "$PACKAGE_NAME" versions --json 2>/dev/null || echo "[]")
51+
52+ # Find the highest beta version for this base version
53+ BETA_NUM=$(node -e "
54+ const versions = JSON.parse('$VERSIONS_JSON' || '[]');
55+ const base = '$BASE_VERSION';
56+ const matching = versions
57+ .filter(v => typeof v === 'string' && v.startsWith(base + '-beta.'))
58+ .map(v => {
59+ const match = v.match(/-beta\.(\d+)$/);
60+ return match ? parseInt(match[1]) : 0;
61+ })
62+ .filter(n => !isNaN(n) && n > 0);
63+
64+ const nextBeta = matching.length > 0 ? Math.max(...matching) + 1 : 1;
65+ console.log(nextBeta);
66+ ")
67+
68+ BETA_VERSION="${BASE_VERSION}-beta.${BETA_NUM}"
69+
70+ # Update package.json with beta version
71+ node -e "
72+ const fs = require('fs');
73+ const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
74+ pkg.version = '$BETA_VERSION';
75+ fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
76+ "
77+
78+ echo "📦 Beta version determined: $BETA_VERSION"
79+ echo "version=$BETA_VERSION" >> $GITHUB_ENV
80+
81+ - name : Display version to publish
82+ run : |
83+ if [ "${{ inputs.publish_beta }}" != "true" ]; then
84+ VERSION=$(node -p "require('./package.json').version")
85+ echo "version=$VERSION" >> $GITHUB_ENV
86+ fi
87+ echo "📦 Publishing version: ${{ env.version }}"
88+
4189 - run : npm ci
4290
4391 - run : npm test --if-present
0 commit comments