diff --git a/.github/actions/setup-tests/action.yml b/.github/actions/setup-tests/action.yml new file mode 100644 index 0000000..6f36304 --- /dev/null +++ b/.github/actions/setup-tests/action.yml @@ -0,0 +1,33 @@ +name: Set up C++ tests + +runs: + using: composite + steps: + - name: Fetch upstream release tags + shell: bash + run: git fetch --tags https://github.com/diffpy/libdiffpy.git + + - name: Check out CxxTest 4.4 + uses: actions/checkout@v6 + with: + repository: CxxTest/cxxtest + ref: 191adddb3876ab389c0c856e1c03874bf70f8ee4 + path: build/cxxtest + + - name: Prepare C++ test configuration + shell: python {0} + run: | + import runpy + runpy.run_path('.github/scripts/configure-tests.py') + + - name: Create build environment + uses: conda-incubator/setup-miniconda@v3 + with: + activate-environment: test + channels: conda-forge + conda-remove-defaults: "true" + auto-update-conda: false + auto-activate-base: false + python-version: "3.14" + environment-file: build/test-environment.yml + channel-priority: strict diff --git a/.github/scripts/configure-matrix.py b/.github/scripts/configure-tests.py similarity index 93% rename from .github/scripts/configure-matrix.py rename to .github/scripts/configure-tests.py index 7687a05..9b3e3fc 100644 --- a/.github/scripts/configure-matrix.py +++ b/.github/scripts/configure-tests.py @@ -1,4 +1,4 @@ -"""Configure SCons and CxxTest for the CI matrix.""" +"""Configure SCons, CxxTest and the conda environment for CI tests.""" import json from pathlib import Path @@ -11,7 +11,7 @@ requirements.append(spec) Path("build").mkdir(exist_ok=True) -Path("build/matrix-environment.yml").write_text( +Path("build/test-environment.yml").write_text( json.dumps( { "name": "test", diff --git a/.github/workflows/matrix-and-codecov.yml b/.github/workflows/matrix-and-codecov.yml index 4379fce..285c9f0 100644 --- a/.github/workflows/matrix-and-codecov.yml +++ b/.github/workflows/matrix-and-codecov.yml @@ -1,29 +1,29 @@ name: Matrix and Codecov on: - # push: - # branches: - # - main - release: - types: - - prereleased - - published + push: + branches: + - main + + workflow_call: + secrets: + CODECOV_TOKEN: + required: false workflow_dispatch: concurrency: group: matrix-${{ github.ref }} - cancel-in-progress: ${{ github.event_name != 'release' }} + cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/') }} jobs: matrix-coverage: - name: C++ tests (${{ matrix.os }}, Python ${{ matrix.python-version }}) + name: C++ tests (${{ matrix.os }}) runs-on: ${{ matrix.os }} timeout-minutes: 45 strategy: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest, macos-15-intel] - python-version: ["3.12", "3.13", "3.14"] include: - os: ubuntu-latest shell: bash -l {0} @@ -51,48 +51,21 @@ jobs: with: fetch-depth: 0 - - name: Fetch upstream release tags - run: git fetch --tags https://github.com/diffpy/libdiffpy.git - - # CxxTest is header-only and its generator runs directly from source. - # The conda-forge package is not available on every matrix platform. - - name: Check out CxxTest 4.4 - uses: actions/checkout@v6 - with: - repository: CxxTest/cxxtest - ref: 191adddb3876ab389c0c856e1c03874bf70f8ee4 - path: build/cxxtest - - - name: Prepare C++ test configuration - shell: python {0} - run: | - import runpy - runpy.run_path('.github/scripts/configure-matrix.py') - - - name: Create build environment - uses: conda-incubator/setup-miniconda@v3 - with: - activate-environment: test - channels: conda-forge - conda-remove-defaults: "true" - auto-update-conda: false - auto-activate-base: false - python-version: ${{ matrix.python-version }} - environment-file: build/matrix-environment.yml - channel-priority: strict + - name: Set up C++ tests + uses: ./.github/actions/setup-tests - name: Build and run C++ tests run: scons -j${{ matrix.jobs }} build=${{ matrix.build }} test - name: Generate coverage report - if: runner.os == 'Linux' && matrix.python-version == '3.14' + if: runner.os == 'Linux' run: >- gcovr --gcov-executable "$CONDA_PREFIX/bin/gcov" --root . --filter 'build/coverage-.*/diffpy/' --xml coverage.xml - name: Save coverage report - if: runner.os == 'Linux' && matrix.python-version == '3.14' + if: runner.os == 'Linux' uses: actions/upload-artifact@v4 with: name: coverage-report @@ -101,9 +74,7 @@ jobs: - name: Upload coverage to Codecov # Fork push builds have no upstream Codecov token; keep their artifact. - if: >- - runner.os == 'Linux' && matrix.python-version == '3.14' && - github.repository == 'diffpy/libdiffpy' + if: runner.os == 'Linux' && github.repository == 'diffpy/libdiffpy' uses: codecov/codecov-action@v5 with: files: coverage.xml diff --git a/.github/workflows/release-github-on-tag.yml b/.github/workflows/release-github-on-tag.yml index b771e7c..a75982e 100644 --- a/.github/workflows/release-github-on-tag.yml +++ b/.github/workflows/release-github-on-tag.yml @@ -19,8 +19,13 @@ jobs: secrets: PAT_TOKEN: ${{ secrets.PAT_TOKEN }} + matrix: + uses: ./.github/workflows/matrix-and-codecov.yml + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + release-github: - needs: [check-tag-privilege, check-pat-token-validity] + needs: [check-tag-privilege, check-pat-token-validity, matrix] uses: scikit-package/release-scripts/.github/workflows/_release-github.yml@v0 secrets: PAT_TOKEN: ${{ secrets.PAT_TOKEN }} diff --git a/.github/workflows/tests-on-pr.yml b/.github/workflows/tests-on-pr.yml index ed8cea1..35e3916 100644 --- a/.github/workflows/tests-on-pr.yml +++ b/.github/workflows/tests-on-pr.yml @@ -21,38 +21,8 @@ jobs: with: fetch-depth: 0 - - name: Initialize miniconda - uses: conda-incubator/setup-miniconda@v3 - with: - activate-environment: test - channels: conda-forge - conda-remove-defaults: "true" - auto-update-conda: false - auto-activate-base: false - - - name: Conda config - run: >- - conda config --set always_yes yes - --set changeps1 no - - - name: Install requirements - run: >- - conda install - --file requirements/build.txt - --file requirements/conda.txt - --file requirements/tests.txt - - - name: Configure SCons for the conda environment - run: | - cat > sconscript.local <<'EOF' - Import('env') - import os - prefix = os.environ['CONDA_PREFIX'] - env.Replace(CXX=os.path.join(prefix, 'bin', 'c++')) - env.Prepend(CCFLAGS=['-isystem' + os.path.join(prefix, 'include')]) - env.Append(LIBPATH=os.path.join(prefix, 'lib')) - env.Append(LINKFLAGS='-Wl,-rpath,' + os.path.join(prefix, 'lib')) - EOF + - name: Set up C++ tests + uses: ./.github/actions/setup-tests - name: Build and run C++ tests with coverage run: |