-
Notifications
You must be signed in to change notification settings - Fork 208
ci: add gha to publish v5 alpha pkgs #2305
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2cf71c0
ci: add gha to publish v5 alpha pkgs
jakehobbs 99f73af
ci: test publish
jakehobbs 12ca27d
ci: clear yarn cache
jakehobbs bd6b53c
Merge branch 'main' into jake/v5-alpha-publish
jakehobbs 9d0ad6e
ci: test actual publish
jakehobbs 75aa027
ci: fix lerna publish step
jakehobbs 1221f08
ci: ship commit checks
jakehobbs 8cca95b
ci: push to correct branch for testing
jakehobbs ab33f5b
ci: remove staged tmp file
jakehobbs 58d57fc
ci: remove debugging
jakehobbs f96ddde
ci: run inject-version after version bump
jakehobbs 1ce030e
chore: use semver instead of awkward manual version calculation for d…
jakehobbs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,206 @@ | ||
| 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 | ||
| 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 "[email protected]" | ||
|
|
||
| - 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" | ||
| # Calculate next version (increment the number after the last dot) | ||
| NEXT_VERSION=$(echo "$CURRENT_VERSION" | awk -F. -v OFS=. '{$NF++; print}') | ||
|
||
| 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" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why is this required on every run?
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.
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