diff --git a/.github/workflows/deploy-alpha.yml b/.github/workflows/deploy-alpha.yml index 1fb3eef..1333d62 100644 --- a/.github/workflows/deploy-alpha.yml +++ b/.github/workflows/deploy-alpha.yml @@ -61,7 +61,7 @@ jobs: - name: Run linter run: npm run lint - deploy-alpha: + check-and-bump-version: needs: lint runs-on: ubuntu-latest if: github.event.pull_request.head.repo.full_name == github.repository @@ -79,6 +79,87 @@ jobs: cache: "npm" - name: Install dependencies run: npm ci --legacy-peer-deps + - name: Check and bump version if needed + run: | + # Get current version from package.json + CURRENT_VERSION=$(node -p "require('./package.json').version") + echo "Current version: ${CURRENT_VERSION}" + + # Get latest version from NPM (just the latest published version) + LATEST_NPM_VERSION=$(npm view react-jsonschema-form-extras version 2>/dev/null || echo "0.0.0") + echo "Latest NPM version: ${LATEST_NPM_VERSION}" + + # Extract clean version from NPM version (remove prerelease suffix) + CLEAN_NPM_VERSION=$(echo "${LATEST_NPM_VERSION}" | sed 's/-.*$//') + echo "Clean NPM version: ${CLEAN_NPM_VERSION}" + + # Clean current version (remove any prerelease suffix) + CLEAN_CURRENT_VERSION=$(echo "${CURRENT_VERSION}" | sed 's/-.*$//') + echo "Clean current version: ${CLEAN_CURRENT_VERSION}" + + # Simple version comparison using Node.js + SHOULD_BUMP=$(node -e " + const current = '${CLEAN_CURRENT_VERSION}'.split('.').map(Number); + const npm = '${CLEAN_NPM_VERSION}'.split('.').map(Number); + + // Compare versions: if current <= npm, need bump + for (let i = 0; i < 3; i++) { + if (current[i] < npm[i]) { + console.log('true'); + process.exit(0); + } else if (current[i] > npm[i]) { + console.log('false'); + process.exit(0); + } + } + // Equal versions = need bump + console.log('true'); + ") + + if [ "${SHOULD_BUMP}" = "true" ]; then + echo "📦 Version bump needed" + + # Calculate next version after NPM version + NEXT_VERSION=$(node -e " + const npm = '${CLEAN_NPM_VERSION}'.split('.').map(Number); + const nextVersion = npm[0] + '.' + npm[1] + '.' + (npm[2] + 1); + console.log(nextVersion); + ") + + # Set the specific next version + npm version "${NEXT_VERSION}" --no-git-tag-version + echo "🚀 Bumped to: ${NEXT_VERSION}" + + # Commit to PR branch + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add package.json package-lock.json + git commit -m "[skip ci] 🔖 Bump version to ${NEXT_VERSION}" + git push origin ${{ github.event.pull_request.head.ref }} + + echo "✅ Version bumped and committed" + else + echo "✅ Current version is already newer than NPM" + fi + + deploy-alpha: + needs: check-and-bump-version + runs-on: ubuntu-latest + if: github.event.pull_request.head.repo.full_name == github.repository + steps: + - name: Checkout code (after version bump) + uses: actions/checkout@v4 + with: + token: ${{ secrets.GH_ACTIONS_TOKEN }} + fetch-depth: 0 + ref: ${{ github.event.pull_request.head.ref }} + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: "20" + cache: "npm" + - name: Install dependencies + run: npm ci --legacy-peer-deps - name: Build project run: npm run dist - name: Validate build output diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9e8a532..cc90795 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -33,11 +33,24 @@ jobs: exit 1 fi echo "✅ Build output validated (lib and dist folders created)" - - name: Bump version - id: bump_version + - name: Get current version + id: get_version run: | - NEW_VERSION=$(npm version patch --no-git-tag-version) - echo "new_version=${NEW_VERSION}" >> $GITHUB_ENV + CURRENT_VERSION=$(node -p "require('./package.json').version") + echo "current_version=${CURRENT_VERSION}" >> $GITHUB_ENV + echo "📦 Publishing version: ${CURRENT_VERSION}" + - name: Check if version exists on NPM + id: check_npm + run: | + CURRENT_VERSION="${{ env.current_version }}" + if npm view react-jsonschema-form-extras@${CURRENT_VERSION} version 2>/dev/null; then + echo "❌ Version ${CURRENT_VERSION} already exists on NPM" + echo "version_exists=true" >> $GITHUB_ENV + exit 1 + else + echo "✅ Version ${CURRENT_VERSION} is new, proceeding with publication" + echo "version_exists=false" >> $GITHUB_ENV + fi - name: Authenticate with NPM env: NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }} @@ -45,22 +58,12 @@ jobs: - name: Publish Release Version run: | npm publish - echo "✅ Successfully published to NPM" + echo "✅ Successfully published version ${{ env.current_version }} to NPM" env: NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }} - - name: Commit and push version bump - run: | - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git add package.json package-lock.json - git commit -m "[skip actions] bump to version ${new_version}" - git push origin master - env: - GITHUB_TOKEN: ${{ secrets.GH_ACTIONS_TOKEN }} - new_version: ${{ env.new_version }} - name: Create GitHub Release env: GH_TOKEN: ${{ secrets.GH_ACTIONS_TOKEN }} - new_version: ${{ env.new_version }} + current_version: ${{ env.current_version }} run: | - gh release create "${new_version}" --generate-notes --latest --target master + gh release create "${{ env.current_version }}" --generate-notes --latest --target master diff --git a/package-lock.json b/package-lock.json index cba2fec..eb05d20 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "react-jsonschema-form-extras", - "version": "1.0.1", + "version": "1.1.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "react-jsonschema-form-extras", - "version": "1.0.1", + "version": "1.1.2", "license": "Apache-2.0", "dependencies": { "@emotion/react": "^11.11.0", diff --git a/package.json b/package.json index 787ccd1..b1b91c2 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "Extra widgets for Mozilla's react-jsonschema-form", "private": false, "author": "mavarazy@gmail.com", - "version": "1.1.0", + "version": "1.1.2", "scripts": { "build:lib": "rimraf lib && cross-env NODE_ENV=production babel -d lib/ src/ --copy-files", "build:dist": "rimraf dist && cross-env NODE_ENV=production webpack --config webpack.config.dist.js",