Skip to content

Commit 2f98f46

Browse files
committed
GitHub actions improvements
1 parent f6741bb commit 2f98f46

File tree

3 files changed

+57
-41
lines changed

3 files changed

+57
-41
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
branches: [ main ]
88

99
env:
10-
graalvm_version: '26-ea'
10+
graalvm_version: '25'
1111

1212
jobs:
1313
# This is done as one single separate step to work around rate limits for the API
@@ -28,7 +28,10 @@ jobs:
2828

2929
- name: Set Maven Bundle URL
3030
id: set_url
31-
run: echo "maven_bundle_url=$(./scripts/maven-bundle-url.sh | tail -n 1)" >> $GITHUB_OUTPUT
31+
run: |
32+
tmp_file="$(mktemp)"
33+
./scripts/maven-bundle-url.sh | tee "$tmp_file"
34+
echo "maven_bundle_url=$(tail -n 1 "$tmp_file")" >> $GITHUB_OUTPUT
3235
shell: bash
3336

3437
pre_commit:
@@ -184,19 +187,23 @@ jobs:
184187
if: runner.os == 'Windows'
185188
run: echo "C:\Program Files\Git\usr\bin" >> $env:GITHUB_PATH
186189

190+
# We scrape the output of integration tests for paths to interesting log files,
191+
# so that we can then upload them in the following actions/upload-artifact
187192
- name: Run integration tests
193+
id: tests_run
188194
run: |
189195
mvn --batch-mode -s settings.xml -Dgradle.java.home=$GRADLE_JAVA_HOME exec:java@integration-tests -Dintegration.tests.args="${{ matrix.test_name }} ${{ matrix.extra_test_args }} $TEST_FLAGS"
190196
shell: bash
191197

198+
# /var/folders/sw/**/T/jbang*native-image
199+
# ^ not using this path on MacOS, because it causes
192200
- name: Upload JBang native-image log
193201
if: failure()
194202
uses: actions/upload-artifact@v4
195203
with:
196204
name: jbang-native-image-log
197205
path: |
198206
/tmp/jbang*native-image
199-
/var/folders/sw/**/T/jbang*native-image
200207
201208
unit-tests:
202209
needs: [build, maven_bundle_url]

integration-tests/run.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@
7070
print("WARNING: JAVA_HOME not in environment.\n")
7171
if args.native_image != 'none':
7272
suffix = '.exe' if sys.platform == 'win32' else ''
73-
if not os.path.exists(os.path.join(os.environ['JAVA_HOME'], 'bin', 'native-image' + suffix)):
74-
print("WARNING: JAVA_HOME is not a GraalVM distribution. Tests using Native Image will fail.\n")
73+
ni_file = os.path.join(os.environ['JAVA_HOME'], 'bin', 'native-image' + suffix)
74+
if not os.path.exists(ni_file):
75+
print(f"WARNING: JAVA_HOME is not a GraalVM distribution. Tests using Native Image will fail. File does not exist: {ni_file}\n")
7576

7677
util.graalvmVersion = args.graalpy_version
7778
util.long_running_test_disabled = args.skip_long_running

integration-tests/test_jbang_integration.py

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,15 @@
5454
ENV = os.environ.copy()
5555
USE_SHELL = 'win32' == sys.platform
5656

57-
def run_cmd(cmd, cwd=None):
58-
print(f"\nExecuting: {cmd=}")
57+
def run_cmd(cmd, log:util.LoggerBase, cwd=None):
58+
log.log(f"\nExecuting: {cmd=}")
5959
env = os.environ.copy()
6060
env['GRAALPY_VERSION'] = util.jbang_graalpy_version
6161
process = subprocess.Popen(cmd, cwd=cwd, env=env, shell=USE_SHELL, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, text=True, errors='backslashreplace')
62-
out = []
63-
print("============== output =============")
64-
for line in iter(process.stdout.readline, ""):
65-
print(line, end="")
66-
out.append(line)
67-
print("========== end of output ==========")
68-
return "".join(out), process.wait()
62+
out = process.stdout.read()
63+
# TODO: check for [jbang\] \[.*\] log:\s*\S+ and add its contents to the logger
64+
log.log_block("Output", out)
65+
return out, process.wait()
6966

