forked from OpenBEL/bel-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repo-ize
executable file
·76 lines (67 loc) · 2.05 KB
/
repo-ize
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
#!/usr/bin/env bash
REQ_EXECS=( "mvn" "zip" )
# Check for executables in PATH
for REQ_EXEC in "${REQ_EXECS[@]}"; do
if [ -z "$(which ${REQ_EXEC} 2>/dev/null)" ]; then
echo "No ${REQ_EXEC} in PATH."
exit 1
fi
done
if [ -z "${BRANCH}" ]; then
# Is this a git repo?
if [ ! -f ".git/HEAD" ]; then
echo "No .git/HEAD - cannot identify branch"
exit 1
fi
BRANCH="$(awk -F/ '{ print $NF }' < .git/HEAD)"
fi
DEST_FILE_NAME="${BRANCH}-repository"
DEST_FILE_EXT=".zip"
if [ ! -z "${BUILD}" ]; then
DEST_FILE_NAME="${DEST_FILE_NAME}-build${BUILD}"
fi
DEST_FILE_NAME="${DEST_FILE_NAME}${DEST_FILE_EXT}"
DEST_DIR=$(pwd)
# End result: ./unstable-repository-build1234.zip
echo -en "Will create ${DEST_FILE_NAME} in ${DEST_DIR}.\n"
echo -en "Executing mvn -q package.\n"
mvn package || exit 1
REPO="org.openbel.editor-site/target/repository"
PUBLISHER_REPO="org.openbel.editor-site/target/publisherRepository"
REQ_DIRS=( "${REPO}" \
"${PUBLISHER_REPO}" \
"${REPO}/features" \
"${REPO}/plugins" )
REQ_FILES=( "${REPO}/artifacts.jar" \
"${REPO}/content.jar" \
"${PUBLISHER_REPO}/artifacts.xml" \
"${PUBLISHER_REPO}/content.xml" )
# Sanity check we have what we need
echo -en "Running some sanity checks... "
for REQ_DIR in "${REQ_DIRS[@]}"; do
if [ ! -d "${REQ_DIR}" ]; then
echo "fail"
echo "No directory: ${REQ_DIR}"
echo "Do you need to 'mvn package'?"
exit 1
fi
done
for REQ_FILE in "${REQ_FILES[@]}"; do
if [ ! -f "${REQ_FILE}" ]; then
echo "fail"
echo "No file: ${REQ_FILE}"
exit 1
fi
done
echo "okay"
# Zip up the repo for deployment
cp "${REQ_FILES[2]}" "${REQ_FILES[3]}" "${REPO}" || exit 1
cd "${REPO}" || exit 1
if [ -f "${DEST_DIR}"/"${DEST_FILE_NAME}" ]; then
echo -en "Existing ${DEST_FILE_NAME} found. Removing it.\n"
rm "${DEST_DIR}"/"${DEST_FILE_NAME}"
fi
echo -en "Zipping... "
zip -9 -q "${DEST_DIR}"/"${DEST_FILE_NAME}" -r *
echo "done"
echo "${DEST_DIR}/${DEST_FILE_NAME} is ready"