-
Notifications
You must be signed in to change notification settings - Fork 3.9k
chore: update version and publish workflow #10231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
2116ddb
6428341
faa888b
749b323
5c05175
3f3218f
536491d
2132ed9
4eb6267
e2531d4
1d92b1d
a4b032a
822a245
2c5b42f
b61707c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,19 +33,20 @@ permissions: | |
| jobs: | ||
| ci: | ||
| uses: ./.github/workflows/build.yml | ||
|
|
||
| version: | ||
| publish: | ||
| 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 | ||
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| 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" | ||
| } |
There was a problem hiding this comment.
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