[WIP] Add duration scripts and logic from conda repo #3254
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: | |
# https://docs.github.com/en/webhooks-and-events/webhooks/webhook-events-and-payloads#push | |
push: | |
branches: | |
- main | |
- feature/** | |
- '[0-9].*.x' # e.g., 3.24.x | |
- '[0-9][0-9].*.x' # e.g., 23.3.x | |
# https://docs.github.com/en/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request | |
pull_request: | |
# https://docs.github.com/en/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_dispatch | |
workflow_dispatch: | |
# no payload | |
schedule: | |
# https://crontab.guru/#37_18_*_*_* | |
- cron: 37 18 * * * | |
concurrency: | |
# Concurrency group that uses the workflow name and PR number if available | |
# or commit SHA as a fallback. If a new build is triggered under that | |
# concurrency group while a previous build is running it will be canceled. | |
# Repeated pushes to a PR will cancel all previous builds, while multiple | |
# merges to main will not cancel. | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} | |
cancel-in-progress: true | |
env: | |
# https://conda.github.io/conda-libmamba-solver/user-guide/configuration/#advanced-options | |
CONDA_LIBMAMBA_SOLVER_NO_CHANNELS_FROM_INSTALLED: true | |
jobs: | |
# detect whether any code changes are included in this PR | |
changes: | |
runs-on: ubuntu-latest | |
permissions: | |
# necessary to detect changes | |
# https://github.com/dorny/paths-filter#supported-workflows | |
pull-requests: read | |
outputs: | |
code: ${{ steps.filter.outputs.code }} | |
steps: | |
- name: Checkout Source | |
uses: actions/checkout@v4 | |
# dorny/paths-filter needs git clone for non-PR events | |
# https://github.com/dorny/paths-filter#supported-workflows | |
if: github.event_name != 'pull_request' | |
- name: Filter Changes | |
uses: dorny/paths-filter@v3 | |
id: filter | |
with: | |
filters: | | |
code: | |
- 'conda_build/**' | |
- 'tests/**' | |
- '*.py' | |
- 'recipe/**' | |
- '.github/workflows/tests.yml' | |
# linux test suite | |
linux: | |
# only run test suite if there are code changes | |
needs: changes | |
if: github.event_name == 'schedule' || needs.changes.outputs.code == 'true' | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
# https://github.com/conda-incubator/setup-miniconda#use-a-default-shell | |
shell: bash -el {0} | |
strategy: | |
fail-fast: false | |
matrix: | |
# test all lower versions (w/ stable conda) and upper version (w/ canary conda) | |
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] | |
conda-version: [23.5.0, release, canary] | |
test-group: [1, 2, 3] | |
exclude: | |
# testing oldest supported conda with Python 3.8 | |
- python-version: '3.9' | |
conda-version: 23.5.0 | |
- python-version: '3.10' | |
conda-version: 23.5.0 | |
- python-version: '3.11' | |
conda-version: 23.5.0 | |
- python-version: '3.12' | |
conda-version: 23.5.0 | |
# testing stable conda with Python 3.9-3.11 | |
- python-version: '3.8' | |
conda-version: release | |
- python-version: '3.12' | |
conda-version: release | |
# testing canary conda with Python 3.12 | |
- python-version: '3.8' | |
conda-version: canary | |
- python-version: '3.9' | |
conda-version: canary | |
- python-version: '3.10' | |
conda-version: canary | |
- python-version: '3.11' | |
conda-version: canary | |
env: | |
CONDA_CHANNEL_LABEL: ${{ matrix.conda-version == 'canary' && 'conda-canary/label/dev::' || '' }} | |
CONDA_VERSION: ${{ contains('canary|release', matrix.conda-version) && 'conda' || format('conda={0}', matrix.conda-version) }} | |
PYTEST_SPLITS: 3 | |
steps: | |
- name: Checkout Source | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Hash + Timestamp | |
run: echo "HASH=${{ runner.os }}-${{ runner.arch }}-Py${{ matrix.python-version }}-${{ matrix.conda-version }}-${{ matrix.test-group }}-$(date -u "+%Y%m")" >> $GITHUB_ENV | |
- name: Cache Conda | |
uses: actions/cache@v4 | |
with: | |
path: ~/conda_pkgs_dir | |
key: cache-${{ env.HASH }} | |
- name: Setup Miniconda | |
uses: conda-incubator/setup-miniconda@v3 | |
with: | |
condarc-file: .github/condarc | |
run-post: false # skip post cleanup | |
- name: Conda Install | |
run: conda install | |
--yes | |
--file tests/requirements.txt | |
--file tests/requirements-${{ runner.os }}.txt | |
--file tests/requirements-ci.txt | |
python=${{ matrix.python-version }} | |
${{ env.CONDA_CHANNEL_LABEL }}${{ env.CONDA_VERSION }} | |
# TODO: how can we remove this step? | |
- name: Install Self | |
run: pip install -e . | |
- name: Conda Info | |
run: conda info --verbose | |
- name: Conda List | |
run: conda list --show-channel-urls | |
- name: Run Tests | |
run: pytest | |
--cov=conda_build | |
--durations-path=tools/durations/${{ runner.os }}.json | |
--group=${{ matrix.test-group }} | |
--splits=${{ env.PYTEST_SPLITS }} | |
-n auto | |
- name: Upload Coverage | |
uses: codecov/codecov-action@v4 | |
with: | |
flags: ${{ runner.os }},${{ runner.arch }},${{ matrix.python-version }},${{ matrix.test-type }} | |
- name: Upload Test Results | |
if: '!cancelled()' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: test-results-${{ env.HASH }} | |
path: | | |
.coverage | |
tools/durations/${{ runner.os }}.json | |
test-report.xml | |
retention-days: 1 # temporary, combined in aggregate below | |
# windows test suite | |
windows: | |
# only run test suite if there are code changes | |
needs: changes | |
if: github.event_name == 'schedule' || needs.changes.outputs.code == 'true' | |
runs-on: windows-2019 | |
strategy: | |
fail-fast: false | |
matrix: | |
# test lower version (w/ stable conda) and upper version (w/ canary conda) | |
python-version: ['3.8', '3.12'] | |
conda-version: [release, canary] | |
test-group: [1, 2, 3] | |
exclude: | |
- python-version: '3.8' | |
conda-version: canary | |
- python-version: '3.12' | |
conda-version: release | |
env: | |
ErrorActionPreference: Stop # powershell exit on first error | |
CONDA_CHANNEL_LABEL: ${{ matrix.conda-version == 'canary' && 'conda-canary/label/dev' || 'defaults' }} | |
PYTEST_SPLITS: 3 | |
steps: | |
- name: Checkout Source | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Hash + Timestamp | |
shell: bash # use bash to run date command | |
run: echo "HASH=${{ runner.os }}-${{ runner.arch }}-Py${{ matrix.python-version }}-${{ matrix.conda-version }}-${{ matrix.test-group }}-$(date -u "+%Y%m")" >> $GITHUB_ENV | |
- name: Cache Conda | |
uses: actions/cache@v4 | |
with: | |
path: ~/conda_pkgs_dir | |
key: cache-${{ env.HASH }} | |
- name: Setup Miniconda | |
uses: conda-incubator/setup-miniconda@v3 | |
with: | |
condarc-file: .github\condarc | |
run-post: false # skip post cleanup | |
- name: Choco Install | |
run: choco install visualstudio2017-workload-vctools | |
- name: Conda Install | |
run: conda install | |
--yes | |
--file tests\requirements.txt | |
--file tests\requirements-${{ runner.os }}.txt | |
--file tests\requirements-ci.txt | |
python=${{ matrix.python-version }} | |
${{ env.CONDA_CHANNEL_LABEL }}::conda | |
# TODO: how can we remove this step? | |
- name: Install Self | |
run: pip install -e . | |
- name: Conda Info | |
run: conda info --verbose | |
- name: Conda List | |
run: conda list --show-channel-urls | |
- name: Run Tests | |
# Windows is sensitive to long paths, using `--basetemp=${{ runner.temp }} to | |
# keep the test directories shorter | |
run: pytest | |
--cov=conda_build | |
--basetemp=${{ runner.temp }} | |
--durations-path=tools\durations\${{ runner.os }}.json | |
--group=${{ matrix.test-group }} | |
--splits=${{ env.PYTEST_SPLITS }} | |
-n auto | |
- name: Upload Coverage | |
uses: codecov/codecov-action@v4 | |
with: | |
flags: ${{ runner.os }},${{ runner.arch }},${{ matrix.python-version }},${{ matrix.test-type }} | |
- name: Upload Test Results | |
if: '!cancelled()' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: test-results-${{ env.HASH }} | |
path: | | |
.coverage | |
tools\durations\${{ runner.os }}.json | |
test-report.xml | |
retention-days: 1 # temporary, combined in aggregate below | |
# macos test suite | |
macos: | |
# only run test suite if there are code changes | |
needs: changes | |
if: github.event_name == 'schedule' || needs.changes.outputs.code == 'true' | |
runs-on: macos-11 | |
defaults: | |
run: | |
# https://github.com/conda-incubator/setup-miniconda#use-a-default-shell | |
shell: bash -el {0} | |
strategy: | |
fail-fast: false | |
matrix: | |
# test lower version (w/ stable conda) and upper version (w/ canary conda) | |
python-version: ['3.8', '3.12'] | |
conda-version: [release, canary] | |
test-group: [1, 2, 3] | |
exclude: | |
- python-version: '3.8' | |
conda-version: canary | |
- python-version: '3.12' | |
conda-version: release | |
env: | |
CONDA_CHANNEL_LABEL: ${{ matrix.conda-version == 'canary' && 'conda-canary/label/dev' || 'defaults' }} | |
PYTEST_SPLITS: 3 | |
steps: | |
- name: Checkout Source | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Hash + Timestamp | |
run: echo "HASH=${{ runner.os }}-${{ runner.arch }}-Py${{ matrix.python-version }}-${{ matrix.conda-version }}-${{ matrix.test-group }}-$(date -u "+%Y%m")" >> $GITHUB_ENV | |
- name: Cache Conda | |
uses: actions/cache@v4 | |
with: | |
path: ~/conda_pkgs_dir | |
key: cache-${{ env.HASH }} | |
- name: Setup Miniconda | |
uses: conda-incubator/setup-miniconda@v3 | |
with: | |
condarc-file: .github/condarc | |
run-post: false # skip post cleanup | |
- name: Xcode Install | |
run: sudo xcode-select --switch /Applications/Xcode_11.7.app | |
- name: Conda Install | |
run: conda install | |
--yes | |
--file tests/requirements.txt | |
--file tests/requirements-${{ runner.os }}.txt | |
--file tests/requirements-ci.txt | |
python=${{ matrix.python-version }} | |
${{ env.CONDA_CHANNEL_LABEL }}::conda | |
# TODO: how can we remove this step? | |
- name: Install Self | |
run: pip install -e . | |
- name: Conda Info | |
run: conda info --verbose | |
- name: Conda List | |
run: conda list --show-channel-urls | |
- name: Run Tests | |
run: pytest | |
--cov=conda_build | |
--durations-path=tools/durations/${{ runner.os }}.json | |
--group=${{ matrix.test-group }} | |
--splits=${{ env.PYTEST_SPLITS }} | |
-n auto | |
- name: Upload Coverage | |
uses: codecov/codecov-action@v4 | |
with: | |
flags: ${{ runner.os }},${{ runner.arch }},${{ matrix.python-version }},${{ matrix.test-type }} | |
- name: Upload Test Results | |
if: '!cancelled()' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: test-results-${{ env.HASH }} | |
path: | | |
.coverage | |
tools/durations/${{ runner.os }}.json | |
test-report.xml | |
retention-days: 1 # temporary, combined in aggregate below | |
# aggregate and upload | |
aggregate: | |
# only aggregate test suite if there are code changes | |
needs: [changes, linux, windows, macos] | |
if: >- | |
!cancelled() | |
&& ( | |
github.event_name == 'schedule' | |
|| needs.changes.outputs.code == 'true' | |
) | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download Artifacts | |
uses: actions/download-artifact@v4 | |
- name: Upload Combined Test Results | |
# provides one downloadable archive of all matrix run test results for further analysis | |
uses: actions/upload-artifact@v4 | |
with: | |
name: test-results-${{ github.sha }}-all | |
path: test-results-* | |
- name: Test Summary | |
uses: test-summary/action@v2 | |
with: | |
paths: test-results-*/test-report.xml | |
# required check | |
analyze: | |
needs: [linux, windows, macos, aggregate] | |
if: '!cancelled()' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Determine Success | |
uses: re-actors/[email protected] | |
with: | |
# permit jobs to be skipped if there are no code changes (see changes job) | |
allowed-skips: ${{ toJSON(needs) }} | |
jobs: ${{ toJSON(needs) }} | |
# canary builds | |
build: | |
needs: [analyze] | |
# only build canary build if | |
# - prior steps succeeded, | |
# - this is the main repo, and | |
# - we are on the main, feature, or release branch | |
if: >- | |
!cancelled() | |
&& !github.event.repository.fork | |
&& ( | |
github.ref_name == 'main' | |
|| startsWith(github.ref_name, 'feature/') | |
|| endsWith(github.ref_name, '.x') | |
) | |
strategy: | |
matrix: | |
include: | |
- runner: ubuntu-latest | |
subdir: linux-64 | |
- runner: macos-latest | |
subdir: osx-64 | |
- runner: macos-14 | |
subdir: osx-arm64 | |
- runner: windows-latest | |
subdir: win-64 | |
runs-on: ${{ matrix.runner }} | |
steps: | |
# Clean checkout of specific git ref needed for package metadata version | |
# which needs env vars GIT_DESCRIBE_TAG and GIT_BUILD_STR: | |
- name: Checkout Source | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.ref }} | |
clean: true | |
fetch-depth: 0 | |
# Explicitly use Python 3.12 since each of the OSes has a different default Python | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.12' | |
- name: Detect Label | |
shell: python | |
run: | | |
from pathlib import Path | |
from re import match | |
from os import environ | |
if "${{ github.ref_name }}" == "main": | |
# main branch commits are uploaded to the dev label | |
label = "dev" | |
elif "${{ github.ref_name }}".startswith("feature/"): | |
# feature branch commits are uploaded to a custom label | |
label = "${{ github.ref_name }}" | |
else: | |
# release branch commits are added to the rc label | |
# see https://github.com/conda/infrastructure/issues/760 | |
_, name = "${{ github.repository }}".split("/") | |
label = f"rc-{name}-${{ github.ref_name }}" | |
Path(environ["GITHUB_ENV"]).write_text(f"ANACONDA_ORG_LABEL={label}") | |
- name: Create & Upload | |
uses: conda/actions/[email protected] | |
with: | |
package-name: ${{ github.event.repository.name }} | |
subdir: ${{ matrix.subdir }} | |
anaconda-org-channel: conda-canary | |
anaconda-org-label: ${{ env.ANACONDA_ORG_LABEL }} | |
anaconda-org-token: ${{ secrets.ANACONDA_ORG_CONDA_CANARY_TOKEN }} |