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
175 changes: 58 additions & 117 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,20 @@ permissions:
jobs:
ci:
uses: ./.github/workflows/build.yml

version:
publish:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we should add the guard that we have in samples that doesn't bother to run any part of this if the owner isn't RaspberryPiFoundation

needs: ci
runs-on: ubuntu-latest
timeout-minutes: 30
outputs:
version: ${{ steps.version.outputs.version }}
# Don't try to publish from a fork of RaspberryPiFoundation/blockly-samples.
if: ${{ github.repository_owner == 'RaspberryPiFoundation' }}
environment: release
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,86 @@ 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 == '' }}
working-directory: packages/blockly
- name: Determine Dist Tag
id: dist
env:
VERSION_OVERRIDE: ${{ inputs.version_override }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
REF_NAME: ${{ github.ref_name }}
run: |
RELEASE_TYPE=$(npx conventional-recommended-bump --preset conventionalcommits -t blockly-)
echo "release_type=$RELEASE_TYPE" >> "$GITHUB_OUTPUT"
echo "Recommended bump: $RELEASE_TYPE"
DIST_TAG=$([[ "${VERSION_OVERRIDE}" == *"-beta."* || "${REF_NAME}" != "${DEFAULT_BRANCH}" ]] && echo "beta" || echo "latest")
echo "dist_tag=$DIST_TAG" >> "$GITHUB_OUTPUT"
echo "NPM distribution tag: $DIST_TAG"

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you want to keep this to make sure we can see error output and that an error in lerna causes the step to fail (my bash is kinda rusty tho)

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
if [ "${DIST_TAG}" = "latest" ]; then
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 --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.

VERSION_COMMAND="${VERSION_COMMAND} --no-push --no-git-tag-version"
echo "Dry run: would publish the following versions to npm dist-tag: ${DIST_TAG}"
eval "$VERSION_COMMAND"
if [ "${DIST_TAG}" = "beta" ]; 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
- name: Build core package
working-directory: packages/blockly
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Version: $VERSION"
run: npm run package

- name: Dry run summary
if: ${{ inputs.dry_run }}
- name: Publish

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this step also shouldn't run if dry run is true.

if: ${{ !inputs.dry_run }}
env:
GH_TOKEN: ${{ github.token }}
SKIP_VERSIONING: ${{ inputs.skip_versioning }}
DIST_TAG: ${{ steps.dist.outputs.dist_tag }}
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 --dist-tag ${DIST_TAG} --loglevel silly
else
npx lerna publish from-git --yes --dist-tag ${DIST_TAG} --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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this step shouldn't run if dry-run is true

working-directory: packages/blockly
if: ${{ !inputs.dry_run }}
env:
GH_TOKEN: ${{ github.token }}
DIST_TAG: ${{ steps.dist.outputs.dist_tag }}
run: |
TARBALL="blockly-${{ needs.version.outputs.version }}.tgz"
if [ "${{ github.ref_name }}" != "${{ github.event.repository.default_branch }}" ]; then
gh release create "blockly-v${{ needs.version.outputs.version }}" "$TARBALL" \
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this tarball isn't going to exist right now because you removed the "create tarball" step

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.

The publish step should create the tarball. I found that info here: https://github.com/lerna/lerna/tree/main/libs/commands/publish#lifecycle-scripts

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i'm pretty sure this will be in a temp directory though and not exist at the package root where you're looking for it here.

if [ "${DIST_TAG}" == "beta" ]; then
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

# 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