feat(workflows): upload core dump files in workflows #1586
Workflow file for this run
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
name: Tests | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
paths: | |
- setup.py | |
- setup.cfg | |
- pyproject.toml | |
- MANIFEST.in | |
- CMakeLists.txt | |
- include/** | |
- src/** | |
- tests/** | |
- optree/** | |
- .github/workflows/tests.yml | |
# Allow to trigger the workflow manually | |
workflow_dispatch: | |
permissions: | |
contents: read | |
concurrency: | |
group: "${{ github.workflow }}-${{ github.ref }}" | |
cancel-in-progress: ${{ github.event_name == 'pull_request' }} | |
env: | |
CMAKE_BUILD_TYPE: "Debug" | |
OPTREE_CXX_WERROR: "ON" | |
FULL_TEST_PYTHON_VERSIONS: "3.10;3.11" | |
PYTHON: "python" # to be updated | |
PYTHON_TAG: "py3" # to be updated | |
COLUMNS: "128" | |
jobs: | |
test: | |
name: Test for Python ${{ matrix.python-version }} on ${{ matrix.runner }} | |
runs-on: ${{ matrix.runner }} | |
strategy: | |
matrix: | |
runner: [ubuntu-latest, macos-latest, windows-latest] | |
python-version: | |
- "3.7" | |
- "3.8" | |
- "3.9" | |
- "3.10" | |
- "3.11" | |
- "3.12" | |
- "3.13" | |
- "pypy-3.9" | |
- "pypy-3.10" | |
include: | |
- runner: macos-13 | |
python-version: "3.7" | |
exclude: | |
- runner: macos-latest | |
python-version: "3.7" # Python 3.7 does not support macOS ARM64 | |
fail-fast: false | |
timeout-minutes: 90 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
update-environment: true | |
allow-prereleases: true | |
- name: Set up Environment | |
shell: bash | |
run: | | |
set -x | |
if [[ "${{ runner.os }}" == 'Windows' ]]; then | |
echo "CMAKE_BUILD_TYPE=Release" | tee -a "${GITHUB_ENV}" | |
fi | |
${{ env.PYTHON }} --version | |
echo "::group::Upgrade pip" | |
${{ env.PYTHON }} -m pip install --upgrade pip setuptools wheel rich | |
echo "::endgroup::" | |
echo "::group::Python sysconfig" | |
${{ env.PYTHON }} -c 'import rich, sysconfig; rich.print(sysconfig.get_config_vars())' | |
echo "::endgroup::" | |
export PYTHON_TAG="$( | |
echo 'import sys; print( | |
"{0.name[0]}p{1.major}{1.minor}{2}".format( | |
sys.implementation, | |
sys.version_info, | |
getattr(sys, "abiflags", ""), | |
).lower(), | |
)' | ${{ env.PYTHON }} - | |
)" | |
echo "PYTHON_TAG=${PYTHON_TAG}" | tee -a "${GITHUB_ENV}" | |
- name: Enable core dump generation (Linux) | |
if: runner.os == 'Linux' | |
run: | | |
sudo sysctl -w kernel.core_pattern="core.${PYTHON_TAG}.%P" | |
sudo sysctl -w kernel.core_uses_pid=0 | |
sudo sysctl -w fs.suid_dumpable=1 | |
sysctl kernel.core_pattern kernel.core_uses_pid fs.suid_dumpable | |
- name: Enable core dump generation (macOS) | |
if: runner.os == 'macOS' | |
run: | | |
sudo sysctl -w kern.corefile="core.${PYTHON_TAG}.%P" | |
sudo sysctl -w kern.coredump=1 | |
sudo sysctl -w kern.sugid_coredump=1 | |
sysctl kern.corefile kern.coredump kern.sugid_coredump | |
- name: Enable core dump generation (Windows) | |
if: runner.os == 'Windows' | |
run: | | |
$pwd = Get-Location | |
$Env:_NT_SOURCE_PATH = "$pwd" | |
$Env:_NT_SYMBOL_PATH = "cache*$pwd\.symcache;$Env:_NT_SOURCE_PATH;srv*https://msdl.microsoft.com/download/symbols" | |
Get-ChildItem -Path "C:\Program Files (x86)\Windows Kits" -Directory | Sort-Object -Property Name | |
$WindowsKitsDir = "C:\Program Files (x86)\Windows Kits\10" | |
$DebuggersDir = "$WindowsKitsDir\Debuggers\x64" | |
Get-ChildItem -Path $DebuggersDir | |
$Env:PATH = "$DebuggersDir;$Env:PATH" | |
$PYTEST = 'cdb -gG -o -c ".dump /ma /u core.dmp; !py; g; q" ${{ env.PYTHON }} -X dev -m pytest' | |
Write-Output "_NT_SOURCE_PATH=$Env:_NT_SOURCE_PATH" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append | |
Write-Output "_NT_SYMBOL_PATH=$Env:_NT_SYMBOL_PATH" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append | |
Write-Output "PATH=$Env:PATH" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append | |
Write-Output "PYTEST=$PYTEST" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append | |
cdb -version | |
- name: Install test dependencies | |
shell: bash | |
run: | | |
if [[ ";${FULL_TEST_PYTHON_VERSIONS};" == *";${{ matrix.python-version }};"* ]]; then | |
${{ env.PYTHON }} -m pip install -r tests/requirements.txt | |
fi | |
- name: Test installable with C++17 | |
if: runner.os != 'Windows' | |
run: | | |
OPTREE_CXX_WERROR=OFF CMAKE_CXX_STANDARD=17 ${{ env.PYTHON }} -m pip install -vv --editable . | |
${{ env.PYTHON }} -X dev -W 'always' -W 'error' -c 'import optree' | |
${{ env.PYTHON }} -m pip uninstall -y optree | |
- name: Install OpTree | |
run: | | |
${{ env.PYTHON }} -m pip install -vv --editable '.[test]' | |
- name: Test with pytest | |
shell: bash | |
run: | | |
set -x | |
ulimit -c unlimited | |
ulimit -a | |
PYTESTOPTS=( | |
"--exitfirst" | |
"--cov-report=xml:coverage-${{ env.PYTHON_TAG }}-${{ runner.os }}.xml" | |
"--junit-xml=junit-${{ env.PYTHON_TAG }}-${{ runner.os }}.xml" | |
) | |
make test PYTESTOPTS="${PYTESTOPTS[*]}" | |
if [[ -n "$(find . -iname "core.*.[1-9]*" -o -iname "core_*.dmp")" ]]; then | |
exit 1 | |
fi | |
- name: List generated files | |
if: ${{ !cancelled() }} | |
shell: bash | |
run: | | |
find . -type f -name '*.py[co]' -delete | |
find . -depth -type d -name "__pycache__" -exec rm -r "{}" + | |
if [[ -n "$(git status --ignored --porcelain | grep -vE '/$')" ]]; then | |
ls -alh $(git status --ignored --porcelain | grep -vE '/$' | cut -d ' ' -f2) | |
fi | |
- name: Collect backtraces from coredumps (if any) | |
if: ${{ !cancelled() }} | |
shell: bash | |
run: | | |
if [[ -n "$(find . -iname "core.*.[1-9]*" -o -iname "core_*.dmp")" ]]; then | |
echo "Found core dumps:" | |
ls -alh $(find . -iname "core.*.[1-9]*" -o -iname "core_*.dmp") | |
BACKTRACE_COMMAND="" | |
if [[ "${{ runner.os }}" == 'Linux' ]]; then | |
echo "::group::Install GDB" | |
( | |
export DEBIAN_FRONTEND=noninteractive | |
sudo apt-get update -qq && sudo apt-get install -yqq gdb | |
) | |
echo "::endgroup::" | |
BACKTRACE_COMMAND="gdb --exec ${{ env.PYTHON }} --core '{}' -ex 'bt' -ex 'q'" | |
elif [[ "${{ runner.os }}" == 'macOS' ]]; then | |
echo "::group::Install LLDB" | |
brew install llvm --quiet | |
echo "::endgroup::" | |
BACKTRACE_COMMAND="lldb --file ${{ env.PYTHON }} --core '{}' -o 'bt' -o 'q'" | |
elif [[ "${{ runner.os }}" == 'Windows' ]]; then | |
BACKTRACE_COMMAND="cdb -z '{}' -c \"!py; !analyze -vv; .ecxr; kP; q\"" | |
fi | |
if [[ -n "${BACKTRACE_COMMAND}" ]]; then | |
echo "Collecting backtraces:" | |
find . -iname "core.*.[1-9]*" -exec bash -xc " | |
echo '::group::backtrace from: {}'; | |
${BACKTRACE_COMMAND}; | |
echo '::endgroup::'; | |
" ';' | |
find . -iname "core_*.dmp" -exec bash -xc " | |
echo '::group::backtrace from: {}'; | |
${BACKTRACE_COMMAND}; | |
echo '::endgroup::'; | |
" ';' | |
fi | |
fi | |
- name: Upload coverage artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-${{ matrix.python-version }}-${{ runner.os }} | |
path: tests/coverage-*.xml | |
if-no-files-found: error | |
- name: Upload JUnit artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: junit-${{ matrix.python-version }}-${{ runner.os }} | |
path: tests/junit-*.xml | |
if-no-files-found: error | |
- name: Upload core dump file | |
if: ${{ !cancelled() }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coredump-${{ env.PYTHON_TAG }}-${{ runner.os }} | |
path: | | |
tests/core.* | |
tests/core_*.dmp | |
if-no-files-found: ignore | |
upload-coverage: | |
name: Upload coverage to Codecov | |
runs-on: ubuntu-latest | |
needs: test | |
timeout-minutes: 15 | |
steps: | |
- name: Download coverage artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: coverage-* | |
path: coverage | |
merge-multiple: true | |
- name: List coverage artifacts | |
run: ls -lh coverage/* | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v4 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
directory: coverage | |
flags: unittests | |
name: codecov-umbrella | |
verbose: true | |
fail_ci_if_error: false | |
upload-junit: | |
name: Upload JUnit results to Codecov | |
runs-on: ubuntu-latest | |
needs: test | |
timeout-minutes: 15 | |
steps: | |
- name: Download JUnit artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: junit-* | |
path: junit | |
merge-multiple: true | |
- name: List JUnit artifacts | |
run: ls -lh junit/* | |
- name: Upload JUnit results to Codecov | |
uses: codecov/test-results-action@v1 | |
with: | |
directory: junit | |
flags: unittests | |
name: junit-umbrella | |
verbose: true | |
fail_ci_if_error: false |