Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 157 additions & 0 deletions .github/scripts/npm-publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#!/usr/bin/env bash
set -euo pipefail

CURRENT_VERSION=$(node -p "require('./package.json').version")
BASE_VERSION="${CURRENT_VERSION%%-*}"
IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE_VERSION"

if [[ -z "${MAJOR:-}" || -z "${MINOR:-}" || -z "${PATCH:-}" ]]; then
echo ""
echo " ERROR: Invalid version: $CURRENT_VERSION"
echo " Expected valid semver (e.g. 1.2.3)"
echo ""
exit 1
fi

if [[ "$BRANCH_NAME" == "main" ]]; then
if [[ -z "${INPUT_VERSION:-}" ]]; then
echo ""
echo " ERROR: Version input is required on the main branch"
echo " Please provide a version (e.g. 1.2.3)"
echo ""
exit 1
fi
FINAL_VERSION="$INPUT_VERSION"
DIST_TAG="latest"
else
FINAL_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))-alpha.$(date +%s)"
DIST_TAG="alpha"
fi

TAG_NAME="v${FINAL_VERSION}"

echo ""
echo " ========================================"
echo " Release Summary"
echo " ========================================"
echo " Branch: $BRANCH_NAME"
echo " Current version: $CURRENT_VERSION"
echo " New version: $FINAL_VERSION"
echo " Dist-tag: $DIST_TAG"
echo " Git tag: $TAG_NAME"
echo " ========================================"
echo ""

echo " Writing version $FINAL_VERSION to package.json ..."

export FINAL_VERSION
node -e "
const fs = require('fs');
const path = './package.json';
const pkg = JSON.parse(fs.readFileSync(path, 'utf8'));
pkg.version = process.env.FINAL_VERSION;
fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + '\n');
"

echo " Version stamped!"

TICKET=$(echo "$BRANCH_NAME" | tr '[:lower:]' '[:upper:]' | grep -Eo '[A-Z]+-[0-9]+' | head -n1 || true)
TICKET="${TICKET:-MOON-000}"

echo ""
echo " Committing version bump ($TICKET) ..."

git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add package.json
git commit -m "chore($TICKET): release @moonit/sdk-evm v$FINAL_VERSION"

echo " Committed!"

echo ""
echo " Tagging release $TAG_NAME ..."

git tag "$TAG_NAME"

echo " Tagged $TAG_NAME!"

echo ""
echo " Publishing @moonit/sdk-evm@$FINAL_VERSION to npm (tag: $DIST_TAG) ..."

# Trusted Publishers on GHA -- no NPM_TOKEN needed.
npm publish --tag "$DIST_TAG" --access public

echo ""
echo " Published @moonit/sdk-evm@$FINAL_VERSION -> npm ($DIST_TAG)!"

if [[ "$BRANCH_NAME" == "main" ]]; then
echo ""
echo " Pushing version bump via PR to $BRANCH_NAME ..."

BUMP_BRANCH="chore/version-bump-sdk-evm-v${FINAL_VERSION}"
git checkout -b "$BUMP_BRANCH"
git push -u origin "$BUMP_BRANCH"
git push origin "$TAG_NAME"

echo " Pushed branch $BUMP_BRANCH!"
echo ""
echo " Creating PR to merge into $BRANCH_NAME ..."

PR_URL=$(gh pr create \
--base "$BRANCH_NAME" \
--head "$BUMP_BRANCH" \
--title "chore($TICKET): bump @moonit/sdk-evm to v$FINAL_VERSION" \
--body "$(cat <<EOF
## Auto-generated version bump

| Field | Value |
|-------|-------|
| **Package** | \`@moonit/sdk-evm\` |
| **Version** | \`$FINAL_VERSION\` |
| **npm tag** | \`$DIST_TAG\` |
| **Branch** | \`$BRANCH_NAME\` |

This PR was created automatically by the npm publish workflow.
The package has **already been published** to npm -- this PR just syncs the version bump back into \`$BRANCH_NAME\`.

> Merge when ready. No code changes, only \`package.json\` version.
EOF
)")

echo " PR created: $PR_URL"

echo ""
echo " Creating GitHub Release $TAG_NAME ..."

gh release create "$TAG_NAME" \
--title "@moonit/sdk-evm v$FINAL_VERSION" \
--generate-notes

echo " GitHub Release created!"
else
echo ""
echo " Pushing version bump to $BRANCH_NAME ..."

git push origin HEAD:"$BRANCH_NAME"
git push origin "$TAG_NAME"

echo ""
echo " Creating GitHub pre-release $TAG_NAME ..."

gh release create "$TAG_NAME" \
--title "@moonit/sdk-evm v$FINAL_VERSION" \
--prerelease \
--generate-notes

echo " GitHub pre-release created!"
fi

echo ""
echo " ========================================"
echo " ALL DONE"
echo " ========================================"
echo ""

if [[ -n "${PR_URL:-}" ]]; then
echo " Merge the version bump PR: $PR_URL"
fi
23 changes: 1 addition & 22 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,8 @@ jobs:
- name: Run linting
run: yarn lint

test:
needs: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'yarn'

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Run tests
env:
RPC_URL: ${{ secrets.RPC_URL }}
TEST_DEV_WALLET: ${{ secrets.TEST_DEV_WALLET }}
run: yarn test

build:
needs: test
needs: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: NPM Publish

on:
workflow_dispatch:
inputs:
version:
description: Required on main branch (e.g. 1.2.3)
required: false

permissions:
contents: write
id-token: write
pull-requests: write

jobs:
publish:
if: github.actor != 'github-actions[bot]'
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '24'
cache: 'yarn'
registry-url: 'https://registry.npmjs.org'

# Node 24 is required for trusted publishers (npm >= 10.9).
# The app itself may target an older version -- ignore engine checks.
- name: Install dependencies
run: yarn install --frozen-lockfile --ignore-engines

- name: Build and publish
shell: bash
env:
INPUT_VERSION: ${{ inputs.version }}
BRANCH_NAME: ${{ github.ref_name }}
GH_TOKEN: ${{ github.token }}
run: .github/scripts/npm-publish.sh
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "@moonit/sdk-evm",
"version": "0.0.1",
"version": "0.0.2-alpha.1770755050",
"main": "dist/index.js",
"types": "dist/types/index.d.ts",
"scripts": {
"build": "tsc -p tsconfig.build.json",
"watch": "tsc --watch",
"test": "jest",
"lint": "eslint 'src/**/*.{js,ts}'",
"format": "prettier --write 'src/**/*.{js,ts,json,md}'"
"format": "prettier --write 'src/**/*.{js,ts,json,md}'",
"prepublishOnly": "rm -rf dist && npm run build"
},
"repository": "git@github.com:@gomoonit/moonit-sdk-evm",
"repository": "https://github.com/gomoonit/moonit-sdk-evm",
"author": "support@moonshot.cc",
"license": "MIT",
"devDependencies": {
Expand Down