Skip to content

Commit

Permalink
feat(tools): add a script to print a dev version
Browse files Browse the repository at this point in the history
  • Loading branch information
jahow committed Jan 10, 2024
1 parent 2c215e8 commit 6433178
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tools/print-dev-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

# Will print a version tag taking into account the current project version and whether it's a dev version
# on main branch: 1.0.0-dev.1234abcd (commit tag)
# on feature branch: 1.0.0-dev.branch-name
# on git tag: 1.0.0 (git tag)

npmVersion=$(node --print 'require("../package.json").version')
gitTag=$(git describe --exact-match --tags 2>/dev/null | sed "s/^v//") # remove "v" in front of version if any
gitBranch=$(git symbolic-ref --short HEAD)
gitRef=$(git rev-parse --short HEAD)

# git tag defined
if [ -n "${gitTag}" ]; then
echo ${gitTag}
exit 0
fi

# main branch
if [ ${gitBranch} == "main" ]; then
echo "${npmVersion}.${gitRef}"
exit 0
fi

echo "${npmVersion}.${gitBranch}"

0 comments on commit 6433178

Please sign in to comment.