7067
class TestJBangIntegration(unittest.TestCase):
7168

@@ -93,7 +90,10 @@ def tearDown(self):
9390
@staticmethod
9491
def clearCache():
9592
command = JBANG_CMD + ["cache", "clear"]
96-
run_cmd(command)
93+
log = util.Logger()
94+
_, res = run_cmd(command, log=log)
95+
if res != 0:
96+
print(f"WARNING: could not clear JBang cache:\n{log}")
9797

9898
@staticmethod
9999
def getCatalogFile():
@@ -141,17 +141,18 @@ def prepare_template(self, template, target):
141141

142142
def test_register_catalog(self):
143143
alias = "graalpy_test_catalog_" + str(int(time.time()))
144+
log = util.Logger()
144145

145146
# jbang checks catalog file sanity when adding
146147
command = JBANG_CMD + ["catalog", "add", "--name", alias, self.catalog_file]
147-
out, result = run_cmd(command, cwd=WORK_DIR)
148+
out, result = run_cmd(command, log=log, cwd=WORK_DIR)
148149
if result != 0:
149-
self.fail(f"Problem during registering catalog")
150+
self.fail(f"Problem during registering catalog. \n" + str(log))
150151

151152
command = JBANG_CMD + ["catalog", "remove", alias]
152-
out, result = run_cmd(command, cwd=WORK_DIR)
153+
out, result = run_cmd(command, log=log, cwd=WORK_DIR)
153154
if result != 0:
154-
self.fail(f"Problem during removing catalog")
155+
self.fail(f"Problem during removing catalog. \n" + str(log))
155156

156157
def test_catalog(self):
157158
json_data = self.getCatalogData(self.catalog_file)
@@ -169,20 +170,21 @@ def test_graalpy_template(self):
169170
template_name = "graalpy"
170171
test_file = "graalpy_test.java"
171172
work_dir = self.tmpdir
173+
log = util.Logger()
172174

173175
command = JBANG_CMD + ["init", f"--template={template_name}@{self.catalog_file}" , test_file]
174-
out, result = run_cmd(command, cwd=work_dir)
175-
self.assertTrue(result == 0, f"Creating template {template_name} failed")
176+
out, result = run_cmd(command, log=log, cwd=work_dir)
177+
self.assertTrue(result == 0, f"Creating template {template_name} failed.\n{log}")
176178

177179
test_file_path = os.path.join(work_dir, test_file)
178180
self.addLocalMavenRepo(test_file_path)
179181
tested_code = "from termcolor import colored; print(colored('hello java', 'red', attrs=['reverse', 'blink']))"
180182
command = JBANG_CMD + [ test_file_path, tested_code]
181-
out, result = run_cmd(command, cwd=work_dir)
183+
out, result = run_cmd(command, log=log, cwd=work_dir)
182184

183-
self.assertTrue(result == 0, f"Execution failed with code {result}\n command: {command}\n stdout: {out}\n")
184-
self.assertIn("Successfully installed termcolor", out)
185-
self.assertIn("hello java", out)
185+
self.assertTrue(result == 0, f"Execution failed with code {result}\n{log}")
186+
self.assertIn("Successfully installed termcolor", out, log)
187+
self.assertIn("hello java", out, log)
186188

187189
@unittest.skipUnless('win32' not in sys.platform, "Currently the jbang native image on Win gate fails.")
188190
def test_graalpy_template_native(self):
@@ -192,16 +194,17 @@ def test_graalpy_template_native(self):
192194
template_name = "graalpy"
193195
test_file = "graalpy_test.java"
194196
work_dir = self.tmpdir
197+
log = util.Logger()
195198

196199
command = JBANG_CMD + ["init", f"--template={template_name}@{self.catalog_file}" , test_file]
197-
out, result = run_cmd(command, cwd=work_dir)
200+
out, result = run_cmd(command, log=log, cwd=work_dir)
198201
self.assertTrue(result == 0, f"Creating template {template_name} failed")
199202

