Skip to content

Instantly share code, notes, and snippets.

@tadhgboyle
Last active November 6, 2022 16:48
Show Gist options
  • Save tadhgboyle/fb3377a178468a34c14b8dd6567aed74 to your computer and use it in GitHub Desktop.
Save tadhgboyle/fb3377a178468a34c14b8dd6567aed74 to your computer and use it in GitHub Desktop.
rm -rf /tmp/Nameless
# clone the repo to a temp directory
echo "Cloning repo..."
git clone https://github.com/NamelessMC/Nameless.git /tmp/Nameless > /dev/null 2>&1
cd /tmp/Nameless
tag=$1
if [ ! $(git tag -l "$tag") ]; then
echo "Invalid tag '$tag'!"
exit 1
fi
git checkout $tag > /dev/null 2>&1
# get the previous tag
prevtag=$(git describe --abbrev=0 --tags $tag^)
echo "Found previous tag of '$prevtag'!"
# zip file name is the tag without periods and v
zipfile="update"$(echo $tag | sed 's/\.//g' | sed 's/\v//g')
rm -rf /tmp/$zipfile
echo "Installing assets..."
composer install > /dev/null 2>&1
yarnpkg > /dev/null 2>&1
# get the diff files and make a folder
echo "Calculating and splitting diff..."
IFS=$'\n'
for file_change in `git diff $prevtag $tag --name-only --diff-filter=d`
do
echo $file_change
done | zip -@ /tmp/$zipfile.zip > /dev/null 2>&1
# extract zip file
unzip /tmp/$zipfile.zip -d /tmp/$zipfile > /dev/null 2>&1
rm /tmp/$zipfile.zip
# copy package.json and composer.json to the root of the zip file
echo "Copying asset metadata..."
cp /tmp/Nameless/package.json /tmp/$zipfile/package.json > /dev/null 2>&1
cp /tmp/Nameless/composer.json /tmp/$zipfile/composer.json > /dev/null 2>&1
mkdir -p /tmp/$zipfile/vendor
cp -R /tmp/Nameless/vendor /tmp/$zipfile
mkdir -p /tmp/$zipfile/core/assets/vendor
cp -R /tmp/Nameless/core/assets/vendor /tmp/$zipfile/core/assets
cd /tmp/$zipfile
# zip the folder again
echo "Creating update zip..."
zip -r /tmp/$zipfile.zip ./ > /dev/null 2>&1
# delete the temp directories
echo "Deleting temp files..."
rm -rf /tmp/Nameless
rm -rf /tmp/$zipfile
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment