[PRODENG-211] reworked version updating (#9104)

* update js-api package metadata

* cleanup

* improve script loop

* cleanup dead code

* Revert "cleanup dead code"

This reverts commit f0de08acf89cfe1dfd568b77438eff60e48ec486.

* cleanup dead code

* cleanup

* cleanup dead code

* reduce scripts

* cleanup script

* better naming

* cleanup

* minor fixes

* code improvements and fixes

* minor improvements

* fix js-api upgrades

* reusable version generator

* fix variable overwrite

* reduce code duplication

* fix version generation for build number

* cleanup
This commit is contained in:
Denys Vuika 2023-11-22 11:33:05 +00:00 committed by GitHub
parent aa05fc28b5
commit e97333aabd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 89 additions and 261 deletions

View File

@ -125,7 +125,7 @@ jobs:
- name: build libraries - name: build libraries
run: | run: |
set -u; set -u;
./scripts/update-version.sh -gnu -nextalpha|| exit 1; ./scripts/update-version.sh -gnu || exit 1;
npx nx affected:build $NX_CALCULATION_FLAGS --prod --exclude="demoshell" --skip-nx-cache npx nx affected:build $NX_CALCULATION_FLAGS --prod --exclude="demoshell" --skip-nx-cache
npx nx affected $NX_CALCULATION_FLAGS --target=pretheme npx nx affected $NX_CALCULATION_FLAGS --target=pretheme
- uses: actions/setup-node@v3 - uses: actions/setup-node@v3

View File

@ -7,10 +7,10 @@
"keywords": ["alfresco"], "keywords": ["alfresco"],
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/Alfresco/alfresco-js-api.git" "url": "https://github.com/Alfresco/alfresco-ng2-components.git"
}, },
"bugs": { "bugs": {
"url": "https://github.com/Alfresco/alfresco-js-api/issues" "url": "https://github.com/Alfresco/alfresco-ng2-components/issues"
}, },
"dependencies": { "dependencies": {
"event-emitter": "^0.3.5", "event-emitter": "^0.3.5",

View File

@ -7,6 +7,5 @@ BRANCH=${GITHUB_REF##*/}
if [[ $BRANCH =~ ^develop(-patch.*)?$ ]] if [[ $BRANCH =~ ^develop(-patch.*)?$ ]]
then then
echo "Replace NPM version with new Alpha tag" echo "Replace NPM version with new Alpha tag"
NEXT_VERSION=-nextalpha ./scripts/update-version.sh -gnu || exit 1;
./scripts/update-version.sh -gnu $NEXT_VERSION || exit 1;
fi fi

View File

@ -1,119 +0,0 @@
#!/usr/bin/env bash
set -f
# By default NEXT_VERSION is set to the current version, so we can change only the aplha suffix as well
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
NEXT_VERSION=`node -p "require('$DIR/../package.json')".version;`;
eval EXEC_PATCH=false
eval EXEC_MAJOR=false
eval EXEC_MINOR=false
eval EXEC_BETA=false
eval EXEC_ALPHA=false
show_help() {
echo "Usage: next_version.sh"
echo ""
echo "-major increase the major number and reset minor and patch"
echo "-minor increase the minor number and reset the patch number"
echo "-patch increase the patch number"
echo "-beta create beta name"
echo "-alpha create beta name"
}
major() {
EXEC_MAJOR=true
}
minor() {
EXEC_MINOR=true
}
patch() {
EXEC_PATCH=true
}
alpha() {
EXEC_ALPHA=true
}
beta() {
EXEC_BETA=true
}
while [[ $1 == -* ]]; do
case "$1" in
-h|--help|-\?) show_help; exit 0;;
-major) major; shift;;
-minor) minor; shift;;
-patch) patch; shift;;
-alpha) alpha; shift;;
-beta) beta; shift;;
-*) echo "invalid option: $1" 1>&2; show_help; exit 1;;
esac
done
if [[ "${EXEC_MINOR}" == true ]]
then
ADF_VERSION=$(npm view @alfresco/adf-core version)
NEXT_VERSION=( ${ADF_VERSION//./ } )
((NEXT_VERSION[1]++))
NEXT_VERSION[2]=0
NEXT_VERSION="${NEXT_VERSION[0]}.${NEXT_VERSION[1]}.${NEXT_VERSION[2]}"
fi
if [[ "${EXEC_MAJOR}" == true ]]
then
ADF_VERSION=$(npm view @alfresco/adf-core version)
NEXT_VERSION=( ${ADF_VERSION//./ } )
((NEXT_VERSION[0]++))
NEXT_VERSION[1]=0
NEXT_VERSION[2]=0
NEXT_VERSION="${NEXT_VERSION[0]}.${NEXT_VERSION[1]}.${NEXT_VERSION[2]}"
fi
if [[ "${EXEC_PATCH}" == true ]]
then
ADF_VERSION=$(npm view ng2-alfresco-core version)
NEXT_VERSION=( ${ADF_VERSION//./ } )
((NEXT_VERSION[2]++))
NEXT_VERSION="${NEXT_VERSION[0]}.${NEXT_VERSION[1]}.${NEXT_VERSION[2]}"
fi
if [[ "${EXEC_ALPHA}" == true ]]
then
NEXT_VERSION=${NEXT_VERSION}-${GH_BUILD_NUMBER}
fi
if [[ "${EXEC_BETA}" == true ]]
then
BETA_VERSION=$(npm view @alfresco/adf-core@beta version)
if [[ $BETA_VERSION == "" ]]; then
NEXT_BETA_VERSION=0
else
NEXT_BETA_VERSION=( ${BETA_VERSION//-beta/ } )
# to reset the beta version in case of a new release
if [[ $NEXT_VERSION != ${NEXT_BETA_VERSION[0]} ]]; then
NEXT_BETA_VERSION[1]=0
fi
if [[ ${NEXT_BETA_VERSION[1]} == "" ]]; then
NEXT_BETA_VERSION[1]=0
fi
fi
while
((NEXT_BETA_VERSION[1]++))
NPM_VIEW="npm view @alfresco/adf-core@${NEXT_VERSION}-beta${NEXT_BETA_VERSION[1]} version"
NEXT_POSSIBLE_VERSION=$(${NPM_VIEW})
[ "$NEXT_POSSIBLE_VERSION" != "" ]
do :; done
NEXT_VERSION=${NEXT_VERSION}-beta${NEXT_BETA_VERSION[1]}
fi
echo $NEXT_VERSION

View File

@ -36,8 +36,6 @@ LICENSE_GREP=`escape_for_grep "$LICENSE_ROW"`
LICENSE_README="$ROOTDIR/docs/license-info/README.md"; LICENSE_README="$ROOTDIR/docs/license-info/README.md";
LICENSE_GREP_RESULT=`grep "$LICENSE_GREP" "$LICENSE_README"`; LICENSE_GREP_RESULT=`grep "$LICENSE_GREP" "$LICENSE_README"`;
#./scripts/update-version.sh -v $VERSION
if [ -z "$LICENSE_GREP_RESULT" ]; if [ -z "$LICENSE_GREP_RESULT" ];
then then
echo -e "\e[33mAdding third party license info for version: $VERSION\e[0m" echo -e "\e[33mAdding third party license info for version: $VERSION\e[0m"

View File

@ -1,14 +1,10 @@
#!/usr/bin/env bash #!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
VERSION_IN_PACKAGE_JSON=`node -p "require('$DIR/../package.json')".version;`;
eval JS_API=true eval JS_API=false
eval GNU=false eval GNU=false
eval DIFFERENT_JS_API=false eval DIFFERENT_JS_API=false
eval AUTO=false
eval TOTAL_BUILD=true;
eval SEMANTIC="minor";
eval projects=( "cli" eval projects=( "cli"
"core" "core"
@ -23,78 +19,44 @@ eval projects=( "cli"
cd `dirname $0` cd `dirname $0`
prefix="@alfresco\/adf-"
projectslength=${#projects[@]}
show_help() { show_help() {
echo "Usage: update-version.sh" echo "Usage: update-version.sh"
echo "" echo ""
echo "-vj or -versionjsapi to use a different version of js-api" echo "-vj or -versionjsapi to use a different version of js-api"
echo "-v or -version version to update" echo "-v or -version version to update"
echo "-major increase the major number and reset minor and patch"
echo "-minor increase the minor number and reset the patch number"
echo "-patch increase the patch number"
echo "-nextalpha update next alpha version of js-api and lib automatically"
echo "-nextbeta update next beta version of js-api and lib automatically"
echo "-alpha update last alpha version of js-api and lib automatically"
echo "-beta update beta alpha version of js-api and lib automatically"
echo "-gnu for gnu" echo "-gnu for gnu"
} }
last_alpha_mode() { get_next_version() {
length=`expr $projectslength - 1` PKG_VERSION=`node -p "require('$1/package.json')".version;`;
echo "====== Auto find last ALPHA version of ${projects[${length}]} ====="
VERSION=$(npm view @alfresco/adf-${projects[${length}]}@alpha version)
echo "====== version lib ${VERSION} =====" if [[ $PKG_VERSION =~ [0-9]*\.[0-9]*\.[0-9]*-.* ]]; then
} PKG_VERSION=$PKG_VERSION
next_alpha_mode() {
# If we are creating a new alpha for a prerelease, we need to simply call it with -alpha
if [[ $VERSION_IN_PACKAGE_JSON =~ [0-9]*\.[0-9]*\.[0-9]*-.* ]]; then
SEMANTIC_PARAM="";
else else
SEMANTIC_PARAM="-${SEMANTIC}"; PKG_VERSION=( ${PKG_VERSION//./ } )
((PKG_VERSION[1]++))
PKG_VERSION[2]=0
PKG_VERSION="${PKG_VERSION[0]}.${PKG_VERSION[1]}.${PKG_VERSION[2]}"
fi fi
echo "====== Auto find next ALPHA version ===== ${SEMANTIC_PARAM} " if [[ $GH_BUILD_NUMBER != "" ]]; then
VERSION=$(./next_version.sh ${SEMANTIC_PARAM} -alpha) PKG_VERSION=$PKG_VERSION-$GH_BUILD_NUMBER
fi
echo "====== version lib ${VERSION} =====" echo $PKG_VERSION
JS_API=false
} }
next_beta_mode() { VERSION=`get_next_version $DIR/..`
echo "====== Auto find next BETA version ===== ${SEMANTIC}" JS_API_VERSION=`get_next_version $DIR/../lib/js-api/src`
VERSION=$(./next_version.sh -${SEMANTIC} -beta)
echo "====== version lib ${VERSION} =====" echo "====== New libs version: $VERSION ====="
JS_API=false echo "====== New js-api version: $VERSION ====="
}
last_beta_mode() {
echo "====== Auto find last BETA version ====="
VERSION=$(npm view @alfresco/adf-core@beta version)
echo "====== version lib ${VERSION} ====="
DIFFERENT_JS_API=true
VERSION_JS_API=$(npm view @alfresco/js-api@alpha version)
echo "====== version js-api ${DIFFERENT_JS_API} ====="
}
gnu_mode() { gnu_mode() {
echo "====== GNU MODE =====" echo "====== GNU MODE ====="
GNU=true GNU=true
} }
semantic_set() {
echo "====== semantic MODE $1 ====="
SEMANTIC=$1
}
version_change() { version_change() {
echo "====== New version $1 =====" echo "====== New version $1 ====="
VERSION=$1 VERSION=$1
@ -106,139 +68,127 @@ version_js_change() {
DIFFERENT_JS_API=true DIFFERENT_JS_API=true
} }
update_component_version() { update_library_version() {
echo "====== UPDATE PACKAGE VERSION of ${PACKAGE} to ${VERSION} version in all the package.json ======" echo "====== $1@$VERSION ======"
DESTDIR="$DIR/../lib/${1}"
cd $DESTDIR DESTDIR="$DIR/../lib/$1"
npm version --allow-same-version --no-git-tag-version --force ${VERSION} if [[ $1 == "js-api" ]]; then
cd - DESTDIR="$DESTDIR/src"
fi
cd $DESTDIR
npm version --allow-same-version --no-git-tag-version --force $VERSION
} }
update_component_dependency_version() { update_dependency_version() {
echo "====== UPDATE DEPENDENCY VERSION of .* to ~${VERSION} in ${1}======" sed "${sedi[@]}" "s/\"$1\": \".*\"/\"$1\": \">=$2\"/g" "package.json"
DESTDIR="$DIR/../lib/${1}" sed "${sedi[@]}" "s/\"$1\": \"~.*\"/\"$1\": \"~$2\"/g" "package.json"
sed "${sedi[@]}" "s/\"$1\": \"^.*\"/\"$1\": \"^$2\"/g" "package.json"
}
for (( j=0; j<${projectslength}; j++ )); update_dependencies() {
for PROJECT in ${projects[@]}
do do
PROJECT=${prefix}${projects[$j]} if [[ $PROJECT == "js-api" ]]; then
sed "${sedi[@]}" "s/\"${PROJECT}\": \".*\"/\"${PROJECT}\": \">=${VERSION}\"/g" ${DESTDIR}/package.json PROJECT="@alfresco\/$PROJECT"
sed "${sedi[@]}" "s/\"${PROJECT}\": \"~.*\"/\"${PROJECT}\": \"~${VERSION}\"/g" ${DESTDIR}/package.json echo "├─ $PROJECT@$JS_API_VERSION"
sed "${sedi[@]}" "s/\"${PROJECT}\": \"^.*\"/\"${PROJECT}\": \"^${VERSION}\"/g" ${DESTDIR}/package.json update_dependency_version $PROJECT $JS_API_VERSION
else
PROJECT="@alfresco\/adf-$PROJECT"
echo "├─ $PROJECT@$VERSION"
update_dependency_version $PROJECT $VERSION
fi
done done
} }
update_total_build_dependency_version() { update_library_dependencies() {
echo "====== UPDATE TOTAL BUILD DEPENDENCY VERSION of .* to ~${VERSION} ======" DESTDIR="$DIR/../lib/$1"
DESTDIR="$DIR/../"
for (( j=0; j<${projectslength}; j++ )); if [[ $1 == "js-api" ]]; then
do DESTDIR="$DESTDIR/src"
PROJECT=${prefix}${projects[$j]} fi
sed "${sedi[@]}" "s/\"${PROJECT}\": \".*\"/\"${PROJECT}\": \">=${VERSION}\"/g" ${DESTDIR}/package.json
sed "${sedi[@]}" "s/\"${PROJECT}\": \"~.*\"/\"${PROJECT}\": \"~${VERSION}\"/g" ${DESTDIR}/package.json cd $DESTDIR
sed "${sedi[@]}" "s/\"${PROJECT}\": \"^.*\"/\"${PROJECT}\": \"^${VERSION}\"/g" ${DESTDIR}/package.json update_dependencies
done
} }
update_total_build_dependency_js_version(){ update_root_dependencies() {
echo "====== UPDATE DEPENDENCY VERSION @alfresco/js-api total build to ~${1} in ${DESTDIR}======" echo "====== Root package.json ======"
DESTDIR="$DIR/../" DESTDIR="$DIR/../"
PACKAGETOCHANGE="@alfresco\/js-api" cd $DESTDIR
update_dependencies
}
sed "${sedi[@]}" "s/\"${PACKAGETOCHANGE}\": \".*\"/\"${PACKAGETOCHANGE}\": \">=${1}\"/g" ${DESTDIR}/package.json update_root_js_api_version(){
sed "${sedi[@]}" "s/\"${PACKAGETOCHANGE}\": \"~.*\"/\"${PACKAGETOCHANGE}\": \"~${1}\"/g" ${DESTDIR}/package.json echo "====== $DESTDIR/@alfresco/js-api@$1 ======"
sed "${sedi[@]}" "s/\"${PACKAGETOCHANGE}\": \"^.*\"/\"${PACKAGETOCHANGE}\": \"^${1}\"/g" ${DESTDIR}/package.json DESTDIR="$DIR/../"
cd $DESTDIR
update_dependency_version "@alfresco\/js-api" $1
} }
update_component_js_version(){ update_component_js_version(){
echo "====== UPDATE DEPENDENCY VERSION of @alfresco/js-api in ${1} to ${2} ======" echo "====== $1/@alfresco/js-api@$2 ======"
DESTDIR="$DIR/../lib/${1}" DESTDIR="$DIR/../lib/$1"
cd $DESTDIR
PACKAGETOCHANGE="@alfresco\/js-api" update_dependency_version "@alfresco\/js-api" $2
sed "${sedi[@]}" "s/\"${PACKAGETOCHANGE}\": \".*\"/\"${PACKAGETOCHANGE}\": \">=${2}\"/g" ${DESTDIR}/package.json
sed "${sedi[@]}" "s/\"${PACKAGETOCHANGE}\": \"~.*\"/\"${PACKAGETOCHANGE}\": \"~${2}\"/g" ${DESTDIR}/package.json
sed "${sedi[@]}" "s/\"${PACKAGETOCHANGE}\": \"^.*\"/\"${PACKAGETOCHANGE}\": \"^${2}\"/g" ${DESTDIR}/package.json
} }
args=("$@")
while [[ $1 == -* ]]; do
case "$1" in
-major) semantic_set "major"; shift;;
-minor) semantic_set "minor"; shift;;
-patch) semantic_set "patch"; shift;;
-*) shift;;
esac
done
set -- "${args[@]}"
while [[ $1 == -* ]]; do while [[ $1 == -* ]]; do
case "$1" in case "$1" in
-h|--help|-\?) show_help; exit 0;; -h|--help|-\?) show_help; exit 0;;
-v|version) version_change $2; shift 2;; -v|version) version_change $2; shift 2;;
-sj|sjsapi) skip_js; shift;;
-vj|versionjsapi) version_js_change $2; shift 2;; -vj|versionjsapi) version_js_change $2; shift 2;;
-gnu) gnu_mode; shift;; -gnu) gnu_mode; shift;;
-alpha) last_alpha_mode; shift;;
-nextalpha) next_alpha_mode; shift;; -nextalpha) next_alpha_mode; shift;;
-beta) last_beta_mode; shift;;
-nextbeta) next_beta_mode; shift;;
-*) shift;; -*) shift;;
esac esac
done done
if $GNU; then if $GNU; then
sedi='-i' sedi='-i'
else else
sedi=('-i' '') sedi=('-i' '')
fi fi
if [[ "${VERSION}" == "" ]] if [[ "${VERSION}" == "" ]]
then then
echo "Version number required" echo "Version number required"
exit 1 exit 1
fi fi
cd "$DIR/../" cd "$DIR/../"
echo "====== UPDATE COMPONENTS ======" echo "====== UPDATE COMPONENTS ======"
# use for loop to read all values and indexes for PROJECT in ${projects[@]}
for (( i=0; i<${projectslength}; i++ ));
do do
echo "====== UPDATE COMPONENT ${projects[$i]} ======" update_library_version $PROJECT
update_component_version ${projects[$i]} update_library_dependencies $PROJECT
update_component_dependency_version ${projects[$i]}
if $JS_API == true; then if $JS_API == true; then
if $DIFFERENT_JS_API == true; then
if $DIFFERENT_JS_API == true; then update_component_js_version $PROJECT $VERSION_JS_API
update_component_js_version ${projects[$i]} ${VERSION_JS_API} else
else update_component_js_version $PROJECT $VERSION
update_component_js_version ${projects[$i]} ${VERSION} fi
fi fi
fi
done done
update_total_build_dependency_version update_root_dependencies
if $JS_API == true; then if $JS_API == true; then
if $DIFFERENT_JS_API == true; then if $DIFFERENT_JS_API == true; then
update_total_build_dependency_js_version ${VERSION_JS_API} update_root_js_api_version $VERSION_JS_API
else else
update_total_build_dependency_js_version ${VERSION} update_root_js_api_version $VERSION
fi fi
fi fi
# bump root package.json
npm version --allow-same-version --no-git-tag-version --force $VERSION
echo "====== UPDATE DEMO SHELL ======" echo "====== UPDATE DEMO SHELL ======"
DESTDIR="$DIR/../demo-shell/" DESTDIR="$DIR/../demo-shell/"
npm version --allow-same-version --no-git-tag-version --force ${VERSION}
cd $DESTDIR cd $DESTDIR
npm version --allow-same-version --no-git-tag-version --force ${VERSION} npm version --allow-same-version --no-git-tag-version --force $VERSION
cd -