200203
test_file_path = os.path.join(work_dir, test_file)
201204
self.addLocalMavenRepo(test_file_path)
202205
tested_code = "from termcolor import colored; print(colored('hello java', 'red', attrs=['reverse', 'blink']))"
203206
command = JBANG_CMD + ["--native", test_file_path, tested_code]
204-
out, result = run_cmd(command, cwd=work_dir)
207+
out, result = run_cmd(command, log=log, cwd=work_dir)
205208

206209
self.assertEqual(0, result, f"command: {command}\n stdout: {out}")
207210
self.assertIn("Successfully installed termcolor", out)
@@ -210,18 +213,19 @@ def test_graalpy_template_native(self):
210213
def test_hello_example(self):
211214
work_dir = self.tmpdir
212215
hello_java_file = self.prepare_hello_example(work_dir)
216+
log = util.Logger()
213217

214218
tested_code = "print('hello java')"
215219
command = JBANG_CMD + [hello_java_file, tested_code]
216-
out, result = run_cmd(command, cwd=work_dir)
220+
out, result = run_cmd(command, log=log, cwd=work_dir)
217221

218222
self.assertEqual(0, result, f"command: {command}\n stdout: {out}")
219223
self.assertIn("Successfully installed termcolor", out)
220224
self.assertIn("hello java", out)
221225

222226
if not 'win32' in sys.platform and util.native_image_smoke():
223227
command = JBANG_CMD + ["--native", hello_java_file, tested_code]
224-
out, result = run_cmd(command, cwd=work_dir)
228+
out, result = run_cmd(command, log=log, cwd=work_dir)
225229

226230
self.assertEqual(0, result, f"command: {command}\n stdout: {out}")
227231
self.assertIn("Successfully installed termcolor", out)
@@ -231,6 +235,7 @@ def test_hello_example(self):
231235
def test_external_dir(self):
232236
work_dir = self.tmpdir
233237
hello_java_file = self.prepare_hello_example(work_dir)
238+
log = util.Logger()
234239

235240
# patch hello.java file to use external dir for resources
236241
resources_dir = os.path.join(work_dir, "python-resources")
@@ -252,7 +257,7 @@ def hello():
252257

253258
tested_code = "import hello; hello.hello()"
254259
command = JBANG_CMD + [hello_java_file, tested_code]
255-
out, result = run_cmd(command, cwd=work_dir)
260+
out, result = run_cmd(command, log=log, cwd=work_dir)
256261

257262
self.assertEqual(0, result, f"command: {command}\n stdout: {out}")
258263
self.assertIn("Successfully installed termcolor", out)
@@ -264,7 +269,7 @@ def hello():
264269
"//PIP termcolor==2.2 ujson")
265270
tested_code = "import hello; hello.hello()"
266271
command = JBANG_CMD + [hello_java_file, tested_code]
267-
out, result = run_cmd(command, cwd=work_dir)
272+
out, result = run_cmd(command, log=log, cwd=work_dir)
268273

269274
self.assertEqual(0, result, f"command: {command}\n stdout: {out}")
270275
self.assertIn("Successfully installed ujson", out)
@@ -277,7 +282,7 @@ def hello():
277282
"//PIP termcolor==2.2\n")
278283
tested_code = "import hello; hello.hello()"
279284
command = JBANG_CMD + [hello_java_file, tested_code]
280-
out, result = run_cmd(command, cwd=work_dir)
285+
out, result = run_cmd(command, log=log, cwd=work_dir)
281286

282287
self.assertEqual(0, result, f"command: {command}\n stdout: {out}")
283288
self.assertNotIn("ujson", out)
@@ -290,7 +295,7 @@ def hello():
290295
"//PIP termcolor==2.2\n//PIP ujson")
291296
tested_code = "import hello; hello.hello()"
292297
command = JBANG_CMD + [hello_java_file, tested_code]
293-
out, result = run_cmd(command, cwd=work_dir)
298+
out, result = run_cmd(command, log=log, cwd=work_dir)
294299

295300
self.assertEqual(0, result, f"command: {command}\n stdout: {out}")
296301
self.assertIn("Successfully installed ujson", out)
@@ -299,43 +304,45 @@ def hello():
299304

