-
Notifications
You must be signed in to change notification settings - Fork 0
/
gityomi
executable file
·115 lines (95 loc) · 2.75 KB
/
gityomi
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
#!/usr/bin/env bash
APKS_PATH=$HOME/APKS
GIT_USER=$(git config --get user.name)
GIT_BRANCH=$(git branch --show-current)
export GH_REPO=$GIT_USER/extension-builder
PROJECT=$(echo ${PWD} | rev | cut -d/ -f -2 | rev)
LANG=${PROJECT%/*}
EXT=${PROJECT##*/}
ATTEMPT="$EXT($LANG): Attempt"
# This is going to commit and push any changes
# The git log is going to be like:
# "zoro(en): Attempt #69"
# "zoro(en): Attempt #68"....
# until you use squashAttempts.
commitAttempt() {
ktlint -F **.kt
git add .
local lastCommit=$(git log -1 --pretty="%s")
if [[ $lastCommit =~ "Attempt" ]]; then
local attemptCount=$((${lastCommit##*#}+1))
git commit -m "$ATTEMPT #$attemptCount"
else
git commit -m "$ATTEMPT #1"
fi
git push origin +$GIT_BRANCH
}
getLastRunId() {
gh run list --json databaseId --jq .[0].databaseId
}
tryIt() {
if [[ $1 == "rerun" ]]; then
local run_id=$(getLastRunId)
gh run rerun $run_id
sleep 1
else
gh workflow run build_single_extension.yml \
-f lang=$LANG -f extension=$EXT -f git-ref=$GIT_BRANCH
sleep 3
local run_id=$(getLastRunId)
fi
# Install the apk if the build ends with success, else show logs
gh run watch --exit-status $run_id \
&& installArtifacts \
|| gh run view --log-failed $run_id
}
downloadArtifacts() {
gh run download -D $APKS_PATH -n "$LANG-$EXT"
}
installArtifacts() {
rm $APKS_PATH/*yomi-$LANG.$EXT-v*-debug.apk
downloadArtifacts
read -n 1 -p "Wants to install it and open aniyomi? " openit
case ${openit^^} in
Y|S)
openAniyomi
adb install $APKS_PATH/*yomi-$LANG.$EXT-v*-debug.apk
;;
*) echo -e "\nOK" ;;
esac
}
openAniyomi(){
local package="xyz.jmir.tachiyomi.mi.debug"
local activity="eu.kanade.tachiyomi.ui.main.MainActivity"
adb shell "am force-stop $package"
adb shell "am start -n $package/$activity -a eu.kanade.tachiyomi.SHOW_CATALOGUES"
}
squashAttempts() {
local hash=$(git log --pretty="%H" --reverse --grep "): Attempt #" | head -n 1)
git reset --soft ${hash}~
git commit
git push origin +$GIT_BRANCH
}
help() {
cat <<EOF
try|build ->
Commit attempt, push to remote and run workflow.
if it fails, it will show failed logs
else, it will download and install the artifacts.
You can disable the commit attempt by putting [nocommit] after it
You can make it rerun a workflow by putting [rerun] after it
down|get ->
Will download the artifacts from the last workflow run.
commit|squash ->
Merge/squash commit attempts into one and push to remote
EOF
}
case "$1" in
try|build)
[[ ! "$@" =~ "nocommit" ]] && commitAttempt
[[ ! "$@" =~ "rerun" ]] && tryIt || tryIt rerun
;;
commit|squash) squashAttempts;;
down|get) downloadArtifacts;;
*) help;;
esac