-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Upload artifacts created by libc-test
This gives us something that is easier to look at when the automatically generated tests fail.
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env python3 | ||
"""Create a tarball of intermediate output for inspection if tests fail.""" | ||
|
||
import os | ||
import subprocess as sp | ||
|
||
from datetime import datetime, timezone | ||
from glob import glob | ||
from pathlib import Path | ||
|
||
|
||
def main(): | ||
# Find the most recently touched file named "main.c" in the target | ||
# directory. This will be libc-tests's `OUT_DIR` | ||
marker_files = [Path(p) for p in glob("target/**/main.c", recursive=True)] | ||
marker_files.sort(key=lambda path: path.stat().st_mtime) | ||
build_dir = marker_files[0].parent | ||
|
||
# Collect all relevant Rust and C files | ||
add_files = glob("**/*.rs", recursive=True, root_dir=build_dir) | ||
add_files += glob("**/*.c", recursive=True, root_dir=build_dir) | ||
file_list = "\n".join(add_files).encode() | ||
|
||
now = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H%MZ") | ||
archive_name = f"archive-{now}" | ||
archive_path = f"{archive_name}.tar.gz" | ||
|
||
sp.run(["tar", "czvf", archive_path, "-C", build_dir, "-T-"], input=file_list) | ||
|
||
# If we are in GHA, set these env vars for future use | ||
gh_env = os.getenv("GITHUB_ENV") | ||
if gh_env is not None: | ||
print("Updating CI environment") | ||
with open(gh_env, "w+") as f: | ||
f.write(f"ARCHIVE_NAME={archive_name}\n") | ||
f.write(f"ARCHIVE_PATH={archive_path}\n") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |