diff --git a/plugins/woocommerce-blocks/bin/github-deploy.sh b/plugins/woocommerce-blocks/bin/github-deploy.sh old mode 100644 new mode 100755 index db108af6369..ff78abb94ae --- a/plugins/woocommerce-blocks/bin/github-deploy.sh +++ b/plugins/woocommerce-blocks/bin/github-deploy.sh @@ -3,6 +3,11 @@ RELEASER_PATH="$(pwd)" IS_PRE_RELEASE=false +# When it is set to true, the commands are just printed but not executed. +DRY_RUN_MODE=false +# When it is set to true, the commands that affect the local env are executed (e.g. git commit), while the commands that affect the remote env are not executed but just printed (e.g. git push) +SIMULATE_RELEASE_MODE=false + # Functions # Check if string contains substring is_substring() { @@ -31,6 +36,26 @@ output() { echo "$(tput setaf "$1")$2$(tput sgr0)" } +simulate() { + if $2 = true ; then + eval "$1" + else + output 3 "DRY RUN: $1" + fi +} + + +run_command() { + if $DRY_RUN_MODE = true; then + output 3 "DRY RUN: $1" + elif $SIMULATE_RELEASE_MODE = true; then + simulate "$1" $2 + else + eval "$1" + fi +} + + if ! [ -x "$(command -v hub)" ]; then echo 'Error: hub is not installed. Install from https://github.com/github/hub' >&2 exit 1 @@ -128,63 +153,64 @@ fi # Version changes output 2 "Updating version numbers in files and regenerating php autoload classmap (note pre-releases will not have the readme.txt stable tag updated)..." -source "$RELEASER_PATH/bin/version-changes.sh" +run_command "source '$RELEASER_PATH/bin/version-changes.sh'" true composer dump-autoload # remove composer.json version bump after autoload regen (we don't commit it) -git checkout -- composer.json +run_command "git checkout -- composer.json" true output 2 "Committing version change..." echo -git commit -am "Bumping version strings to new version." --no-verify -git push origin $CURRENTBRANCH +run_command "git commit -am 'Bumping version strings to new version.' --no-verify" true +run_command "git push origin $CURRENTBRANCH" false # Tag existing version for reference output 2 "Creating tag for current non-built branch on GitHub..." echo DEVTAG="v${VERSION}-dev" -git tag $DEVTAG -git push origin $DEVTAG +run_command "git tag $DEVTAG" true +run_command "git push origin $DEVTAG" false output 2 "Prepping release for GitHub..." echo # Create a release branch. BRANCH="build/${VERSION}" -git checkout -b $BRANCH + +run_command "git checkout -b $BRANCH" true # Force add build directory and commit. -git add build/. --force -git add . -git commit -m "Adding /build directory to release" --no-verify +run_command "git add build/. --force" true +run_command "git add ." true +run_command "git commit -m 'Adding /build directory to release' --no-verify" true -# Force add vendor directory and commit. -git add vendor/. --force -git add . -git commit -m "Adding /vendor directory to release" --no-verify +# # Force add vendor directory and commit. +run_command "git add vendor/. --force" true +run_command "git add ." true +run_command "git commit -m 'Adding /vendor directory to release' --no-verify" true -# Push branch upstream -git push origin $BRANCH +# # Push branch upstream +run_command "git push origin $BRANCH" false # Create the new release. if [ "$(echo "${DO_WP_DEPLOY:-n}" | tr "[:upper:]" "[:lower:]")" = "y" ]; then 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}" + run_command "hub release create -m $VERSION -m 'Release of version $VERSION. See readme.txt for details.' -t $BRANCH --prerelease 'v${VERSION}'" false else - hub release create -m $VERSION -m "Release of version $VERSION. See readme.txt for details." -t $BRANCH "v${VERSION}" + run_command "hub release create -m $VERSION -m 'Release of version $VERSION. See readme.txt for details.' -t $BRANCH 'v${VERSION}'" false fi else - git tag "v${VERSION}" - git push origin "v${VERSION}" + run_command "git tag 'v${VERSION}'" true + run_command "git push origin 'v${VERSION}'" false fi -git checkout $CURRENTBRANCH -git branch -D $BRANCH -git push origin --delete $BRANCH +run_command "git checkout $CURRENTBRANCH" true +run_command "git branch -D $BRANCH" true +run_command "git push origin --delete $BRANCH" false # regenerate classmap for development -composer dump-autoload +run_command "composer dump-autoload" false output 2 "GitHub release complete." diff --git a/plugins/woocommerce-blocks/bin/storybook-deploy.sh b/plugins/woocommerce-blocks/bin/storybook-deploy.sh new file mode 100755 index 00000000000..af98c2785aa --- /dev/null +++ b/plugins/woocommerce-blocks/bin/storybook-deploy.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +# When it is set to true, the commands are just printed but not executed. +DRY_RUN_MODE=false + +# When it is set to true, the commands that affect the local env are executed (e.g. git commit), while the commands that affect the remote env are not executed but just printed (e.g. git push) +SIMULATE_RELEASE_MODE=false + + +# Output colorized strings +# +# Color codes: +# 0 - black +# 1 - red +# 2 - green +# 3 - yellow +# 4 - blue +# 5 - magenta +# 6 - cian +# 7 - white +output() { + echo "$(tput setaf "$1")$2$(tput sgr0)" +} + + +simulate() { + if $2 = true ; then + eval "$1" + else + output 3 "DRY RUN: $1" + fi +} + + +run_command() { + if $DRY_RUN_MODE = true; then + output 3 "DRY RUN: $1" + elif $SIMULATE_RELEASE_MODE = true; then + simulate "$1" $2 + else + eval "$1" + fi +} + + +run_command "rimraf ./storybook/dist/*" true +run_command "npm run storybook:build" true +run_command "gh-pages -d ./storybook/dist" false diff --git a/plugins/woocommerce-blocks/bin/wordpress-deploy.sh b/plugins/woocommerce-blocks/bin/wordpress-deploy.sh index 7d0639b1fe1..5b24807f010 100644 --- a/plugins/woocommerce-blocks/bin/wordpress-deploy.sh +++ b/plugins/woocommerce-blocks/bin/wordpress-deploy.sh @@ -7,6 +7,12 @@ GITHUB_SLUG="woocommerce-gutenberg-products-block" IS_PRE_RELEASE=false BUILD_PATH="${HOME}/blocks-deployment" +# When it is set to true, the commands are just printed but not executed. +DRY_RUN_MODE=false + +# When it is set to true, the commands that affect the local env are executed (e.g. git commit), while the commands that affect the remote env are not executed but just printed (e.g. git push) +SIMULATE_RELEASE_MODE=false + # Functions # Check if string contains substring is_substring() { @@ -40,6 +46,25 @@ output_list() { echo "$(tput setaf "$1") • $2:$(tput sgr0) \"$3\"" } +simulate() { + if $2 = true ; then + eval "$1" + else + output 3 "DRY RUN: $1" + fi +} + + +run_command() { + if $DRY_RUN_MODE = true; then + output 3 "DRY RUN: $1" + elif $SIMULATE_RELEASE_MODE = true; then + simulate "$1" $2 + else + eval "$1" + fi +} + # Release script echo output 4 "BLOCKS->WordPress.org RELEASE SCRIPT" @@ -106,7 +131,7 @@ rm -rf "$GIT_PATH" # Clone GIT repository output 2 "Cloning GIT repository..." -git clone "$GIT_REPO" "$GIT_PATH" --branch "$BRANCH" --single-branch || exit "$?" +run_command "git clone '$GIT_REPO' '$GIT_PATH' --branch '$BRANCH' --single-branch || exit '$?'" true if [ ! -d "$GIT_PATH/build" ]; then output 3 "Build directory not found in tag. Aborting." @@ -122,50 +147,50 @@ fi if [ ! -d "$SVN_PATH" ]; then output 2 "No SVN directory found, fetching files..." # Checkout project without any file - svn co --depth=files "$SVN_REPO" "$SVN_PATH" + run_command "svn co --depth=files '$SVN_REPO' '$SVN_PATH'" true cd "$SVN_PATH" || exit # Fetch main directories - svn up assets branches trunk + run_command "svn up assets branches trunk" true # Fetch tags directories without content - svn up --set-depth=immediates tags + run_command "svn up --set-depth=immediates tags" true # To fetch content for a tag, use: # svn up --set-depth=infinity tags/ else # Update SVN cd "$SVN_PATH" || exit output 2 "Updating SVN..." - svn up + run_command "svn up" true fi # Copy GIT directory to trunk output 2 "Copying project files to SVN trunk..." -sh "${RELEASER_PATH}/bin/copy-plugin-files.sh" "$GIT_PATH" "$SVN_PATH/trunk" +run_command "sh '${RELEASER_PATH}/bin/copy-plugin-files.sh' '$GIT_PATH' '$SVN_PATH/trunk'" true cd "$SVN_PATH" # Update stable tag on trunk/readme.txt if [ $IS_PRE_RELEASE = false ]; then output 2 "Updating \"Stable tag\" to ${VERSION} on trunk/readme.txt..." - perl -i -pe"s/Stable tag: .*/Stable tag: ${VERSION}/" trunk/readme.txt + run_command "perl -i -pe's/Stable tag: .*/Stable tag: ${VERSION}/' trunk/readme.txt" true fi # Do the remove all deleted files -svn st | grep -v "^.[ \t]*\..*" | grep "^\!" | awk '{print $2"@"}' | xargs svn rm +run_command "svn st | grep -v '^.[ \t]*\..*' | grep '^\!' | awk '{print $2'@'}' | xargs svn rm" true # Do the add all not know files -svn st | grep -v "^.[ \t]*\..*" | grep "^?" | awk '{print $2"@"}' | xargs svn add +run_command "svn st | grep -v '^.[ \t]*\..*' | grep '^?' | awk '{print $2'@'}' | xargs svn add" true # Copy trunk to tag/$VERSION if [ ! -d "tags/${VERSION}" ]; then output 2 "Creating SVN tags/${VERSION}..." - svn cp trunk tags/"${VERSION}" + run_command "svn 'cp trunk tags/'${VERSION}''" true fi # Remove the GIT directory output 2 "Removing GIT directory..." -rm -rf "$GIT_PATH" +run_command "rm -rf '$GIT_PATH'" true # SVN commit messsage output 2 "Ready to commit into WordPress.org Plugin's Directory!" diff --git a/plugins/woocommerce-blocks/package.json b/plugins/woocommerce-blocks/package.json index 4ce72de9347..36abbe10b5e 100644 --- a/plugins/woocommerce-blocks/package.json +++ b/plugins/woocommerce-blocks/package.json @@ -40,7 +40,6 @@ "changelog": "node ./bin/changelog", "changelog:zenhub": "node ./bin/changelog --changelogSrcType='ZENHUB_RELEASE'", "deploy": "npm run build:deploy && sh ./bin/github-deploy.sh", - "postdeploy": "npm run storybook:deploy", "dev": "rimraf build/* && cross-env BABEL_ENV=default webpack", "labels:dry": "github-label-sync --labels ./.github/label-sync-config.json --allow-added-labels --dry-run woocommerce/woocommerce-gutenberg-products-block", "labels:sync": "github-label-sync --labels ./.github/label-sync-config.json --allow-added-labels woocommerce/woocommerce-gutenberg-products-block",