From 1729270f3f5a77eece4938e9df06d67ac7157bc6 Mon Sep 17 00:00:00 2001 From: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> Date: Mon, 11 Aug 2025 04:26:13 -0400 Subject: [PATCH 1/2] chore: remove Lerna and publishing scripts Removed `lerna.json`, custom publishing scripts, and related GPG setup from workflows. Simplified the publishing process by migrating to direct npm commands in GitHub Actions. Cleaned up unnecessary dependencies and configurations. --- .github/workflows/npm-publish.yml | 55 +++--------- lerna.json | 20 ----- scripts/publish-to-npm.sh | 136 ------------------------------ 3 files changed, 14 insertions(+), 197 deletions(-) delete mode 100644 lerna.json delete mode 100755 scripts/publish-to-npm.sh diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 81ade43..f7fdcb3 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -2,7 +2,7 @@ name: NPM Publish on: release: - types: [created] + types: [ created ] workflow_dispatch: inputs: version: @@ -15,30 +15,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - with: - submodules: recursive - fetch-depth: 0 - - - name: Install GPG - run: | - sudo apt-get update - sudo apt-get install -y gnupg - - - name: Import GPG key - env: - GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} - run: | - mkdir -p ~/.gnupg - chmod 700 ~/.gnupg - echo "$GPG_PRIVATE_KEY" | gpg --batch --import - gpg --list-secret-keys --keyid-format LONG # Print all keys for debugging - KEY_ID=$(gpg --list-secret-keys --keyid-format LONG | awk '/^sec/{print $2}' | awk -F'/' '{print $2}') - echo "GPG key ID: $KEY_ID" # Debug line to print the KEY_ID - echo "default-key $KEY_ID" >> ~/.gnupg/gpg.conf - echo "use-agent" >> ~/.gnupg/gpg.conf - echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf - echo "KEY_ID=$KEY_ID" >> $GITHUB_ENV - export GPG_TTY=$(tty) - name: Setup Bun uses: oven-sh/setup-bun@v1 @@ -49,28 +25,25 @@ jobs: uses: foundry-rs/foundry-toolchain@v1 with: version: stable - + - name: Install dependencies run: bun install + - name: Build + run: bun run build + - name: Run tests - run: forge test + run: bun run test - name: Authenticate to npm run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc - - name: Check npm login - run: | - npm whoami || (echo "Not logged in to npm registry" && exit 1) - - - name: Run Nightly Script - env: - GH_TOKEN: ${{ secrets.TOWNS_DIAMOND_PAT }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} + - name: Set version and publish run: | - git config user.name "GitHub Action Bot" - git config user.email "john+bot@towns.com" - git config commit.gpgSign false - git config user.signingkey ${{ env.KEY_ID }} - ./scripts/publish-to-npm.sh ${{ inputs.version }} + VERSION="${{ github.event.release.tag_name || inputs.version }}" + if [ -n "$VERSION" ]; then + # Remove 'v' prefix if present + VERSION=$(echo "$VERSION" | sed 's/^v//') + npm version "$VERSION" --no-git-tag-version + fi + npm publish --access public diff --git a/lerna.json b/lerna.json deleted file mode 100644 index b56bd31..0000000 --- a/lerna.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "version": "0.6.1", - "npmClient": "bun", - "command": { - "publish": { - "registry": "https://registry.npmjs.org/", - "access": "public" - }, - "version": { - "allowBranch": [ - "main", - "release-diamond/*" - ], - "message": "chore(release): publish %s" - } - }, - "packages": [ - "." - ] -} \ No newline at end of file diff --git a/scripts/publish-to-npm.sh b/scripts/publish-to-npm.sh deleted file mode 100755 index 12a8c8d..0000000 --- a/scripts/publish-to-npm.sh +++ /dev/null @@ -1,136 +0,0 @@ -#!/usr/bin/env bash - -function parse_git_branch() { - git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' -} - -function make_pr_description() { - # Use git log to list commit messages not present on origin/main - git log origin/main..HEAD -} - -# You must be on main with a clean working directory to run this script. -if [[ "$(git status --porcelain)" != "" ]]; then - echo "There are uncommitted changes. Please commit or stash them before running this script." - exit 1 -fi - -INPUT_VERSION="$1" - -# get the current git hash -COMMIT_HASH=$(git rev-parse --short HEAD) -BRANCH_NAME="release-diamond/${COMMIT_HASH}" -PR_TITLE="Release Towns Protocol Diamond ${COMMIT_HASH}" -VERSION_PREFIX="towns-protocol/diamond-${COMMIT_HASH}-" - -git checkout -b "${BRANCH_NAME}" - -bun install -exit_status_yarn=$? - -if [ $exit_status_yarn -ne 0 ]; then - echo "bun install failed." - exit 1 -fi - -bun add -g lerna - -bun run build -exit_status_build=$? - -if [ $exit_status_build -ne 0 ]; then - echo "bun build failed." - exit 1 -fi - -git add . -git commit -m "release diamond ${VERSION_PREFIX}" - -git push -u origin "${BRANCH_NAME}" - -# If input version is provided, use it, otherwise use Lerna to get the new patch version -if [ -z "$INPUT_VERSION" ]; then - npx lerna version patch --yes --force-publish --no-private --tag-version-prefix "${VERSION_PREFIX}" -else - echo "Using provided version: ${INPUT_VERSION}" - npx lerna version "${INPUT_VERSION}" --yes --force-publish --no-private --tag-version-prefix "${VERSION_PREFIX}" -fi - -PR_DESCRIPTION="$(make_pr_description)" - -# Create PR and capture the PR number -PR_URL=$(gh pr create --base main --head "${BRANCH_NAME}" --title "${PR_TITLE}" --body "${PR_DESCRIPTION}") -if [ $? -ne 0 ]; then - echo "Failed to create PR" - exit 1 -fi -PR_NUMBER=$(echo $PR_URL | rev | cut -d'/' -f1 | rev) - -# Enable auto-merge -gh pr merge "${PR_NUMBER}" --auto --squash - -echo "Created PR #${PR_NUMBER}" - -while true; do - WAIT_TIME=5 - while true; do - OUTPUT=$(gh pr checks "${BRANCH_NAME}" 2>&1) - if [[ "$OUTPUT" == *"no checks reported on the '${BRANCH_NAME}' branch"* ]]; then - echo "Checks for '${BRANCH_NAME}' haven't started yet. Waiting for $WAIT_TIME seconds..." - sleep $WAIT_TIME - else - break - fi - done - - gh pr checks "${BRANCH_NAME}" --fail-fast --interval 2 --watch - exit_status=$? - - # Check if the command succeeded or failed - if [ $exit_status -ne 0 ]; then - echo "Failure detected in PR checks." - if [[ $USER_MODE -eq 1 ]]; then - read -p "CI is failing. Restart CI. (any key to retry/q) " -n 1 -r - echo "" - if [[ $REPLY =~ ^[Qq]$ ]]; then - echo "Pull request creation aborted." - exit $exit_status - fi - else - echo "CI is failing. Restart CI." - exit $exit_status - fi - else - echo "All checks passed." - break - fi -done - -# Wait for PR to be merged using the specific PR number -TIMEOUT=2100 # 35 minutes in seconds -START_TIME=$(date +%s) - -while gh pr view "$PR_NUMBER" --json state -q ".state" | grep -q "OPEN"; do - CURRENT_TIME=$(date +%s) - ELAPSED_TIME=$(($CURRENT_TIME - $START_TIME)) - - if [ $ELAPSED_TIME -ge $TIMEOUT ]; then - echo "Error: Timed out waiting for PR #${PR_NUMBER} to merge after 35 minutes" - exit 1 - fi - - echo "Waiting for PR #${PR_NUMBER} to be merged..." - sleep 30 -done -echo "PR #${PR_NUMBER} has been merged" - -# Pull the changes to local main -git pull --rebase - -# Publish the nightly version to npm -echo "Starting Lerna publish..." -npx lerna publish from-package --yes --no-private --force-publish --tag-version-prefix "${VERSION_PREFIX}" || { - echo "Lerna publish failed with exit code $?" - exit 1 -} -echo "Lerna publish completed successfully" From 5fd1dcd2fe7984a516de76cd49f53ad1637be530 Mon Sep 17 00:00:00 2001 From: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> Date: Mon, 11 Aug 2025 04:42:43 -0400 Subject: [PATCH 2/2] Update .github/workflows/npm-publish.yml Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .github/workflows/npm-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index f7fdcb3..e36c4da 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -2,7 +2,7 @@ name: NPM Publish on: release: - types: [ created ] + types: [ published ] workflow_dispatch: inputs: version: