-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sh
executable file
·129 lines (107 loc) · 3.17 KB
/
build.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
#!/bin/bash -e
DEFAULT_BRANCH=master
USER_EMAIL="[email protected]"
USER_NAME="nextcloud-command"
COMMIT_MESSAGE="Update OCP"
PUSH_REPOSITORY="https://${GITHUB_TOKEN}@github.com/nextcloud-deps/ocp.git"
# Setup the git configuration for creating commits and tags
init_git() {
echo "Init git"
git config user.email "$USER_EMAIL"
git config user.name "$USER_NAME"
# Only add if needed
git remote show 2>&1 | grep push-origin || \
git remote add push-origin "$PUSH_REPOSITORY"
}
# Detect local changes
# Return 0 if changes are detected, 1 otherwise
detect_changes() {
echo "Detecting changes"
echo ""
git diff --cached --name-only
echo ""
if git diff --cached --quiet HEAD --; then
echo -e "\033[1;35m🏳️ No changes detected\033[0m"
return 1
fi
echo -e "\033[1;33m🛠️ Changes detected\033[0m"
echo ""
}
# Create and push a new commit with updated sources
create_commit() {
set -x
git commit -a -m "$COMMIT_MESSAGE"
git push --set-upstream push-origin
set +x
}
# create and push a new tag (argument 1)
create_tag() {
echo "Creating tag v$1"
if ! [[ "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.*)?$ ]]; then
echo "Aborting: Tag $1 looks invalid"
return 1
fi
set -x
git tag "v$1"
git push push-origin "v$1"
set +x
}
# Update sources from the server repository
update_sources() {
rm -rf OCP
cp -r server/lib/public OCP
git add OCP
if [ -d server/lib/unstable ]; then
rm -rf NCU
cp -r server/lib/unstable NCU
git add NCU
fi
}
# Check current branch, fallback to default
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if ! [[ "$CURRENT_BRANCH" =~ ^(stable[1-9][0-9]+|master|main)$ ]]; then
CURRENT_BRANCH="$DEFAULT_BRANCH"
fi
echo "Updating OCP from branch: $CURRENT_BRANCH"
echo ""
# Load server repository
[ -d server ] && rm -rf server
echo "git clone --depth 1 --branch $CURRENT_BRANCH https://github.com/nextcloud/server.git"
git clone --depth 1 --branch "$CURRENT_BRANCH" https://github.com/nextcloud/server.git
echo ""
# Print last commit
pushd server
git log
echo ""
popd
# Init git user and push remote
init_git
# Handle tags if we are on a stable branch
if [[ "$CURRENT_BRANCH" =~ stable([0-9]+) ]]; then
CURRENT_MAJOR=${BASH_REMATCH[1]}
OCP_TAGS=$(git ls-remote --tags origin | grep -Po "(?<=refs/tags/v)$CURRENT_MAJOR\.\d\.\d$" || echo "")
pushd server
NC_TAGS=$(git ls-remote --tags origin | grep -Po "(?<=refs/tags/v)$CURRENT_MAJOR\.\d\.\d$" || echo "")
popd
MISSING_TAGS=$(comm -13 <(echo "$OCP_TAGS" | sort) <(echo "$NC_TAGS" | sort))
for tag in $MISSING_TAGS; do
echo -e "\nDetected missing tag: v$tag\n-----------------------"
pushd server
git fetch --depth 1 origin "refs/tags/v$tag"
git checkout -q FETCH_HEAD
popd
update_sources
detect_changes && create_commit
create_tag "$tag"
echo -e "-----------------------\n\n"
done
# Reset to latest commit
pushd server
git checkout -q "$CURRENT_BRANCH"
popd
fi
# Update OCP
update_sources
detect_changes && create_commit
# cleanup
rm -rf server