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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
# -*- python -*-
# kukuri BuildBot master - runs on 192.168.3.110 (budget: 512MB RAM / 3GB disk)
# Required environment (via /etc/kukuri-buildbot.env or exported):
# WORKER_PASS = <shared worker secret> (must match worker side)
# Git authentication: uses .git-credentials (credential.helper store) to avoid
# leaking password into sourcestamps/build URLs.
import os
from buildbot.plugins import *
def _load_env_file(path='/etc/kukuri-buildbot.env'):
data = {}
try:
for line in open(path):
line = line.strip()
if not line or line.startswith('#') or '=' not in line:
continue
k, v = line.split('=', 1)
data.setdefault(k, v)
except FileNotFoundError:
pass
return data
_ENVFILE = _load_env_file()
WPASS = os.environ.get('WORKER_PASS') or _ENVFILE.get('WORKER_PASS')
if not WPASS:
raise SystemExit('Set WORKER_PASS (env or /etc/kukuri-buildbot.env)')
REPO = 'http://192.168.3.110/git/kukuri.git'
ENV = {'GRADLE_USER_HOME': '/var/jenkins_home/.gradle'}
c = BuildmasterConfig = {}
c['buildbotNetUsageData'] = None
c['title'] = 'kukuri'
c['titleURL'] = 'http://192.168.3.110/cgit/cgit.cgi/kukuri.git/'
c['buildbotURL'] = 'http://192.168.3.110:8010/'
c['workers'] = [worker.Worker('lan-builder', WPASS)]
c['protocols'] = {'pb': {'port': 9989}}
c['change_source'] = [
changes.GitPoller(
REPO,
branch='main',
pollInterval=30,
pollAtLaunch=True,
)
]
factory = util.BuildFactory()
factory.addStep(steps.ShellCommand(
name='setup-git-auth',
command=['bash', '-c', '''
mkdir -p "$HOME"
echo "http://ketsuban:$(cat /run/secrets/git_pass)@192.168.3.110" > "$HOME/.git-credentials"
chmod 600 "$HOME/.git-credentials"
git config --global credential.helper store
'''],
env=ENV, haltOnFailure=True))
factory.addStep(steps.Git(repourl=REPO, mode='full', method='clean'))
factory.addStep(steps.ShellCommand(
name='detekt-gate', command=['./gradlew', ':modules:orgflow-domain:detekt'], env=ENV, haltOnFailure=True))
factory.addStep(steps.ShellCommand(
name='assemble', command=['./gradlew', 'assemble'], env=ENV, haltOnFailure=True))
factory.addStep(steps.ShellCommand(
name='jvm-tests', command=['./gradlew', 'jvmTest'], env=ENV, haltOnFailure=True))
factory.addStep(steps.ShellCommand(
name='android-tests', command=['./gradlew', 'testDebugUnitTest', 'testReleaseUnitTest'],
env=ENV, haltOnFailure=True))
factory.addStep(steps.ShellCommand(
name='wasm-tests', command=['./gradlew', 'wasmJsNodeTest'], env=ENV, haltOnFailure=True))
factory.addStep(steps.ShellCommand(
name='native-tests', command=['./gradlew', 'linuxX64Test'], env=ENV, haltOnFailure=True))
factory.addStep(steps.ShellCommand(
name='bundles',
command=['./gradlew', 'bundleDesktop', 'bundleWasm', 'bundleNative', 'bundleWeb', 'bundleApk'],
env=ENV, haltOnFailure=True))
# Wait for the GitHub Actions "ios" workflow to finish for this exact commit,
# then pull its "kukuri-ios" artifact so deploy ships it alongside the rest.
factory.addStep(steps.ShellCommand(
name='wait-github-ios',
command=['bash', '-c', '''
set -e
REPO="ketsuban152/kukuri"
TOKEN="Authorization: Bearer $(cat /run/secrets/github_token)"
SHA=$(git rev-parse HEAD)
DEADLINE=$(( $(date +%s) + 2400 ))
while [ "$(date +%s)" -lt "$DEADLINE" ]; do
RES=$(curl -sf -H "$TOKEN" "https://api.github.com/repos/$REPO/actions/runs?head_sha=$SHA" | python3 -c '
import json,sys
rs=[r for r in json.load(sys.stdin).get("workflow_runs",[]) if r.get("name")=="ios"]
if rs: print(rs[0]["id"], rs[0]["status"], rs[0].get("conclusion") or "")
' || true)
if [ -n "$RES" ]; then
set -- $RES
if [ "$2" = "completed" ]; then
if [ "$3" = "success" ]; then echo "ios run $1: success"; exit 0; fi
echo "ios run $1 finished with conclusion: $3"; exit 1
fi
echo "ios run $1: $2..."
else
echo "no ios run for $SHA yet..."
fi
sleep 20
done
echo "timeout waiting for the ios run"; exit 1
'''],
env=ENV, haltOnFailure=True, timeout=2700))
factory.addStep(steps.ShellCommand(
name='fetch-github-ios',
command=['bash', '-c', '''
set -e
REPO="ketsuban152/kukuri"
TOKEN="Authorization: Bearer $(cat /run/secrets/github_token)"
SHA=$(git rev-parse HEAD)
RUN=$(curl -sf -H "$TOKEN" "https://api.github.com/repos/$REPO/actions/runs?head_sha=$SHA" | python3 -c '
import json,sys
rs=[r for r in json.load(sys.stdin).get("workflow_runs",[]) if r.get("name")=="ios" and r.get("conclusion")=="success"]
print(rs[0]["id"])
')
URL=$(curl -sf -H "$TOKEN" "https://api.github.com/repos/$REPO/actions/runs/$RUN/artifacts" | python3 -c '
import json,sys
a=[x for x in json.load(sys.stdin)["artifacts"] if x["name"]=="kukuri-ios"]
print(a[0]["archive_download_url"])
')
curl -sfL -H "$TOKEN" -o /tmp/kukuri-ios.zip "$URL"
DIST=modules/orgflow-domain/build/distributions
V=$(ls "$DIST"/kukuri-wasm-web-*.zip | sed "s/.*-\([0-9][^/]*\)\.zip/\1/")
cp /tmp/kukuri-ios.zip "$DIST/kukuri-ios-$V.zip"
echo "staged: $DIST/kukuri-ios-$V.zip"
'''],
env=ENV, haltOnFailure=True))
factory.addStep(steps.ShellCommand(
name='deploy-to-lighttpd',
command=['bash', '-c', '''
set -e
PW=$(cat /run/secrets/git_pass)
echo "machine 192.168.3.110 login ketsuban password $PW" > /tmp/curl-netrc
chmod 600 /tmp/curl-netrc
BASE="ftp://192.168.3.110/var/www/html/artifact/kukuri/latest"
mkdir -p webout
unzip -o -q modules/orgflow-domain/build/distributions/kukuri-wasm-web-*.zip -d webout
for f in modules/orgflow-domain/build/distributions/*.zip; do
curl -sf --netrc-file /tmp/curl-netrc --ftp-create-dirs -T "$f" "$BASE/$(basename "$f")"
done
for f in modules/orgflow-domain/build/distributions/*.apk; do
curl -sf --netrc-file /tmp/curl-netrc --ftp-create-dirs -T "$f" "$BASE/$(basename "$f")"
done
for f in webout/*; do
curl -sf --netrc-file /tmp/curl-netrc --ftp-create-dirs -T "$f" "$BASE/web/$(basename "$f")"
done
rm -f /tmp/curl-netrc
echo "deployed to http://192.168.3.110/artifact/kukuri/latest/"
'''],
env=ENV, haltOnFailure=True))
c['schedulers'] = [
schedulers.SingleBranchScheduler(
name='kukuri-main',
change_filter=util.ChangeFilter(branch='main'),
treeStableTimer=5,
builderNames=['kukuri-build'],
),
schedulers.ForceScheduler(
name='force',
builderNames=['kukuri-build'],
),
]
c['builders'] = [
util.BuilderConfig(
name='kukuri-build',
workernames=['lan-builder'],
factory=factory,
)
]
c['www'] = dict(port=8010,
plugins=dict(waterfall_view=True, console_view=True, grid_view=True))
c['db'] = {'db_url': 'sqlite:///state.sqlite3'}
|