Skip to content
205 changes: 205 additions & 0 deletions .github/workflows/publish-v5-alpha.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
name: Publish V5 Alpha 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-alpha
cancel-in-progress: false

jobs:
publish_v5_alpha:
name: Build and Publish V5 Alpha
runs-on: ubuntu-latest

# Needed for Publishing
permissions:
contents: write
packages: write

steps:
# Always checkout moldy/v5-base, regardless of which branch the workflow file lives on
- name: Checkout moldy/v5-base branch
uses: actions/checkout@v3
with:
ref: moldy/v5-base
token: ${{ secrets.ALCHEMY_BOT_PAT }}
fetch-depth: "0"
submodules: "recursive"

- name: Free up disk space
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this required on every run?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good question. i just copied it from the other publishing action.

looks like @blakecduncan added it a couple of months ago b/c the other GHA was running out of disk space: 0c1b48a

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

# Swap to v5 lerna config temporarily
- name: Setup V5 Lerna Config
run: |
if [ ! -f lerna-v5.json ]; then
echo "ERROR: lerna-v5.json not found. This file is required for v5 publishing."
exit 1
fi
mv lerna.json lerna-v4.json.tmp
mv lerna-v5.json lerna.json

# 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 alpha)
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 ==="

# Restore lerna config after dry run
- name: Dry Run - Restore Lerna Config
if: ${{ inputs.publish == false }}
run: |
mv lerna.json lerna-v5.json
mv lerna-v4.json.tmp lerna.json

# Auto-increment prerelease version
- name: Increment Version
if: ${{ inputs.publish }}
shell: bash
run: |
echo "Auto-incrementing prerelease version..."
npx lerna version prerelease \
--preid alpha \
--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: |
git add -A
git commit --no-verify -m "chore: bump versions for alpha publish [skip ci]"

# Publish packages from the updated package.json versions
- name: Publish V5 Alpha to NPM
if: ${{ inputs.publish }}
shell: bash
run: |
set +e
npx lerna publish from-package \
--dist-tag alpha \
--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

# Restore lerna configs to their original names for committing
- name: Restore Lerna Config Names
if: ${{ inputs.publish }}
run: |
mv lerna.json lerna-v5.json
mv lerna-v4.json.tmp lerna.json

# Amend commit with restored lerna configs and create tag
- name: Amend Commit and Tag Changes
if: ${{ inputs.publish && env.lerna_published == 'true' }}
shell: bash
run: |
# Get the new version from lerna-v5.json
NEW_VERSION=$(node -p "require('./lerna-v5.json').version")
echo "Published version: $NEW_VERSION"

# Stage the restored lerna configs and removal of tmp file
git add lerna.json lerna-v5.json
git add -u # This stages the deletion of lerna-v4.json.tmp

# Amend the previous commit to include the restored lerna configs
git commit --amend --no-verify -m "chore(v5): publish alpha version $NEW_VERSION [skip ci]"

# Create tag for the release
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 moldy/v5-base
- name: Push Changes to moldy/v5-base
if: ${{ inputs.publish && env.lerna_published == 'true' && env.has_changes == 'true' }}
run: |
git push origin HEAD:moldy/v5-base --follow-tags
echo "Successfully pushed version ${{ env.new_version }} to moldy/v5-base"
2 changes: 1 addition & 1 deletion docs-site
Submodule docs-site updated 283 files
Loading