Skip to content

Commit

Permalink
Merge pull request #5202 from WalletConnect/feat/auto-publish
Browse files Browse the repository at this point in the history
feat: auto publish to npm
  • Loading branch information
ganchoradkov authored Sep 5, 2024
2 parents df36918 + 1b7e183 commit 89abd5c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Publish to NPM
on:
release:
types: [created]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"
- name: Install dependencies and build 🔧
run: npm ci && npm run build
- name: Publish package on NPM 📦
run: npm run npm-publish:latest
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"test:ignoreUnhandled": "npm run test:ignoreUnhandled --workspaces --if-present",
"check": "npm run lint; npm run build; npm run test",
"reset": "npm run clean; npm run check",
"new-version": "lerna version --no-private --no-git-tag-version --exact && ./scripts/update_relayer_sdk_version.sh",
"new-version": "lerna version --no-private --no-git-tag-version --exact && ./scripts/update_relayer_sdk_version.sh && ./scripts/update_web3wallet_version.sh && npm i",
"pre-publish": "npm run new-version; npm run reset",
"npm-publish:rc": "lerna exec --no-private -- npm publish --access public --tag rc",
"npm-publish:latest": "lerna exec --no-private -- npm publish --access public --tag latest",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@walletconnect/web3wallet",
"description": "Web3Wallet for WalletConnect Protocol",
"version": "1.14.2",
"private": true,
"private": false,
"author": "WalletConnect, Inc. <walletconnect.com>",
"homepage": "https://github.com/walletconnect/walletconnect-monorepo/",
"license": "Apache-2.0",
Expand Down
33 changes: 33 additions & 0 deletions scripts/update_web3wallet_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
# Context: https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
set -Eeuo pipefail

file_location="packages/web3wallet/package.json"

# Get the next version from lerna.json.
lerna_file="lerna.json"
lerna_version=$(grep -E '"version": "(.*)"' $lerna_file | sed -E 's/"version": "(.*)"/\1/' | sed 's/^[[:space:]]*//')

IFS='.' read -r -a VERSION_PARTS <<< "$lerna_version"
MAJOR_VERSION=${VERSION_PARTS[0]}
MINOR_VERSION=${VERSION_PARTS[1]}
PATCH_VERSION=${VERSION_PARTS[2]}
echo "major version: $MAJOR_VERSION"
echo "minor version: $MINOR_VERSION"
echo "patch version: $PATCH_VERSION"

# web3wallet version is always one major & one minor version behind the lerna version
next_web3wallet_version="$((MAJOR_VERSION - 1)).$((MINOR_VERSION - 1)).$PATCH_VERSION"

echo "[SCRIPT] Updating Web3wallet version to $next_web3wallet_version in $file_location..."
# Use sed to update the value in the file
if [ "$(uname)" = "Darwin" ]; then
# MacOS requires an empty string as the second argument to -i
sed -i '' -E "s/\"version\": \"[^\"]+\"/\"version\": \"$next_web3wallet_version\"/" "$file_location"
else
sed -i -E "s/\"version\": \"[^\"]+\"/\"version\": \"$next_web3wallet_version\"/" "$file_location"
fi

echo "[SCRIPT] Version updated to $next_web3wallet_version in $file_location"

echo "[SCRIPT] ...Done!"

0 comments on commit 89abd5c

Please sign in to comment.