11# Invoke is broken on Python 3.11
22# https://github.com/pyinvoke/invoke/issues/833#issuecomment-1293148106
33import inspect
4+ import json
45import os
56import re
67import sys
8+ from pathlib import Path
79from typing import Optional
810
911if not hasattr (inspect , "getargspec" ):
@@ -163,6 +165,7 @@ def lint(context):
163165def test_integration (
164166 context ,
165167 focus = None ,
168+ full = False ,
166169 debug = False ,
167170):
168171 clean_itest_artifacts (context )
@@ -176,13 +179,17 @@ def test_integration(
176179 focus_or_none = f"--filter { focus } " if focus else ""
177180 debug_opts = "-vv --show-all" if debug else ""
178181
182+ full = full or _is_full_ci_test ()
183+ param_full_test = "--param HTML2PDF4DOC_FULL_TEST=1" if full else ""
184+
179185 # For now, the --threads are set to 1 because running tests parallelized
180186 # will result in race conditions between Web Driver Manager downloading
181187 # ChromeDriver.
182188 itest_command = f"""
183189 lit
184190 --threads 1
185191 --param HTML2PDF4DOC_EXEC="{ html2pdf_exec } "
192+ { param_full_test }
186193 -v
187194 { debug_opts }
188195 { focus_or_none }
@@ -340,3 +347,54 @@ def test_docker(context, image: str = "html2pdf4doc:latest"):
340347 "cd tests/integration/01_hello_world && html2pdf4doc print index.html /data/output/index.pdf"
341348 ),
342349 )
350+
351+
352+ def _is_full_ci_test () -> bool :
353+ """
354+ Determine whether @full_test was requested in a GitHub CI run.
355+ Returns True if the tag is found in PR body/title or commit message.
356+ Returns False for local runs or when tag not found.
357+ """
358+ event_name = os .getenv ("GITHUB_EVENT_NAME" )
359+ event_path = os .getenv ("GITHUB_EVENT_PATH" )
360+
361+ # No GitHub env (e.g. local run)
362+ if not event_name or not event_path or not Path (event_path ).exists ():
363+ print ( # noqa: T201
364+ "[is_full_ci_test] No GitHub environment detected — running in local mode."
365+ )
366+ return False
367+
368+ try :
369+ with open (event_path , encoding = "utf-8" ) as f :
370+ event = json .load (f )
371+ except Exception as e :
372+ print ( # noqa: T201
373+ f"[is_full_ci_test] Failed to parse event file: { e } "
374+ )
375+ return False
376+
377+ tag = "@full_test"
378+
379+ # Check PR body/title
380+ if event_name == "pull_request" :
381+ pr = event .get ("pull_request" , {})
382+ body = (pr .get ("body" ) or "" ).lower ()
383+ title = (pr .get ("title" ) or "" ).lower ()
384+ if tag in body or tag in title :
385+ print ( # noqa: T201
386+ "[is_full_ci_test] Detected @full_test in PR body/title."
387+ )
388+ return True
389+
390+ # Check commit message
391+ if event_name == "push" :
392+ commit_msg = (event .get ("head_commit" , {}).get ("message" ) or "" ).lower ()
393+ if tag in commit_msg :
394+ print ( # noqa: T201
395+ "[is_full_ci_test] Detected @full_test in commit message."
396+ )
397+ return True
398+
399+ print ("[is_full_ci_test] @full_test not found." ) # noqa: T201
400+ return False
0 commit comments