Skip to content
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

Add an build & deploy script #238

Merged
merged 1 commit into from
Sep 10, 2024
Merged
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
69 changes: 69 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

svn_url="http://plugins.svn.wordpress.org/aftership-woocommerce-tracking"
git_url="[email protected]:AfterShip/aftership-apps-woocommerce.git"

git_tmp_dir=$(mktemp -d)
git clone $git_url $git_tmp_dir

# get version number from readme.txt
version=$(sed -n '7p' "$git_tmp_dir/readme.txt" | cut -c 13-)

echo "Version number is $version"

build_dir="../build/$version"

# if build directory exists, remove it
if [ -d "$build_dir" ]; then
rm -rf "$build_dir"
fi

mkdir -p "$build_dir"

# move all files from git to build directory
cp "$git_tmp_dir"/aftership-woocommerce-tracking.php "$build_dir"
mkdir -p "$build_dir/assets/frontend"
mkdir -p "$build_dir/assets/frontendv2"
cp -r "$git_tmp_dir"/assets/frontend/dist "$build_dir/assets/frontend"
cp -r "$git_tmp_dir"/assets/frontendv2/dist "$build_dir/assets/frontendv2"
cp -r "$git_tmp_dir"/assets/css "$build_dir/assets"
cp -r "$git_tmp_dir"/assets/js "$build_dir/assets"
cp -r "$git_tmp_dir"/assets/images "$build_dir/assets"
cp -r "$git_tmp_dir"/assets/plugin "$build_dir/assets"
cp -r "$git_tmp_dir"/assets/*.png "$build_dir/assets"
cp -r "$git_tmp_dir"/includes "$build_dir"
cp -r "$git_tmp_dir"/templates "$build_dir"
cp -r "$git_tmp_dir"/views "$build_dir"
cp -r "$git_tmp_dir"/woo-includes "$build_dir"
cp -r "$git_tmp_dir"/aftership.php "$build_dir"
cp -r "$git_tmp_dir"/aftership-woocommerce-tracking.php "$build_dir"
cp -r "$git_tmp_dir"/readme.txt "$build_dir"

# remove git temporary directory
rm -rf "$git_tmp_dir"

# check script parameters if it want to deploy to SVN
if [ "$1" != "deploy" ]; then
echo "Build completed. Run 'sh scripts/build.sh deploy' to deploy to SVN."
exit 0
fi

# deploy to SVN
svn_tmp_dir=$(mktemp -d)
svn checkout $svn_url $svn_tmp_dir

# check if already deployed to svn
if [ -d "$svn_tmp_dir/tags/$version" ]; then
echo "Version $version already exists in SVN. Please update version number in readme.txt."
exit 1
fi

rm -rf "$svn_tmp_dir/trunk/*"
mkdir -p "$svn_tmp_dir/tags/$version"

cp -r "$build_dir/*" "$svn_tmp_dir/trunk"
cp -r "$build_dir/*" "$svn_tmp_dir/tags/$version"

cd "$svn_tmp_dir" && svn add . --force && svn ci -m "Version $version" --username aftership --force-interactive

echo "Process completed."
Loading