Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Upload artifacts created by libc-test #4180

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,23 @@ jobs:
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}

- name: Run natively
if: "!matrix.docker"
run: ./ci/run.sh ${{ matrix.target }}
- name: Run in Docker
if: "matrix.docker"
run: ./ci/run-docker.sh ${{ matrix.target }}

- name: Create CI artifacts
if: always()
run: ./ci/create-artifacts.py
- uses: actions/upload-artifact@v4
with:
name: ${{ env.ARCHIVE_NAME }}-${{ matrix.target }}
path: ${{ env.ARCHIVE_PATH }}
retention-days: 5

test_tier2:
name: Test tier2
needs: [test_tier1, style_check]
Expand Down Expand Up @@ -150,9 +160,19 @@ jobs:
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}

- name: Execute run-docker.sh
run: ./ci/run-docker.sh ${{ matrix.target }}

- name: Create CI artifacts
if: always()
run: ./ci/create-artifacts.py
- uses: actions/upload-artifact@v4
with:
name: ${{ env.ARCHIVE_NAME }}-${{ matrix.target }}
path: ${{ env.ARCHIVE_PATH }}
retention-days: 5

test_tier2_vm:
name: Test tier2 VM
needs: [test_tier1, style_check]
Expand Down
64 changes: 64 additions & 0 deletions ci/create-artifacts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env python3
"""Create a tarball of intermediate output for inspection if tests fail.

This is useful for seeing what exactly `ctest` is running.
"""

import os
import subprocess as sp
import sys

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
print(f"Located build directory '{build_dir}'")

# 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__":
# FIXME(ci): remove after the bump to windoes-2025 GHA images
# Python <= 3.9 does not support the very helpful `root_dir` argument,
# and that is the version used by the Windows GHA images. Rather than
# using setup-python or doing something in the CI script, just find
# the newer version and relaunch if this happens to be run with an old
# version.
try:
glob("", root_dir="")
except TypeError:
if os.environ.get("CI") is None:
sys.exit(1)

# Find the next 3.1x Python version
dirs = sorted(list(Path(r"C:\hostedtoolcache\windows\Python").iterdir()))
usepy = next(x for x in dirs if r"\3.1" in str(x))
py = usepy.joinpath(r"x64\python.exe")
print(f"relaunching with {py}")
os.execvp(py, [__file__] + sys.argv)

main()
Loading