|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -./build-dev.sh |
| 3 | +# This script is used to build and package the plugin for distribution. |
| 4 | +# It will clean up the environment, execute Composer, prefix dependencies, finalize the build, archive the build, and sign the archive. |
4 | 5 |
|
| 6 | +function trim() { |
| 7 | + local str="$*" |
| 8 | + str="${str#"${str%%[![:space:]]*}"}" |
| 9 | + str="${str%"${str##*[![:space:]]}"}" |
| 10 | + echo "${str}" |
| 11 | +} |
| 12 | + |
| 13 | +function semver { |
| 14 | + local SEMVER_REGEX='^([0-9]+\.){2}(\*|[0-9]+)(-.*)?$' |
| 15 | + local version=$(trim $1) |
| 16 | + |
| 17 | + if [[ "$version" =~ $SEMVER_REGEX ]]; then |
| 18 | + if [ "$#" -eq 2 ]; then |
| 19 | + local major=${BASH_REMATCH[0]} |
| 20 | + local minor=${BASH_REMATCH[1]} |
| 21 | + local patch=${BASH_REMATCH[2]} |
| 22 | + local suffix=${BASH_REMATCH[3]} |
| 23 | + eval "$2=(\"$major\" \"$minor\" \"$patch\" \"$suffix\")" |
| 24 | + fi |
| 25 | + else |
| 26 | + echo "Error: version '$version' does not match the semver 'X.Y.Z' format." |
| 27 | + exit 1 |
| 28 | + fi |
| 29 | +} |
| 30 | + |
| 31 | +printf 'What version are you building? ' |
| 32 | +read version |
| 33 | +echo "Version: $version" |
| 34 | +semver "$version" version |
| 35 | +filename="Auth0_WordPress_${version}.zip" |
| 36 | + |
| 37 | +echo "# Cleaning up environment..." |
| 38 | +rm -f build.zip |
| 39 | +rm -f build.zip.sig |
| 40 | +rm -rf build |
| 41 | +rm -rf vendor |
| 42 | +rm composer.lock |
| 43 | + |
| 44 | +echo "# Executing Composer..." |
| 45 | +composer update --no-plugins |
| 46 | + |
| 47 | +echo "# Prefixing Dependencies..." |
| 48 | +vendor/bin/php-scoper add-prefix --force |
| 49 | + |
| 50 | +echo "# Finalizing Build..." |
| 51 | +cd build |
5 | 52 | composer update --no-dev --optimize-autoloader --no-plugins |
| 53 | +rm composer.json |
| 54 | +rm composer.lock |
| 55 | +cd .. |
| 56 | + |
| 57 | +echo "# Archiving Build..." |
| 58 | +zip -vr ${filename} build/ -x "*.DS_Store" |
| 59 | + |
| 60 | +echo "# Signing Build..." |
| 61 | +openssl dgst -sign private-signing-key.pem -sha256 -out ${filename}.sig -binary ${filename} |
0 commit comments