Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 64 additions & 8 deletions xwiki-release-scripts/maven-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,43 @@ function check_versions() {
fi
}

function set_packages_version() {
if [ -z "$1" ]; then
echo "Missing version parameter" >&2
exit 1
fi

version="$1"
current_directory="$(dirname "$(readlink -f "$0")")/.."


find "$current_directory" -type d -name "node_modules" -prune -o -name "package.json" -print | \
grep -v "^$current_directory/package.json$" | \
while IFS= read -r pkg_path; do

## private or unnamed packages are skipped
is_skipped=$(jq -r '.private' "$pkg_path")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm making sure that all existing packages.json files, that are not meant to be published, are private so that this script doesn't impact the release process of LTS branches?


if [ "$is_skipped" = "true" ]; then
continue
fi

# Create a temporary file in case of issue during the version patch
temp_file=$(mktemp)

# Update the version with jq on the temp file, and replace the original file with the patch version if no
# problem was encountered.
if ! jq ".version = \"$version\"" "$pkg_path" > "$temp_file"; then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script relied on jq to manipulate json files.
This tool is currently not installed on the release machine, so there is likely something to change to make it available.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, just needs to be installed, I guess. I think it's not the first non installed by default tool we are using in this script (even if we usually try to avoid it).

relative_pkg_path=$(realpath --relative-to="$current_directory" "$pkg_path")
echo "Failed to update $relative_pkg_path: jq error" >&2
rm -f "$temp_file"
continue
fi

mv "$temp_file" "$pkg_path"
done
}

# Clean up the sources, discarding any changes in the local workspace not found in the local git clone and switching back to the master branch.
function pre_cleanup() {
echo -e "\033[0;32m* Cleaning up\033[0m"
Expand Down Expand Up @@ -274,19 +311,27 @@ function create_release_branch() {
CURRENT_VERSION=`mvn help:evaluate -Dexpression='project.version' -N | grep -v '\[' | grep -v 'Download' | cut -d- -f1`
}

function pre_update_versions() {
echo -e "\033[0;32m* Preparing project for release\033[0m"
pre_update_parent_versions
pre_update_packages_versions
git add pom.xml
git commit -m "[release] Preparing release ${TAG_NAME}" -q
}

# Update the root project's parent version and version variables, if needed.
# For xwiki-commons updates the value for the commons.version variable.
# For the other projects it changes the version of the parent in the current repository root pom.
# The changes will be committed as a new git version.
function pre_update_parent_versions() {
echo -e "\033[0;32m* Preparing project for release\033[0m"
mvn versions:update-parent -DgenerateBackupPoms=false -DskipResolution=true -DparentVersion=$VERSION -N -q
sed -e "s/<commons.version>.*<\/commons.version>/<commons.version>${VERSION}<\/commons.version>/" -i pom.xml
PROJECT_NAME=`mvn help:evaluate -Dexpression='project.artifactId' -N | grep -v '\[' | grep -v 'Download'`
TAG_NAME=${PROJECT_NAME}-${VERSION}
}

git add pom.xml
git commit -m "[release] Preparing release ${TAG_NAME}" -q
function pre_update_packages_versions() {
set_packages_version $VERSION
}

# Perform the actual maven release.
Expand Down Expand Up @@ -332,14 +377,18 @@ function release_maven() {
git tag -s -f -m "Tagging ${TAG_NAME}" ${TAG_NAME}
}

function post_update_versions() {
echo -e "\033[0;32m* Go back to branch ${RELEASE_BRANCH}\033[0m"
git checkout ${RELEASE_BRANCH}
post_update_parent_versions
post_update_packages_versions
}

# Update the root project's parent version and version variables, if needed.
# For xwiki-commons updates the value for the commons.version variable.
# For the other projects it changes the version of the parent in the current repository root pom.
# The changes will be committed as a new git version.
function post_update_parent_versions() {
echo -e "\033[0;32m* Go back to branch ${RELEASE_BRANCH}\033[0m"
git checkout ${RELEASE_BRANCH}

echo -e "\033[0;32m* Update parent to ${NEXT_SNAPSHOT_VERSION} after release\033[0m"
xsltproc -o pom.xml --stringparam parentversion "${NEXT_SNAPSHOT_VERSION}" $PRGDIR/set-parent-version.xslt pom.xml
echo -e "\033[0;32m* Update commons.version to ${NEXT_SNAPSHOT_VERSION} after release\033[0m"
Expand All @@ -349,6 +398,13 @@ function post_update_parent_versions() {
git commit -m "[release] Update parent after release ${TAG_NAME}" -q
}

function post_update_packages_versions() {
echo -e "\033[0;32m* Update packages to ${NEXT_SNAPSHOT_VERSION} after release\033[0m"
set_packages_version $NEXT_SNAPSHOT_VERSION
git add .
git commit -m "[release] Update packages after release ${TAG_NAME}" -q
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On LTS branches, set_packages_version will not change any file.
Therefore, git add/commit won't have side effects except for a no changes added to commit message in the log.
Sounds fine to me, but let me know if you see an issue with that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me why there is a difference between LTS branches and latest branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LTS branches don't contain packages that we want to publish on npm registries.
This new packages.json version patching is only useful for packages we want to publish.
Basically I aim to avoid noise with useless changes in LTS branches.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LTS branches don't contain packages that we want to publish on npm registries.

Well, I still don't understand why. Shouldn't we publish bugfix releases ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expressed myself badly, I don't want to have an impact on versions prior to v18.* (where I introduced the first packages we want to publish). Regardless of the branch, version 18+ will see their package versions updated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I doubt that log is a big problem, nobody is looking at it anyway :)

}

# Push changes made to the release branch (new SNAPSHOT version, etc)
function push_release() {
echo -e "\033[0;32m* Switch to release base branch\033[0m"
Expand Down Expand Up @@ -392,9 +448,9 @@ function release_project() {
if [[ $do_release == true ]]
then
create_release_branch
pre_update_parent_versions
pre_update_versions
release_maven
post_update_parent_versions
post_update_versions
push_release
post_cleanup
push_tag
Expand Down