Skip to content
Open
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
160 changes: 44 additions & 116 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@ jobs:
ci:
uses: ./.github/workflows/build.yml

version:
publish:
needs: ci
runs-on: ubuntu-latest
timeout-minutes: 30
outputs:
version: ${{ steps.version.outputs.version }}
environment: release
env:
NPM_DIST_TAG: ${{ github.ref_name == github.event.repository.default_branch && 'latest' || 'beta' }}
steps:
- name: Checkout
uses: actions/checkout@v7
with:
ref: ${{ github.ref }}
fetch-depth: 0
ssh-key: ${{ secrets.DEPLOY_PRIVATE_KEY }}

- name: Setup Node.js
uses: actions/setup-node@v7
Expand All @@ -54,146 +55,73 @@ jobs:
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
if: ${{ !inputs.skip_versioning }}
run: npm ci

- name: Determine version bump
id: bump
if: ${{ !inputs.skip_versioning && inputs.version_override == '' }}
- name: Build core package
working-directory: packages/blockly
run: |
RELEASE_TYPE=$(npx conventional-recommended-bump --preset conventionalcommits -t blockly-)
echo "release_type=$RELEASE_TYPE" >> "$GITHUB_OUTPUT"
echo "Recommended bump: $RELEASE_TYPE"
run: npm run package

- name: Apply version bump
- name: Version
if: ${{ !inputs.skip_versioning }}
working-directory: packages/blockly
env:
GH_TOKEN: ${{ github.token }}
VERSION_OVERRIDE: ${{ inputs.version_override }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
REF_NAME: ${{ github.ref_name }}
RELEASE_TYPE: ${{ steps.bump.outputs.release_type }}
VERSION_OVERRIDE: ${{ inputs.version_override }}
DRY_RUN: ${{ inputs.dry_run}}
run: |
set -euo pipefail
VERSION_COMMAND="npx lerna version"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm essentially doing a string builder and adding the appropriate flags depending on the inputs and which branch we're working from.

if [ -n "${VERSION_OVERRIDE}" ]; then
npm version "${VERSION_OVERRIDE}" --no-git-tag-version
exit 0
VERSION_COMMAND="${VERSION_COMMAND} ${VERSION_OVERRIDE}"
fi
if [ "${REF_NAME}" = "${DEFAULT_BRANCH}" ]; then
npm version "${RELEASE_TYPE}" --no-git-tag-version
exit 0
VERSION=$(node -p "require('./packages/blockly/package.json').version")
if [[ "${VERSION}" == *"-beta."* ]]; then
VERSION_COMMAND="${VERSION_COMMAND} --conventional-graduate"
fi
else
VERSION_COMMAND="${VERSION_COMMAND} --conventional-prerelease --preid beta"
fi
VERSION=$(node -p "require('./package.json').version")
if [[ "${VERSION}" == *"-beta."* ]]; then
npm version prerelease --preid=beta --no-git-tag-version
VERSION_COMMAND="${VERSION_COMMAND} --conventional-commits --no-git-tag-version --yes"
if [ "${DRY_RUN}" = "true" ]; then

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a change from what I showed you the other day. I moved dry run into here so that we're using the same version command that would be applied with the same inputs.

DIST_TAG=$([ ${REF_NAME} = ${DEFAULT_BRANCH} ] && echo "latest" || echo "beta")
VERSION_COMMAND="${VERSION_COMMAND} --no-push"
RELEASE_VERSIONS=$(eval "$VERSION_COMMAND")
echo "Dry run: would publish the following versions to npm dist-tag: ${DIST_TAG}"
echo "${RELEASE_VERSIONS}"
if [ "${REF_NAME}" != "${DEFAULT_BRANCH}" ]; then
echo "GitHub release would be created as prerelease."
fi
else
case "${RELEASE_TYPE}" in
major) npm version premajor --preid=beta --no-git-tag-version ;;
minor) npm version preminor --preid=beta --no-git-tag-version ;;
patch) npm version prepatch --preid=beta --no-git-tag-version ;;
*)
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
exit 1
;;
esac
eval "$VERSION_COMMAND"
fi

- name: Read package version
id: version
working-directory: packages/blockly
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Version: $VERSION"

