-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathpost_action.bash
54 lines (51 loc) · 1.59 KB
/
post_action.bash
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
#!/usr/bin/env bash
# need the following min environment to run this script
# WORKSPACE_PATH
# SCHEME_NAME
if [[ -n $SCHEME_ACTION_NAME ]]; then
currentSeconds=$(date +%s)
else
currentSeconds=0 # not wait newer script generate
fi
# exec &>/tmp/a.log
if [[ -z $WORKSPACE_PATH ]]; then
echo "you should run this script in xcode post build action or provide WORKSPACE_PATH and SCHEME_NAME environment"
exit 2
fi
if [[ -z $SRCROOT ]]; then
if [[ $WORKSPACE_PATH == *xcodeproj/project.xcworkspace ]]; then
cd "$WORKSPACE_PATH"/../..
else
cd "$WORKSPACE_PATH"/..
fi
SRCROOT=$(pwd)
else
cd "$SRCROOT"
fi
if [[ -n $INDEX_DATA_STORE_DIR ]]; then
ROOT="$INDEX_DATA_STORE_DIR"/../..
else
ROOT=$(xcodebuild -showBuildSettings -workspace "$WORKSPACE_PATH" -scheme "$SCHEME_NAME" 2>/dev/null | grep "\bBUILD_DIR =" | head -1 | awk '{print $3}' | tr -d '"')/../..
fi
GeneratePath="buildServer.json"
if (( currentSeconds != 0 )); then
# xcode may delay generate log file, wait it for a while
ManifestPath="$ROOT"/Logs/Build/LogStoreManifest.plist
function validElapsedTime() {
lastModificationSeconds=$(date -r "$ManifestPath" "+%s")
(( lastModificationSeconds > currentSeconds - 60 ))
}
for (( i = 0; i < 10; i++ )); do
if [[ $ManifestPath -nt $GeneratePath ]] && validElapsedTime; then
break
fi
sleep 1
done
if (( i == 10 )); then
echo "no newer $ManifestPath generate in 10 seconds, abort"
exit 3
fi
fi
echo pwd: $(pwd)
xcode-build-server parse -as "$ROOT"
touch "$GeneratePath"