From 3fde9bd6027f632ccdde96818206da5feeced238 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sat, 7 Dec 2024 09:12:13 +0000 Subject: [PATCH] ci: Upload artifacts created by libc-test This gives us something that is easier to look at when the automatically generated tests fail. --- .github/workflows/ci.yaml | 20 ++++++++++++++++++++ ci/create-artifacts.py | 40 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100755 ci/create-artifacts.py diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c18cb79714fc..77746592a9be 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -96,6 +96,7 @@ jobs: - uses: Swatinem/rust-cache@v2 with: key: ${{ matrix.target }} + - name: Run natively if: "!matrix.docker" run: ./ci/run.sh ${{ matrix.target }} @@ -103,6 +104,15 @@ jobs: if: "matrix.docker" run: ./ci/run-docker.sh ${{ matrix.target }} + - name: Create CI artifacts + if: always() + run: python3.12 ci/create-artifacts.py + - uses: actions/upload-artifact@v4 + with: + name: ${{ env.ARCHIVE_NAME }} + path: ${{ env.ARCHIVE_PATH }} + retention-days: 5 + test_tier2: name: Test tier2 needs: [test_tier1, style_check] @@ -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: python3.12 ci/create-artifacts.py + - uses: actions/upload-artifact@v4 + with: + name: ${{ env.ARCHIVE_NAME }} + path: ${{ env.ARCHIVE_PATH }} + retention-days: 5 + test_tier2_vm: name: Test tier2 VM needs: [test_tier1, style_check] diff --git a/ci/create-artifacts.py b/ci/create-artifacts.py new file mode 100755 index 000000000000..b8eeba487c34 --- /dev/null +++ b/ci/create-artifacts.py @@ -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()