Skip to content

Instantly share code, notes, and snippets.

@rafesposo
Last active December 18, 2023 23:32
Show Gist options
  • Save rafesposo/bb8ec873dc46eb6729f9e5fab74beb4f to your computer and use it in GitHub Desktop.
Save rafesposo/bb8ec873dc46eb6729f9e5fab74beb4f to your computer and use it in GitHub Desktop.
Generate a package with the files that were modified in the last commit.
#!/bin/sh
# ==================================
# Creators: @rafesposo | @dudecussi
# Date: 2022-12-16
# Description: This script will generate a package with the files that were modified in the last commit.
# How to use: Copy this file to the .git/hooks folder and give it execution permissions.
# ==================================
branchPath=$(git symbolic-ref -q HEAD)
branch=${branchPath##*/}
commitHash=$(git rev-parse --short HEAD)
listFiles=$(git show --pretty="" --name-only $commitHash)
if [ "master" == "$branch" ]; then
echo "Generating package..."
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
zip package/$commitHash.zip $listFiles
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
echo "Creating changelog..."
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
echo "-- CHANGELOG --" >> changelog-$commitHash.txt
git show --name-only -1 >> changelog-$commitHash.txt
zip -u package/$commitHash.zip changelog-$commitHash.txt
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
echo "Package generated: package/$commitHash.zip"
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
rm changelog-$commitHash.txt
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment