44 workflow_dispatch :
55 inputs :
66 dry_run :
7- description : ' Dry run - print the version that would be published, but do not commit or publish anything.'
7+ description : >
8+ Dry run — print the version and npm dist-tag that would be used; no commit or publish.
9+ Pick the branch to publish from with the "Use workflow from" dropdown.
10+ Non-default branches publish to the npm dist-tag `beta` (not `latest`).
811 required : false
912 default : false
1013 type : boolean
1114 skip_versioning :
1215 description : >
13- Skip version bump - use the version already in the repo
16+ Skip version bump — use the version already in the repo
1417 (e.g. retry after npm publish failed but the release commit is already pushed).
1518 required : false
1619 default : false
1720 type : boolean
21+ version_override :
22+ description : >
23+ Optional. Full semver to publish (e.g. 12.6.0-beta.2). Skips conventional bump when set.
24+ Leave empty for automatic versioning.
25+ required : false
26+ default : ' '
27+ type : string
1828
1929permissions :
2030 contents : write
3444 - name : Checkout
3545 uses : actions/checkout@v5
3646 with :
47+ ref : ${{ github.ref }}
3748 fetch-depth : 0
3849
3950 - name : Setup Node.js
4859
4960 - name : Determine version bump
5061 id : bump
51- if : ${{ !inputs.skip_versioning }}
62+ if : ${{ !inputs.skip_versioning && inputs.version_override == '' }}
5263 working-directory : packages/blockly
5364 run : |
5465 RELEASE_TYPE=$(npx conventional-recommended-bump --preset conventionalcommits -t blockly-)
5869 - name : Apply version bump
5970 if : ${{ !inputs.skip_versioning }}
6071 working-directory : packages/blockly
61- run : npm version ${{ steps.bump.outputs.release_type }} --no-git-tag-version
72+ env :
73+ DEFAULT_BRANCH : ${{ github.event.repository.default_branch }}
74+ REF_NAME : ${{ github.ref_name }}
75+ RELEASE_TYPE : ${{ steps.bump.outputs.release_type }}
76+ VERSION_OVERRIDE : ${{ inputs.version_override }}
77+ run : |
78+ set -euo pipefail
79+ if [ -n "${VERSION_OVERRIDE}" ]; then
80+ npm version "${VERSION_OVERRIDE}" --no-git-tag-version
81+ exit 0
82+ fi
83+ if [ "${REF_NAME}" = "${DEFAULT_BRANCH}" ]; then
84+ npm version "${RELEASE_TYPE}" --no-git-tag-version
85+ exit 0
86+ fi
87+ VERSION=$(node -p "require('./package.json').version")
88+ if [[ "${VERSION}" == *"-beta."* ]]; then
89+ npm version prerelease --preid=beta --no-git-tag-version
90+ else
91+ case "${RELEASE_TYPE}" in
92+ major) npm version premajor --preid=beta --no-git-tag-version ;;
93+ minor) npm version preminor --preid=beta --no-git-tag-version ;;
94+ patch) npm version prepatch --preid=beta --no-git-tag-version ;;
95+ *)
96+ echo "::error title=Invalid release bump::conventional-recommended-bump returned '${RELEASE_TYPE}' (expected major, minor, or patch). Fix commits/tags or set version_override." >&2
97+ exit 1
98+ ;;
99+ esac
100+ fi
62101
63102 - name : Read package version
64103 id : version
@@ -68,6 +107,15 @@ jobs:
68107 echo "version=$VERSION" >> "$GITHUB_OUTPUT"
69108 echo "Version: $VERSION"
70109
110+ - name : Dry run summary
111+ if : ${{ inputs.dry_run }}
112+ run : |
113+ DIST_TAG="${{ github.ref_name == github.event.repository.default_branch && 'latest' || 'beta' }}"
114+ echo "Dry run: would publish version ${{ steps.version.outputs.version }} to npm dist-tag: ${DIST_TAG}"
115+ if [ "${{ github.ref_name }}" != "${{ github.event.repository.default_branch }}" ]; then
116+ echo "GitHub release would be created as prerelease."
117+ fi
118+
71119 - name : Upload versioned files
72120 if : ${{ !inputs.skip_versioning }}
73121 uses : actions/upload-artifact@v4
@@ -82,10 +130,13 @@ jobs:
82130 runs-on : ubuntu-latest
83131 if : ${{ !inputs.dry_run }}
84132 environment : release
133+ env :
134+ NPM_DIST_TAG : ${{ github.ref_name == github.event.repository.default_branch && 'latest' || 'beta' }}
85135 steps :
86136 - name : Checkout
87137 uses : actions/checkout@v5
88138 with :
139+ ref : ${{ github.ref }}
89140 fetch-depth : 0
90141 ssh-key : ${{ secrets.DEPLOY_PRIVATE_KEY }}
91142
@@ -119,7 +170,7 @@ jobs:
119170
120171 - name : Publish to npm
121172 working-directory : packages/blockly/dist
122- run : npm publish --verbose
173+ run : npm publish --tag "${NPM_DIST_TAG}" -- verbose
123174
124175 - name : Create tarball
125176 working-directory : packages/blockly
@@ -131,7 +182,15 @@ jobs:
131182 GH_TOKEN : ${{ github.token }}
132183 run : |
133184 TARBALL="blockly-${{ needs.version.outputs.version }}.tgz"
134- gh release create "blockly-v${{ needs.version.outputs.version }}" "$TARBALL" \
135- --repo "$GITHUB_REPOSITORY" \
136- --title "blockly-v${{ needs.version.outputs.version }}" \
137- --generate-notes
185+ if [ "${{ github.ref_name }}" != "${{ github.event.repository.default_branch }}" ]; then
186+ gh release create "blockly-v${{ needs.version.outputs.version }}" "$TARBALL" \
187+ --repo "$GITHUB_REPOSITORY" \
188+ --title "blockly-v${{ needs.version.outputs.version }}" \
189+ --generate-notes \
190+ --prerelease
191+ else
192+ gh release create "blockly-v${{ needs.version.outputs.version }}" "$TARBALL" \
193+ --repo "$GITHUB_REPOSITORY" \
194+ --title "blockly-v${{ needs.version.outputs.version }}" \
195+ --generate-notes
196+ fi
0 commit comments