- name: Dry run summary
if: ${{ inputs.dry_run }}
- name: Publish
env:
GH_TOKEN: ${{ github.token }}
SKIP_VERSIONING: ${{ inputs.skip_versioning }}
run: |
DIST_TAG="${{ github.ref_name == github.event.repository.default_branch && 'latest' || 'beta' }}"
echo "Dry run: would publish version ${{ steps.version.outputs.version }} to npm dist-tag: ${DIST_TAG}"
if [ "${{ github.ref_name }}" != "${{ github.event.repository.default_branch }}" ]; then
echo "GitHub release would be created as prerelease."
if [ "${SKIP_VERSIONING}" = "true" ]; then
npx lerna publish from-package --yes --loglevel silly

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove the --loglevel silly once we're happy with the results

else
npx lerna publish from-git --yes --loglevel silly
fi

- name: Upload versioned files
if: ${{ !inputs.skip_versioning }}
uses: actions/upload-artifact@v7
with:
name: versioned-files
path: |
packages/blockly/package.json
package-lock.json

publish:
needs: version
runs-on: ubuntu-latest
if: ${{ !inputs.dry_run }}
environment: release
env:
NPM_DIST_TAG: ${{ github.ref_name == github.event.repository.default_branch && 'latest' || 'beta' }}
steps:
- name: Checkout
uses: actions/checkout@v7
with:
ref: ${{ github.ref }}
fetch-depth: 0
ssh-key: ${{ secrets.DEPLOY_PRIVATE_KEY }}

- name: Download versioned files
if: ${{ !inputs.skip_versioning }}
uses: actions/download-artifact@v8
with:
name: versioned-files

- name: Commit and push version bump
if: ${{ !inputs.skip_versioning }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add packages/blockly/package.json package-lock.json
git commit -m "release: v${{ needs.version.outputs.version }}"
git push
TAG="blockly-v${{ needs.version.outputs.version }}"
git tag "$TAG"
git push origin "refs/tags/$TAG"

- name: Setup Node.js
uses: actions/setup-node@v7
with:
node-version: 24.x
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm ci

- name: Build package
working-directory: packages/blockly
run: npm run package

- name: Publish to npm
working-directory: packages/blockly/dist
run: npm publish --tag "${NPM_DIST_TAG}" --verbose

- name: Create tarball
working-directory: packages/blockly
run: npm pack ./dist

- name: Create GitHub release
working-directory: packages/blockly
env:
GH_TOKEN: ${{ github.token }}
run: |
TARBALL="blockly-${{ needs.version.outputs.version }}.tgz"
VERSION=$(node -p "require('.packages/blockly/package.json').version")
TARBALL="blockly-*${VERSION}.tgz"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure on this. I did a test of packing locally and all of the file names matched this pattern, so I think this will work.

if [ "${{ github.ref_name }}" != "${{ github.event.repository.default_branch }}" ]; then
gh release create "blockly-v${{ needs.version.outputs.version }}" "$TARBALL" \
gh release create "blockly-v${VERSION}" "$TARBALL" \
--repo "$GITHUB_REPOSITORY" \
--title "blockly-v${{ needs.version.outputs.version }}" \
--title "blockly-v${VERSION}" \
--generate-notes \
--prerelease
else
gh release create "blockly-v${{ needs.version.outputs.version }}" "$TARBALL" \
gh release create "blockly-v${VERSION}" "$TARBALL" \
--repo "$GITHUB_REPOSITORY" \
--title "blockly-v${{ needs.version.outputs.version }}" \
--title "blockly-v${VERSION}" \
--generate-notes
fi
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ build-debug.log
/nbproject/private/
tsdoc-metadata.json
.vscode
CHANGELOG.md

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell from the Lerna documentation, there's no per-package configuration for version. I'm hoping adding the root level and blockly package changelog files to gitignore will prevent them from being published.


# All packages
build/
Expand All @@ -23,6 +24,7 @@ packages/blockly/tests/compile/main_compressed.js
packages/blockly/tests/compile/main_compressed.js.map
packages/blockly/tests/mocha/test-modules.generated.mjs
packages/blockly/temp/
packages/blockly/CHANGELOG.md

# Docs:
# Autogenerated reference docs, do not check in
Expand Down
18 changes: 18 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": "13.2.0",
"npmClient": "npm",
"changelogPreset": {
"name": "conventionalcommits"
},
"ignoreChanges": ["**/package-lock.json"],
"command": {
"version": {
"tagVersionPrefix": "blockly-v"
},
"publish": {
"tagVersionPrefix": "blockly-v"
}
},
"packages": ["packages/blockly", "packages/plugins/*"],
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
}
Loading