Skip to content

Commit f249d1e

Browse files
committed
Add test suite to build images for all supported UE releases
1 parent 4c0491c commit f249d1e

File tree

3 files changed

+194
-2
lines changed

3 files changed

+194
-2
lines changed

src/ue4docker/clean.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import argparse, subprocess, sys
1+
import argparse, itertools, subprocess, sys
22
from .infrastructure import *
33

44

@@ -11,7 +11,9 @@ def _isIntermediateImage(image):
1111
def _cleanMatching(cleaner, filter, tag, dryRun):
1212
tagSuffix = ":{}".format(tag) if tag is not None else "*"
1313
matching = DockerUtils.listImages(tagFilter=filter + tagSuffix)
14-
cleaner.cleanMultiple([image.tags[0] for image in matching], dryRun)
14+
cleaner.cleanMultiple(
15+
itertools.chain.from_iterable([image.tags for image in matching]), dryRun
16+
)
1517

1618

1719
def clean():

test-suite/credentials/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
username.txt
2+
password.txt

test-suite/test-ue-releases.py

+188
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
#!/usr/bin/env python3
2+
import argparse, os, platform, subprocess, sys, traceback
3+
from pathlib import Path
4+
5+
try:
6+
import colorama
7+
from termcolor import colored
8+
except:
9+
print(
10+
"Error: could not import colorama and termcolor! Make sure you install ue4-docker at least once before running the test suite."
11+
)
12+
sys.exit(1)
13+
14+
15+
class UERelease:
16+
def __init__(
17+
self, name: str, tag: str, repo: str, vsVersion: int, ubuntuVersion: str
18+
) -> None:
19+
self.name = name
20+
self.tag = tag
21+
self.repo = repo
22+
self.vsVersion = vsVersion
23+
self.ubuntuVersion = ubuntuVersion
24+
25+
26+
# Older releases have broken tags in the upstream Unreal Engine repository, so we use a fork with the updated `Commit.gitdeps.xml` files
27+
UPSTREAM_REPO = "https://github.com/EpicGames/UnrealEngine.git"
28+
COMMITDEPS_REPO = "https://github.com/adamrehn/UnrealEngine.git"
29+
30+
# The list of Unreal Engine releases that are currently supported by ue4-docker
31+
SUPPORTED_RELEASES = [
32+
UERelease("4.22", "4.22.3-fixed", COMMITDEPS_REPO, 2017, None),
33+
UERelease("4.23", "4.23.1-fixed", COMMITDEPS_REPO, 2017, None),
34+
UERelease("4.24", "4.24.3-fixed", COMMITDEPS_REPO, 2017, None),
35+
UERelease("4.25", "4.25.4-fixed", COMMITDEPS_REPO, 2017, None),
36+
UERelease("4.26", "4.26.2-fixed", COMMITDEPS_REPO, 2017, None),
37+
UERelease("4.27", "4.27.2-fixed", COMMITDEPS_REPO, 2017, None),
38+
UERelease("5.0", "5.0.3-fixed", COMMITDEPS_REPO, 2019, "20.04"),
39+
UERelease("5.1", "5.1.1-fixed", COMMITDEPS_REPO, 2019, None),
40+
UERelease("5.2", "5.2.1-release", UPSTREAM_REPO, 2022, None),
41+
UERelease("5.3", "5.3.2-release", UPSTREAM_REPO, 2022, None),
42+
]
43+
44+
45+
# Logs a message with the specified colour, making it bold to distinguish it from `ue4-docker build` log output
46+
def log(message: str, colour: str):
47+
print(colored(message, color=colour, attrs=["bold"]), file=sys.stderr, flush=True)
48+
49+
50+
# Logs a command and runs it
51+
def run(dryRun: bool, command: str, **kwargs: dict) -> subprocess.CompletedProcess:
52+
log(command, colour="green")
53+
if not dryRun:
54+
return subprocess.run(command, **{"check": True, **kwargs})
55+
else:
56+
return subprocess.CompletedProcess(command, 0)
57+
58+
59+
# Runs our tests for the specified Unreal Engine release
60+
def testRelease(
61+
release: UERelease, username: str, token: str, keepImages: bool, dryRun: bool
62+
) -> None:
63+
64+
# Pass the supplied credentials to the build process via environment variables
65+
environment = {
66+
**os.environ,
67+
"UE4DOCKER_USERNAME": username,
68+
"UE4DOCKER_PASSWORD": token,
69+
}
70+
71+
# Generate the command to build the ue4-minimal image (and its dependencies) for the specified Unreal Engine release
72+
command = [
73+
sys.executable,
74+
"-m",
75+
"ue4docker",
76+
"build",
77+
"--ue-version",
78+
f"custom:{release.name}",
79+
"-repo",
80+
release.repo,
81+
"-branch",
82+
release.tag,
83+
"--target",
84+
"minimal",
85+
]
86+
87+
# Apply any platform-specific flags
88+
if platform.system() == "Windows":
89+
command += ["--visual-studio", release.vsVersion]
90+
elif release.ubuntuVersion is not None:
91+
command += ["-basetag", f"ubuntu{release.ubuntuVersion}"]
92+
93+
# Attempt to run the build
94+
run(
95+
dryRun,
96+
command,
97+
env=environment,
98+
)
99+
100+
# Unless requested otherwise, remove the built images to free up disk space
101+
if not keepImages:
102+
run(
103+
dryRun,
104+
[
105+
sys.executable,
106+
"-m",
107+
"ue4docker",
108+
"clean",
109+
"-tag",
110+
release.name,
111+
"--all",
112+
"--prune",
113+
"--dry-run",
114+
],
115+
)
116+
117+
118+
if __name__ == "__main__":
119+
120+
try:
121+
# Initialise coloured log output under Windows
122+
colorama.init()
123+
124+
# Resolve the paths to our input directories
125+
testDir = Path(__file__).parent
126+
credentialsDir = testDir / "credentials"
127+
repoRoot = testDir.parent
128+
129+
# Parse our command-line arguments
130+
parser = argparse.ArgumentParser()
131+
parser.add_argument(
132+
"--releases",
133+
default=None,
134+
help="Run tests for the specified Unreal Engine releases (comma-delimited, defaults to all supported releases)",
135+
)
136+
parser.add_argument(
137+
"--keep-images",
138+
action="store_true",
139+
help="Don't remove images after they are built (uses more disk space)",
140+
)
141+
parser.add_argument(
142+
"--dry-run",
143+
action="store_true",
144+
help="Print commands instead of running them",
145+
)
146+
args = parser.parse_args()
147+
148+
# Parse and validate the specified list of releases
149+
if args.releases is not None:
150+
testQueue = []
151+
versions = args.releases.split(",")
152+
for version in versions:
153+
found = [r for r in SUPPORTED_RELEASES if r.name == version]
154+
if len(found) == 1:
155+
testQueue.append(found[0])
156+
else:
157+
raise RuntimeError(f'unsupported Unreal Engine release "{version}"')
158+
else:
159+
testQueue = SUPPORTED_RELEASES
160+
161+
# Read the GitHub username from the credentials directory
162+
usernameFile = credentialsDir / "username.txt"
163+
if usernameFile.exists():
164+
username = usernameFile.read_text("utf-8").strip()
165+
else:
166+
raise RuntimeError(f"place GitHub username in the file {str(usernameFile)}")
167+
168+
# Read the GitHub Personal Access Token (PAT) from the credentials directory
169+
tokenFile = credentialsDir / "password.txt"
170+
if tokenFile.exists():
171+
token = tokenFile.read_text("utf-8").strip()
172+
else:
173+
raise RuntimeError(
174+
f"place GitHub Personal Access Token (PAT) in the file {str(tokenFile)}"
175+
)
176+
177+
# Ensure any local changes to ue4-docker are installed
178+
run(
179+
args.dry_run,
180+
[sys.executable, "-m", "pip", "install", "--user", str(repoRoot)],
181+
)
182+
183+
# Run the tests for each of the selected Unreal Engine releases
184+
for release in testQueue:
185+
testRelease(release, username, token, args.keep_images, args.dry_run)
186+
187+
except Exception as e:
188+
log(traceback.format_exc(), colour="red")

0 commit comments

Comments
 (0)