-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-package.sh
executable file
·147 lines (128 loc) · 4.02 KB
/
setup-package.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
# Usage:
# setup-package.sh -p $package_path [-t $tag]
#
# Creates a package of the unity files at the `$package_path` folder
# and will include the files form "./Assets/Samples" in the export
# under the path "Samples~" to follow unity convention.
#
# Will also preserve any git-lfs links for files to avoid
# duplicating assets in the repo.
#
# Arguments:
#
# -p $package_path - Required, path to package folder of project,
# Should be something like "./openkcc"
# [-t $tag] - Optional, tag version to checkout before building
# package. If provided, will create a new branch with
# the name pattern "release/$tag"
current_branch=$(git rev-parse --abbrev-ref HEAD)
current_sha=$(git rev-parse --verify HEAD)
previous_githooks=$(git config core.hooksPath)
if [ $# -eq 0 ]
then
show_help
exit 0
fi
show_help () {
echo "Usage:"
echo " setup-package.sh -p \$package_path [-t \$tag]"
echo ""
echo " Creates a package of the unity files at the `\$package_path` folder"
echo " and will include the files form \"$sample_path\" in the export"
echo " under the path \"Samples~\" to follow unity convention."
echo ""
echo " Will also preserve any git-lfs links for files to avoid"
echo " duplicating assets in the repo."
echo " Arguments:"
echo ""
echo " -p \$package_path - Required, path to package folder of project,"
echo " Should be something like \"./openkcc\""
echo " [-t \$tag] - Optional, tag version to checkout before building"
echo " package. If provided, will create a new branch with"
echo " the name pattern \"release/\$tag\""
}
while getopts "p:t:h" opt; do
case $opt in
p) package_path=$OPTARG ;;
t) selected_tag=$OPTARG ;;
h) show_help;exit 0 ;;
?)
echo "Invalid option: -${OPTARG}."
echo
show_help
exit 1
;;
esac
done
if [ -z "$package_path" ]
then
echo "Error: Did not provide package path (-p) argument" 1>&2
show_help
exit 1
fi
if [ ! -d "$package_path" ]
then
echo "Error: Did not find package at path: \"$package_path\"" 1>&2
fi
# Checkout specific tag if one is provided
if [ ! -z "$selected_tag" ]
then
echo "Attempting to make release for tag $selected_tag"
if git rev-parse "$selected_tag" >/dev/null 2>&1; then
# git config core.hooksPath .git/hooks
echo "Found tag $selected_tag, checking out changes"
# git checkout "$selected_tag"
else
echo "Error: Tag $selected_tag does not exist, aborting changes" 1>&2
exit 1
fi
fi
# Check if there are changes
if [ ! -z "$(git status --porcelain)" ]; then
echo "Found unstaged changes:"
git status --porcelain
echo "Will not setup package if branch has changes" 1>&2
exit 1
fi
# Move to temporary branch
exists=`git show-ref refs/heads/temp-branch`
if [ -n "$exists" ]; then
git branch -D temp-branch
fi
git checkout -b temp-branch
user_email=$(git config --global user.email)
user_name=$(git config --global user.name)
if [ -z "$user_email" ]
then
git config --global user.email "github-actions[bot]@users.noreply.github.com"
fi
if [ -z "$user_name" ]
then
git config --global user.name "github-actions[bot]"
fi
git lfs install
# Reset all other changes
git rm -rf .
git checkout HEAD -- "$package_path"
# Keep .gitattributes for lfs files
git checkout HEAD -- .gitattributes
git commit -m "Filtered for only package files"
# Move files from $package_path to root folder
git mv $package_path/* .
git commit -m "Moved files from \"$package_path/*\" to root"
# Push changes to repo if tag was provided
if [ ! -z "$selected_tag" ]
then
# Push changes to original repo
exists=`git show-ref refs/heads/release/$selected_tag`
if [ -n "$exists" ]; then
git branch -D "release/$selected_tag"
fi
git branch -m "release/$selected_tag"
git push --set-upstream origin "release/$selected_tag" --force
git config core.hooksPath "$previous_githooks"
# Cleanup any files in the repo we don't care about
git checkout . && git clean -xdf .
git checkout "$current_sha" && git checkout "$current_branch"
fi