-
Notifications
You must be signed in to change notification settings - Fork 40
XINFRA-446: Support patching npm package during releases #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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") | ||
|
|
||
| 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 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The script relied on
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
|
@@ -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. | ||
|
|
@@ -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" | ||
|
|
@@ -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 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On LTS branches,
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Well, I still don't understand why. Shouldn't we publish bugfix releases ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
|
@@ -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 | ||
|
|
||
There was a problem hiding this comment.
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?