Bump version via node script

This commit is contained in:
adrinr 2023-04-21 14:11:21 +01:00
parent 2735f1bfc6
commit 7e271fed18
4 changed files with 62 additions and 16 deletions

View File

@ -36,4 +36,4 @@ jobs:
# setup the username and email.
git config --global user.name "Budibase Staging Release Bot"
git config --global user.email "<>"
./scripts/bumpLernaVersion.sh
./scripts/versionCommit.sh alpha

View File

@ -1,15 +0,0 @@
#!/bin/bash
# Bump the version in lerna.json
CURRENT_VERSION=$(node -p "require('./lerna.json').version")
NEW_VERSION=$(echo $CURRENT_VERSION | awk -F. -v OFS=. '{++$NF; print}')
sed -i '' "s/\"version\": \"$CURRENT_VERSION\"/\"version\": \"$NEW_VERSION\"/" lerna.json
lerna version prerelease --no-git-tag-version --force-publish --no-push --y
git add lerna.json
git commit -m "Bump version to $NEW_VERSION"
git tag v$NEW_VERSION
git push
git push --tags

43
scripts/bumpVersion.js Normal file
View File

@ -0,0 +1,43 @@
const fs = require("fs")
const filePath = "lerna.json"
const versionBump = process.argv[2] || "patch"
// Read and parse lerna.json file
const fileData = fs.readFileSync(filePath)
const lernaData = JSON.parse(fileData)
// Get current version and split into major, minor, patch, and alpha components
const currentVersion = lernaData.version
const [versionWithoutPrerelease, prerelease] = currentVersion.split("-")
const [major, minor, patch] = versionWithoutPrerelease.split(".").map(Number)
// Calculate new version based on specified version bump
let newVersion = currentVersion
switch (versionBump) {
case "major":
newVersion = `${major + 1}.0.0`
break
case "minor":
newVersion = `${major}.${minor + 1}.0`
break
case "patch":
newVersion = `${major}.${minor}.${patch + 1}`
break
case "alpha":
const newPrerelease = (prerelease || -1) + 1
newVersion = prerelease
? `${versionWithoutPrerelease}-alpha.${newPrerelease}`
: `${major}.${minor}.${patch}-alpha.${newPrerelease}`
break
default:
console.error(`Invalid version bump '${versionBump}' specified.`)
process.exit(1)
}
// Update lerna.json file with new version
lernaData.version = newVersion
const updatedData = JSON.stringify(lernaData, null, 2)
fs.writeFileSync(filePath, updatedData)
console.log(`Updated version from ${currentVersion} to ${newVersion}`)

18
scripts/versionCommit.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/bash
if [ -z "$1" ]
then
echo "Error: version number is required. Usage: $0 [major|minor|patch|alpha]"
exit 1
fi
# Bump the version in lerna.json
node scripts/bumpVersion.js $1
git add lerna.json
git commit -m "Bump version to $NEW_VERSION"
git tag v$NEW_VERSION
git push
git push --tags