-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsplit.sh
executable file
·79 lines (67 loc) · 3.06 KB
/
split.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env bash
set -exuo pipefail
# check if gh is installed
if ! command -v gh &> /dev/null
then
echo -e "\033[31m[ERROR] gh is not installed\033[0m"
exit 1
fi
#check if GH_TOKEN is set
if [ -z "${GH_TOKEN}" ]; then
echo -e "\033[31m[ERROR] GH_TOKEN is not set\033[0m"
exit 1
fi
# go through all packages
packages=$(ls packages/)
# if first parameter is set, we only want to split this package
if [ $# -gt 0 ]; then
packages=$1
# check if directory exists
if [ ! -d "packages/${packages}" ]; then
echo -e "\033[31m[ERROR] Package ${packages} does not exist\033[0m"
exit 1
fi
fi
commitMessage=$(git log -1 --pretty=format:"%s | %an <%ae> | %ad | https://github.com/andersundsehr/grumphp-config/commit/%H" --date=iso --no-show-signature)
mkdir -p tmp/
function printToSummary() {
echo -e "\033[33m$1\033[0m"
if [ ! -z ${GITHUB_STEP_SUMMARY+x} ]; then
echo "$1" >> $GITHUB_STEP_SUMMARY
fi
}
# set author for git
# only set if not present
git config --global user.email || git config --global user.email "[email protected]"
git config --global user.name || git config --global user.name "Automated Splitter"
for package in $packages ; do
echo -e "\033[36m[INFO] ${package} started\033[0m"
rm -rf tmp/${package}/
git clone https://${GH_TOKEN}@github.com/andersundsehr/${package}.git tmp/${package}/
rsync -acv --delete --exclude='.git' --exclude-from=packages/${package}/.gitignore --exclude-from=.gitignore packages/${package}/ tmp/${package}/
git -C tmp/${package}/ add .
# if there is nothing to commit we can skip the commit and push
if [ -z "$(git -C tmp/${package}/ status --porcelain)" ]; then
# color yellow
printToSummary "🟡 Nothing to commit for \`${package}\` https://github.com/andersundsehr/${package}"
else
git -C tmp/${package}/ commit -m "${commitMessage}"
git -C tmp/${package}/ push --follow-tags
printToSummary "✅ Pushed to remote \`${package}\` https://github.com/andersundsehr/${package}"
fi
currentMonoRepoTag=$(git tag --points-at HEAD)
if [ ! -z "$currentMonoRepoTag" ]; then
# only if the current package commit doesn't have a tag
packageCommitTag=$(git -C tmp/${package}/ tag --points-at HEAD)
commitHash=$(git -C tmp/${package}/ rev-parse HEAD)
if [ ! -z "$packageCommitTag" ]; then
commit=$(git -C tmp/${package}/ rev-parse HEAD)
printToSummary "🦘 skip tag \`${currentMonoRepoTag}\` for \`${package}\` as the current package commit \`${commitHash}\` already has the tag \`${packageCommitTag}\` https://github.com/andersundsehr/${package}/releases/tag/${packageCommitTag}"
else
git -C tmp/${package}/ tag -e -f -a $currentMonoRepoTag -m "See more at https://github.com/andersundsehr/grumphp-config/releases/tag/${currentMonoRepoTag}" --no-edit
git -C tmp/${package}/ push --tags
GH_REPO=andersundsehr/${package} gh release create $currentMonoRepoTag --notes-from-tag --verify-tag
printToSummary "✅ Published \`${package}:${currentMonoRepoTag}\` https://github.com/andersundsehr/${package}/releases/tag/${currentMonoRepoTag}"
fi
fi
done