diff --git a/.github/workflows/npm-publish.yaml b/.github/workflows/npm-publish.yaml index 845c6015..db73fe48 100644 --- a/.github/workflows/npm-publish.yaml +++ b/.github/workflows/npm-publish.yaml @@ -21,6 +21,8 @@ jobs: steps: - name: Checkout repository 🛎️ uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Set up Node.js uses: actions/setup-node@v3 @@ -31,21 +33,27 @@ jobs: - name: Install dependencies 📥 run: npm ci - - name: Make is-release-needed.sh executable - run: chmod +x ./scripts/is-release-needed.sh - - - name: Check if version number has already been released 🕵️‍♀️ - id: is-release-needed + - name: Make scripts executable run: | - echo "Checking if ${{ matrix.package }} is already published..." - IS_RELEASE_NEEDED=$(npm run is-release-needed --workspace=${{ matrix.package }} --silent) - echo "is-release-needed=$IS_RELEASE_NEEDED" - echo "is-release-needed=$IS_RELEASE_NEEDED" >> $GITHUB_OUTPUT + chmod +x ./scripts/check-release-type.sh + chmod +x ./scripts/publish-next-release.sh - - name: Publish package on NPM 📦 - if: steps.is-release-needed.outputs.is-release-needed == 'true' + - name: Check release type 🕵️‍♀️ + id: check-release run: | - npm publish --workspace=${{ matrix.package }} + RELEASE_TYPE=$(./scripts/check-release-type.sh) + echo "release-type=$RELEASE_TYPE" >> $GITHUB_OUTPUT + + - name: Publish stable version 📦 + if: steps.check-release.outputs.release-type == 'stable' + run: npm publish --workspace=${{ matrix.package }} + env: + NODE_AUTH_TOKEN: ${{ secrets.REQUEST_BOT_NPM_TOKEN }} + VITE_WEB3MODAL_PROJECT_ID: ${{ secrets.VITE_WEB3MODAL_PROJECT_ID }} + + - name: Publish next version 📦 + if: steps.check-release.outputs.release-type == 'next' + run: ./scripts/publish-next-release.sh env: NODE_AUTH_TOKEN: ${{ secrets.REQUEST_BOT_NPM_TOKEN }} VITE_WEB3MODAL_PROJECT_ID: ${{ secrets.VITE_WEB3MODAL_PROJECT_ID }} diff --git a/scripts/check-release-type.sh b/scripts/check-release-type.sh new file mode 100644 index 00000000..214cf3c5 --- /dev/null +++ b/scripts/check-release-type.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# This script checks if we need a stable or next release +PACKAGE_VERSION="$(node -p -e "require('./package.json').version")" +PACKAGE_NAME="$(node -p -e "require('./package.json').name")" + +# Check if current version exists in npm +FOUND_VERSION=$(npm view $PACKAGE_NAME versions | grep $PACKAGE_VERSION) + +if [ -z "$FOUND_VERSION" ]; then + echo 'stable' # New version in package.json, do stable release +else + # Check if there are changes since last release + git diff --quiet HEAD~1 HEAD -- . + if [ $? -eq 1 ]; then + echo "next" # Changes detected, do next release + else + echo 'none' # No changes, no release needed + fi +fi diff --git a/scripts/is-release-needed.sh b/scripts/is-release-needed.sh deleted file mode 100755 index 2fbbb5d3..00000000 --- a/scripts/is-release-needed.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -# This script checks if the current version of the package is already published on npm -PACKAGE_VERSION="$(node -p -e "require('./package.json').version")" -PACKAGE_NAME="$(node -p -e "require('./package.json').name")" - -FOUND_VERSION=$(npm view $PACKAGE_NAME versions | grep $PACKAGE_VERSION) - -if [ -z "$FOUND_VERSION" ]; then - echo 'true' # release needed -else - echo 'false' # release not needed -fi diff --git a/scripts/publish-next-release.sh b/scripts/publish-next-release.sh new file mode 100644 index 00000000..b7fe403a --- /dev/null +++ b/scripts/publish-next-release.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +PACKAGE_VERSION="$(node -p -e "require('./package.json').version")" +PACKAGE_NAME="$(node -p -e "require('./package.json').name")" + +# Increment patch version +PATCH_VERSION=$(echo $PACKAGE_VERSION | awk -F. '{print $3}') +NEW_PATCH=$((PATCH_VERSION + 1)) +BASE_VERSION=$(echo $PACKAGE_VERSION | awk -F. '{print $1"."$2".'$NEW_PATCH'"}') + +# Get latest next version number +LATEST_NEXT=$(npm view $PACKAGE_NAME dist-tags.next) + +if [ -z "$LATEST_NEXT" ]; then + # No next version exists, start at 1 + NEXT_NUMBER=1 +else + # Extract and increment the next number + CURRENT_NEXT_NUMBER=$(echo $LATEST_NEXT | grep -oE '[0-9]+$') + NEXT_NUMBER=$((CURRENT_NEXT_NUMBER + 1)) +fi + +# Update package.json with next version +npm version "${BASE_VERSION}-next.${NEXT_NUMBER}" --no-git-tag-version + +# Publish with next tag +npm publish --tag next