300305
if not 'win32' in sys.platform and util.native_image_all():
301306
command = JBANG_CMD + ["--native", hello_java_file, tested_code]
302-
out, result = run_cmd(command, cwd=work_dir)
307+
out, result = run_cmd(command, log=log, cwd=work_dir)
303308

304309
self.assertEqual(0, result, f"command: {command}\n stdout: {out}")
305310
self.assertNotIn("Successfully installed ujson", out)
306311
self.assertNotIn("Successfully installed termcolor", out)
307312
self.assertIn("hello java", out)
308313

309-
def check_empty_comments(self, work_dir, java_file):
314+
def check_empty_comments(self, work_dir, java_file, log):
310315
command = JBANG_CMD + [java_file]
311-
out, result = run_cmd(command, cwd=work_dir)
316+
out, result = run_cmd(command, log=log, cwd=work_dir)
312317
self.assertEqual(0, result, f"command: {command}\n stdout: {out}")
313318
self.assertNotIn("[graalpy jbang integration]", out)
314319

315320
def test_malformed_tag_formats(self):
316321
jbang_templates_dir = os.path.join(os.path.dirname(__file__), "jbang")
317322
work_dir = self.tmpdir
323+
log = util.Logger()
318324

319325
java_file = os.path.join(work_dir, "EmptyPIPComments.java")
320326
self.prepare_template(os.path.join(jbang_templates_dir, "EmptyPIPComments.j"), java_file)
321-
self.check_empty_comments(work_dir, java_file)
327+
self.check_empty_comments(work_dir, java_file, log=log)
322328

323329
java_file = os.path.join(work_dir, "EmptyPythonResourceComment.java")
324330
self.prepare_template(os.path.join(jbang_templates_dir, "EmptyPythonResourceComment.j"), java_file)
325-
self.check_empty_comments(work_dir, java_file)
331+
self.check_empty_comments(work_dir, java_file, log=log)
326332

327333
java_file = os.path.join(work_dir, "EmptyPythonResourceCommentWithBlanks.java")
328334
self.prepare_template(os.path.join(jbang_templates_dir, "EmptyPythonResourceCommentWithBlanks.j"), java_file)
329-
self.check_empty_comments(work_dir, java_file)
335+
self.check_empty_comments(work_dir, java_file, log=log)
330336

331337
def test_no_pkgs_but_resource_dir(self):
332338
jbang_templates_dir = os.path.join(os.path.dirname(__file__), "jbang")
333339
work_dir = self.tmpdir
340+
log = util.Logger()
334341

335342
java_file = os.path.join(work_dir, "NoPackagesResourcesDir.java")
336343
self.prepare_template(os.path.join(jbang_templates_dir, "NoPackagesResourcesDir.j"), java_file)
337344
command = JBANG_CMD + [java_file]
338-
out, result = run_cmd(command, cwd=work_dir)
345+
out, result = run_cmd(command, log=log, cwd=work_dir)
339346
self.assertEqual(0, result, f"command: {command}\n stdout: {out}")
340347
self.assertNotIn("[graalpy jbang integration] python packages", out)
341348
self.assertIn("[graalpy jbang integration] python resources directory: python-resources", out)
@@ -345,10 +352,11 @@ def test_no_pkgs_but_resource_dir(self):
345352
def test_two_resource_dirs(self):
346353
jbang_templates_dir = os.path.join(os.path.dirname(__file__), "jbang")
347354
work_dir = self.tmpdir
355+
log = util.Logger()
348356

349357
java_file = os.path.join(work_dir, "TwoPythonResourceComments.java")
350358
self.prepare_template(os.path.join(jbang_templates_dir, "TwoPythonResourceComments.j"), java_file)
351359
command = JBANG_CMD + [java_file]
352-
out, result = run_cmd(command, cwd=work_dir)
360+
out, result = run_cmd(command, log=log, cwd=work_dir)
353361
self.assertEqual(1, result, f"command: {command}\n stdout: {out}")
354362
self.assertIn("only one //PYTHON_RESOURCES_DIRECTORY comment is allowed", out)

0 commit comments

Comments
 (0)