Skip to content
Merged
83 changes: 82 additions & 1 deletion .github/workflows/deploy-alpha.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
37 changes: 20 additions & 17 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,37 @@ 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 }}
run: echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > ~/.npmrc
- 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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading