Skip to content

Publish V5 Beta Packages #2

Publish V5 Beta Packages

Publish V5 Beta Packages #2

name: Publish V5 Beta Packages
# workflow dispatch requires a maintainer to go to the Actions tab and manually trigger the workflow
on:
workflow_dispatch:
inputs:
publish:
description: "Publish packages (leave unchecked for dry-run)"
required: true
default: false
type: boolean
# Sets permissions of the GITHUB_TOKEN
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent publish
concurrency:
group: publish-v5-beta
cancel-in-progress: false
jobs:
publish_v5_beta:
name: Build and Publish V5 Beta
runs-on: ubuntu-latest
# Needed for Publishing
permissions:
contents: write
packages: write
steps:
# Always checkout v5.x.x, regardless of which branch the workflow file lives on
- name: Checkout v5.x.x branch
uses: actions/checkout@v3
with:
ref: v5.x.x
token: ${{ secrets.ALCHEMY_BOT_PAT }}
fetch-depth: "0"
submodules: "recursive"
- name: Free up disk space
run: |
echo "Disk space before cleanup:"
df -h
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo docker image prune --all --force
echo "Disk space after cleanup:"
df -h
# Clear yarn cache to avoid stale workspace resolution from other branches
- name: Clear Yarn Cache
run: yarn cache clean
- name: Setup
uses: ./.github/actions/setup
with:
use-android-cache: false
- name: Set Github User Details
run: |
git config --global user.name "Alchemy Bot"
git config --global user.email "alchemy-bot@alchemy.com"
- name: Set NPM Permissions
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc
- name: Build V5 Packages
run: yarn build:libs
# Dry run to see what would be published
- name: Dry Run - Show what would be published
if: ${{ inputs.publish == false }}
shell: bash
run: |
echo "=== DRY RUN MODE - No packages will be published ==="
echo ""
CURRENT_VERSION=$(node -p "require('./lerna.json').version")
echo "Current version: $CURRENT_VERSION"
NEXT_VERSION=$(npx semver $CURRENT_VERSION -i prerelease --preid beta)
echo "Next version: $NEXT_VERSION"
echo ""
echo "Packages that would be published:"
npx lerna ls --long
echo ""
echo "=== To actually publish, re-run with 'publish' checkbox checked ==="
# Auto-increment prerelease version
- name: Increment Version
if: ${{ inputs.publish }}
shell: bash
run: |
echo "Auto-incrementing prerelease version..."
npx lerna version prerelease \
--preid beta \
--no-push \
--no-git-tag-version \
--yes \
--force-publish \
--no-private \
--ignore-scripts
# Run inject-version scripts to update version.ts files with new versions
- name: Inject Versions
if: ${{ inputs.publish }}
run: |
for pkg in packages/*/; do
if [ -f "$pkg/inject-version.ts" ]; then
echo "Injecting version for $pkg"
(cd "$pkg" && npx tsx inject-version.ts)
fi
done
# Commit version changes so lerna publish doesn't complain about uncommitted changes
- name: Commit Version Changes
if: ${{ inputs.publish }}
run: |
NEW_VERSION=$(node -p "require('./lerna.json').version")
git add -A
git commit --no-verify -m "chore(v5): publish beta version $NEW_VERSION [skip ci]"
# Publish packages from the updated package.json versions
- name: Publish V5 Beta to NPM
if: ${{ inputs.publish }}
shell: bash
run: |
set +e
npx lerna publish from-package \
--no-private \
--no-verify-access \
--yes \
--ignore-scripts
LERNA_EXIT=$?
set -e
if [ $LERNA_EXIT -ne 0 ]; then
echo "Lerna publish exited with code $LERNA_EXIT"
echo "This may mean some packages failed to publish"
echo "lerna_published=false" >> $GITHUB_ENV
exit $LERNA_EXIT
else
echo "Lerna publish completed successfully"
echo "lerna_published=true" >> $GITHUB_ENV
fi
# Tag the version commit
- name: Tag Changes
if: ${{ inputs.publish && env.lerna_published == 'true' }}
shell: bash
run: |
NEW_VERSION=$(node -p "require('./lerna.json').version")
echo "Published version: $NEW_VERSION"
TAG_NAME="v$NEW_VERSION"
echo "Creating tag: $TAG_NAME"
git tag -a "$TAG_NAME" -m "v$NEW_VERSION"
echo "has_changes=true" >> $GITHUB_ENV
echo "new_version=$NEW_VERSION" >> $GITHUB_ENV
# Push commit and tags to v5.x.x
- name: Push Changes to v5.x.x
if: ${{ inputs.publish && env.lerna_published == 'true' && env.has_changes == 'true' }}
run: |
git push origin HEAD:v5.x.x --follow-tags
echo "Successfully pushed version ${{ env.new_version }} to v5.x.x"