Skip to content

Commit cdcdaf3

Browse files
authored
chore: add ability to publish prereleases (#9687)
* chore: add ability to publish prereleases * chore: error if release version is not valid
1 parent 61583ff commit cdcdaf3

2 files changed

Lines changed: 73 additions & 9 deletions

File tree

.github/workflows/build.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
steps:
2828
- uses: actions/checkout@v5
2929
with:
30+
ref: ${{ github.ref }}
3031
persist-credentials: false
3132

3233
- name: Reconfigure git to use HTTP authentication
@@ -58,6 +59,8 @@ jobs:
5859
runs-on: ubuntu-latest
5960
steps:
6061
- uses: actions/checkout@v5
62+
with:
63+
ref: ${{ github.ref }}
6164

6265
- name: Use Node.js 20.x
6366
uses: actions/setup-node@v5
@@ -75,6 +78,8 @@ jobs:
7578
runs-on: ubuntu-latest
7679
steps:
7780
- uses: actions/checkout@v5
81+
with:
82+
ref: ${{ github.ref }}
7883

7984
- name: Use Node.js 20.x
8085
uses: actions/setup-node@v5

.github/workflows/publish.yml

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,27 @@ on:
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

1929
permissions:
2030
contents: write
@@ -34,6 +44,7 @@ jobs:
3444
- name: Checkout
3545
uses: actions/checkout@v5
3646
with:
47+
ref: ${{ github.ref }}
3748
fetch-depth: 0
3849

3950
- name: Setup Node.js
@@ -48,7 +59,7 @@ jobs:
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-)
@@ -58,7 +69,35 @@ jobs:
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

Comments
 (0)