Skip to content

Commit 26b5337

Browse files
authored
Merge pull request #4190 from tgross35/backport-ci-artifacts
[0.2] Backports
2 parents abe73ab + 4344e54 commit 26b5337

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

Diff for: .github/workflows/ci.yaml

+20
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,23 @@ jobs:
9797
- uses: Swatinem/rust-cache@v2
9898
with:
9999
key: ${{ matrix.target }}
100+
100101
- name: Run natively
101102
if: "!matrix.docker"
102103
run: ./ci/run.sh ${{ matrix.target }}
103104
- name: Run in Docker
104105
if: "matrix.docker"
105106
run: ./ci/run-docker.sh ${{ matrix.target }}
106107

108+
- name: Create CI artifacts
109+
if: always()
110+
run: ./ci/create-artifacts.py
111+
- uses: actions/upload-artifact@v4
112+
with:
113+
name: ${{ env.ARCHIVE_NAME }}-${{ matrix.target }}
114+
path: ${{ env.ARCHIVE_PATH }}
115+
retention-days: 5
116+
107117
test_tier2:
108118
name: Test tier2
109119
needs: [test_tier1, style_check]
@@ -151,9 +161,19 @@ jobs:
151161
- uses: Swatinem/rust-cache@v2
152162
with:
153163
key: ${{ matrix.target }}
164+
154165
- name: Execute run-docker.sh
155166
run: ./ci/run-docker.sh ${{ matrix.target }}
156167

168+
- name: Create CI artifacts
169+
if: always()
170+
run: ./ci/create-artifacts.py
171+
- uses: actions/upload-artifact@v4
172+
with:
173+
name: ${{ env.ARCHIVE_NAME }}-${{ matrix.target }}
174+
path: ${{ env.ARCHIVE_PATH }}
175+
retention-days: 5
176+
157177
test_tier2_vm:
158178
name: Test tier2 VM
159179
needs: [test_tier1, style_check]

Diff for: ci/create-artifacts.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python3
2+
"""Create a tarball of intermediate output for inspection if tests fail.
3+
4+
This is useful for seeing what exactly `ctest` is running.
5+
"""
6+
7+
import os
8+
import subprocess as sp
9+
import sys
10+
11+
from datetime import datetime, timezone
12+
from glob import glob
13+
from pathlib import Path
14+
15+
16+
def main():
17+
# Find the most recently touched file named "main.c" in the target
18+
# directory. This will be libc-tests's `OUT_DIR`
19+
marker_files = [Path(p) for p in glob("target/**/main.c", recursive=True)]
20+
marker_files.sort(key=lambda path: path.stat().st_mtime)
21+
build_dir = marker_files[0].parent
22+
print(f"Located build directory '{build_dir}'")
23+
24+
# Collect all relevant Rust and C files
25+
add_files = glob("**/*.rs", recursive=True, root_dir=build_dir)
26+
add_files += glob("**/*.c", recursive=True, root_dir=build_dir)
27+
file_list = "\n".join(add_files).encode()
28+
29+
now = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H%MZ")
30+
archive_name = f"archive-{now}"
31+
archive_path = f"{archive_name}.tar.gz"
32+
33+
sp.run(["tar", "czvf", archive_path, "-C", build_dir, "-T-"], input=file_list)
34+
35+
# If we are in GHA, set these env vars for future use
36+
gh_env = os.getenv("GITHUB_ENV")
37+
if gh_env is not None:
38+
print("Updating CI environment")
39+
with open(gh_env, "w+") as f:
40+
f.write(f"ARCHIVE_NAME={archive_name}\n")
41+
f.write(f"ARCHIVE_PATH={archive_path}\n")
42+
43+
44+
if __name__ == "__main__":
45+
# FIXME(ci): remove after the bump to windoes-2025 GHA images
46+
# Python <= 3.9 does not support the very helpful `root_dir` argument,
47+
# and that is the version used by the Windows GHA images. Rather than
48+
# using setup-python or doing something in the CI script, just find
49+
# the newer version and relaunch if this happens to be run with an old
50+
# version.
51+
try:
52+
glob("", root_dir="")
53+
except TypeError:
54+
if os.environ.get("CI") is None:
55+
sys.exit(1)
56+
57+
# Find the next 3.1x Python version
58+
dirs = sorted(list(Path(r"C:\hostedtoolcache\windows\Python").iterdir()))
59+
usepy = next(x for x in dirs if r"\3.1" in str(x))
60+
py = usepy.joinpath(r"x64\python.exe")
61+
print(f"relaunching with {py}")
62+
os.execvp(py, [__file__] + sys.argv)
63+
64+
main()

0 commit comments

Comments
 (0)