From a7db89ff4f09898d4f5e0848610802ef75931c4b Mon Sep 17 00:00:00 2001 From: louwie17 Date: Thu, 13 May 2021 09:26:12 -0300 Subject: [PATCH] Add dry run option for the release script (https://github.com/woocommerce/woocommerce-admin/pull/6946) * Added dry run option and clean between core and plugin builds * Add safety so I will not accidently start a release * Change return to exit and update plugin release name on dry run * Updated some of the logging * Made use of git --dry-run and hub --noop * Add dry run to add as well * Removed dry-run command, updated log --- plugins/woocommerce-admin/README.md | 1 + .../woocommerce-admin/bin/build-plugin-zip.sh | 19 ++++++- .../woocommerce-admin/bin/github-deploy.sh | 52 ++++++++++++------- 3 files changed, 50 insertions(+), 22 deletions(-) diff --git a/plugins/woocommerce-admin/README.md b/plugins/woocommerce-admin/README.md index 61bf551919d..625b2676202 100644 --- a/plugins/woocommerce-admin/README.md +++ b/plugins/woocommerce-admin/README.md @@ -21,6 +21,7 @@ Now you can build the files using one of these commands: - `npm run dev` : Build a development version - `npm start` : Build a development version, watch files for changes - `npm run build:release` : Build a WordPress plugin ZIP file (`woocommerce-admin.zip` will be created in the repository root) +- `DRY_RUN=1 npm run build:release` : Builds a Wordpress plugin ZIP **without** pushing it to Github and creating a release. For more helper scripts [see here](./CONTRIBUTING.md#helper-scripts) diff --git a/plugins/woocommerce-admin/bin/build-plugin-zip.sh b/plugins/woocommerce-admin/bin/build-plugin-zip.sh index 37c695a8a85..a2622f98cac 100755 --- a/plugins/woocommerce-admin/bin/build-plugin-zip.sh +++ b/plugins/woocommerce-admin/bin/build-plugin-zip.sh @@ -40,6 +40,9 @@ warning () { } status "💃 Time to release WooCommerce Admin 🕺" +if [ $DRY_RUN ]; then + warning "This is a dry run, nothing will be pushed up to Github, it will only generate zip files." +fi warning "Please enter the version number to tag, for example, 1.0.0: " read -r VERSION @@ -108,13 +111,18 @@ status "Generating the plugin build... 👷‍♀️" # Make a Github release. status "Starting a Github release... 👷‍♀️" -./bin/github-deploy.sh ${PLUGIN_TAG} ${ZIP_FILE} +if [ $DRY_RUN ]; then + PLUGIN_ZIP_FILE="woocommerce-admin-plugin.zip" +else + PLUGIN_ZIP_FILE=$ZIP_FILE +fi +./bin/github-deploy.sh ${PLUGIN_TAG} ${PLUGIN_ZIP_FILE} if [ $IS_CUSTOM_BUILD = false ]; then # Remove ignored files to reset repository to pristine condition. Previous # test ensures that changed files abort the plugin build. status "Cleaning working directory... 🛀" - git clean -xdf + git clean -xdf -e woocommerce-admin-plugin.zip # Install PHP dependencies status "Gathering PHP dependencies... 🐿️" @@ -129,4 +137,11 @@ if [ $IS_CUSTOM_BUILD = false ]; then ./bin/github-deploy.sh ${CORE_TAG} ${ZIP_FILE} fi +if [ $DRY_RUN ]; then + output 2 "Dry run successfully finished." + echo + echo "Generated $PLUGIN_ZIP_FILE for the woocommerce-admin plugin build" + echo "Generated $ZIP_FILE for the woocommerce-admin core build" + exit; +fi success "Done. You've built WooCommerce Admin! 🎉 " diff --git a/plugins/woocommerce-admin/bin/github-deploy.sh b/plugins/woocommerce-admin/bin/github-deploy.sh index d557619618b..aa8b44185e1 100755 --- a/plugins/woocommerce-admin/bin/github-deploy.sh +++ b/plugins/woocommerce-admin/bin/github-deploy.sh @@ -51,6 +51,7 @@ if [[ $1 == '' || $2 == '' ]] exit 1 fi + printf "This script will build files and create a tag on GitHub based on your local branch." echo echo @@ -59,6 +60,9 @@ echo echo printf "The /dist/ directory will also be pushed to the tagged release." echo +if [ $DRY_RUN ]; then + output 2 "This is a dry run, only the zip will be generated." +fi echo echo "Before proceeding:" echo " • Ensure you have checked out the branch you wish to release" @@ -89,45 +93,53 @@ fi output 2 "Starting release to GitHub..." echo -# Create a release branch. BRANCH="build/${VERSION}" + +NOOP_ARG="" +DRY_RUN_ARG="" +if [ $DRY_RUN ]; then + NOOP_ARG="--noop" + DRY_RUN_ARG="--dry-run" +fi + +# Create a release branch. git checkout -b $BRANCH # Force add feature-config.php -git add includes/feature-config.php --force -git add . -git commit -m "Adding feature-config.php directory to release" --no-verify - +git add includes/feature-config.php --force $DRY_RUN_ARG +git add . $DRY_RUN_ARG +git commit -m "Adding feature-config.php directory to release" --no-verify $DRY_RUN_ARG + # Force add language files -git add languages/woocommerce-admin.pot --force -git add . -git commit -m "Adding translations to release" --no-verify - +git add languages/woocommerce-admin.pot --force $DRY_RUN_ARG +git add . $DRY_RUN_ARG +git commit -m "Adding translations to release" --no-verify $DRY_RUN_ARG + # Force add build directory and commit. -git add dist/. --force -git add . -git commit -m "Adding /dist directory to release" --no-verify - +git add dist/. --force $DRY_RUN_ARG +git add . $DRY_RUN_ARG +git commit -m "Adding /dist directory to release" --no-verify $DRY_RUN_ARG + # Force add vendor directory and commit. -git add vendor/. --force -git add . -git commit -m "Adding /vendor directory to release" --no-verify +git add vendor/. --force $DRY_RUN_ARG +git add . $DRY_RUN_ARG +git commit -m "Adding /vendor directory to release" --no-verify $DRY_RUN_ARG # Push branch upstream -git push origin $BRANCH +git push origin $BRANCH $DRY_RUN_ARG # Create the zip archive ./bin/make-zip.sh $ZIP_FILE # Create the new release. if [ $IS_PRE_RELEASE = true ]; then - hub release create -m $VERSION -m "Release of version $VERSION. See readme.txt for details." -t $BRANCH --prerelease "v${VERSION}" --attach "${ZIP_FILE}" + hub $NOOP_ARG release create -m $VERSION -m "Release of version $VERSION. See readme.txt for details." -t $BRANCH --prerelease "v${VERSION}" --attach "${ZIP_FILE}" else - hub release create -m $VERSION -m "Release of version $VERSION. See readme.txt for details." -t $BRANCH "v${VERSION}" --attach "${ZIP_FILE}" + hub $NOOP_ARG release create -m $VERSION -m "Release of version $VERSION. See readme.txt for details." -t $BRANCH "v${VERSION}" --attach "${ZIP_FILE}" fi git checkout $CURRENTBRANCH git branch -D $BRANCH -git push origin --delete $BRANCH +git push origin --delete $BRANCH $DRY_RUN_ARG output 2 "GitHub release complete."