Skip to content

Update CI workflow to improve execution time #2

Update CI workflow to improve execution time

Update CI workflow to improve execution time #2

Workflow file for this run

name: CI-Time
on:
pull_request:
workflow_dispatch:
schedule:
- cron: '0 0 * * *' # Daily “At 00:00”
jobs:
test:
name: Python (${{ matrix.python-version }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash -l {0}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-latest", "macos-14", "windows-latest"]
python-version: ["3.13"]
steps:
- name: Cancel previous runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- name: checkout
uses: actions/checkout@v4
with:
token: ${{ github.token }}
# Conda
- name: conda_setup (x64)
if: matrix.os != 'macos-14'
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: uxarray_build
channel-priority: strict
python-version: ${{ matrix.python-version }}
channels: conda-forge
environment-file: ci/environment.yml
miniforge-variant: Miniforge3
miniforge-version: latest
- name: conda_setup (ARM64)
if: matrix.os == 'macos-14'
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: uxarray_build
channel-priority: strict
python-version: ${{ matrix.python-version }}
channels: conda-forge
environment-file: ci/environment.yml
installer-url: https://github.com/conda-forge/miniforge/releases/download/23.11.0-0/Miniforge3-23.11.0-0-MacOSX-arm64.sh
- name: Install uxarray
run: |
python -m pip install . --no-deps
- name: conda list
run: conda list
# Namespace
- name: Run Namespace Tests (timed + durations)
run: |
python - <<'PY'
import subprocess, sys, time
cmd = [sys.executable, "-m", "pytest", "test", "-q", "--durations=0"]
t0 = time.time()
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
with open("pytest_durations_ns.txt", "w", encoding="utf-8") as f:
for line in p.stdout:
print(line, end="")
f.write(line)
rc = p.wait()
dt = time.time() - t0
with open("total_time_ns.txt", "w", encoding="utf-8") as f:
f.write(f"{dt:.3f} seconds")
sys.exit(rc)
PY
# Coverage
- name: Run Coverage Tests (timed + durations)
env:
NUMBA_DISABLE_JIT: 1
run: |
python - <<'PY'
import subprocess, sys, time
cmd = [sys.executable, "-m", "pytest", "test", "-v",
"--cov=./uxarray", "--cov-report=xml", "--durations=0"]
t0 = time.time()
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
with open("pytest_durations_cov.txt", "w", encoding="utf-8") as f:
for line in p.stdout:
print(line, end="")
f.write(line)
rc = p.wait()
dt = time.time() - t0
with open("total_time_cov.txt", "w", encoding="utf-8") as f:
f.write(f"{dt:.3f} seconds")
sys.exit(rc)
PY
# Summary
- name: Add timing summary
if: always()
run: |
echo "## Test Timing Summary" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "- **Namespace tests total**: \`$(cat total_time_ns.txt 2>/dev/null || echo N/A)\`" >> "$GITHUB_STEP_SUMMARY"
echo "- **Coverage tests total**: \`$(cat total_time_cov.txt 2>/dev/null || echo N/A)\`" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "<details><summary>Namespace: pytest --durations=0</summary>" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
sed 's/^/ /' pytest_durations_ns.txt >> "$GITHUB_STEP_SUMMARY" || true
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "</details>" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "<details><summary>Coverage: pytest --durations=0</summary>" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
sed 's/^/ /' pytest_durations_cov.txt >> "$GITHUB_STEP_SUMMARY" || true
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "</details>" >> "$GITHUB_STEP_SUMMARY"
# Upload artifacts
- name: Upload timing logs
if: always()
uses: actions/upload-artifact@v4
with:
name: timings-${{ matrix.os }}-py${{ matrix.python-version }}
path: |
pytest_durations_ns.txt
total_time_ns.txt
pytest_durations_cov.txt
total_time_cov.txt
- name: Upload code coverage to Codecov
if: github.repository == 'UXARRAY/uxarray'
uses: codecov/[email protected]
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
file: ./coverage.xml
flags: unittests
env_vars: OS,PYTHON
name: codecov-umbrella
fail_ci_if_error: false