From ab608b3f40bc3fa712675a7a197ad90e28f0abbb Mon Sep 17 00:00:00 2001 From: Thomas Chamberlin Date: Tue, 5 Dec 2023 15:43:23 -0500 Subject: [PATCH] Updates to GitHub Actions/Workflows (#151) - Updates to GH Actions and pre-commit hooks - Enable caching of pip reqs - Enable code coverage generation and reporting - Removed unused workflow files - Update README to add badges - Re-enable pip-compile hook; regenerate requirements.txt - Remove requirements_dev.txt; not used --- .github/workflows/build.yml | 31 -- .github/workflows/ci.yml | 86 ++++ .github/workflows/hatch-and-pytest.yml | 40 -- .github/workflows/pre-commit.yml | 20 - .github/workflows/pyinstaller.yml | 38 -- .github/workflows/release.yml | 15 +- .github/workflows/workflow.yml | 16 - .pre-commit-config.yaml | 15 +- README.md | 2 + pyproject.toml | 19 +- requirements.txt | 582 +++++++++++++++++++++++-- requirements_dev.txt | 15 - src/dysh/__init__.py | 1 + src/dysh/fits/__init__.py | 9 +- src/dysh/fits/sdfitsload.py | 1 + src/dysh/plot/__init__.py | 1 + src/dysh/spectra/__init__.py | 1 + src/dysh/util/__init__.py | 1 + 18 files changed, 665 insertions(+), 228 deletions(-) delete mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/hatch-and-pytest.yml delete mode 100644 .github/workflows/pre-commit.yml delete mode 100644 .github/workflows/pyinstaller.yml delete mode 100644 .github/workflows/workflow.yml delete mode 100644 requirements_dev.txt diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 44c02b78..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Build with hatch - -on: - release: - types: [created] - workflow_dispatch: # needed for "Run" button to show up in action menu - -jobs: - build: - runs-on: ${{ matrix.os }} - environment: hatch build - - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest] - python-version: ["3.x"] - steps: - - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements_dev.txt - pip install -e . - - name: Build with hatch - run: | - hatch build -c diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..84be9456 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,86 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: CI +on: + push: + branches: + - "main" + - "release*" + - "*-devel" + - "*_devel" + - "*-ci" + - "*_ci" + pull_request: # Run on all pull requests + workflow_dispatch: # needed for "Run" button to show up in action +env: + FORCE_COLOR: "1" # Make tools pretty. + PIP_DISABLE_PIP_VERSION_CHECK: "1" + PIP_NO_PYTHON_VERSION_WARNING: "1" + +jobs: + tests: + runs-on: ${{ matrix.os }} + + strategy: + # Ensure that if even if a build in the matrix fails, the others continue + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + python-version: ["3.9", "3.10", "3.11", "3.12"] + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + # Enable caching of pip packages between workflow jobs. This can speed things up dramatically, _if_ + # jobs are executed fairly close together in time + # See: https://github.com/actions/setup-python/blob/main/docs/advanced-usage.md#caching-packages + cache: 'pip' + cache-dependency-path: 'requirements.txt' + - name: Install dependencies + run: | + # Install requirements, as compiled by pip-compile + pip install -r requirements.txt + # Install dysh itself, in editable mode (which is required to avoid breaking the caching mechanism above) + pip install -e . + - name: Test with pytest + run: | + # Write coverage data files, namespaced using matrix info + coverage run --data-file=".coverage.${{ matrix.os }}.${{ matrix.python-version }}" -m pytest + - name: Upload coverage data + # Upload only ubuntu results, since we are only running the coverage step on ubuntu + if: matrix.os == 'ubuntu-latest' + uses: actions/upload-artifact@v3 + with: + name: coverage-data + path: ".coverage.ubuntu-latest*" + coverage: + needs: tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: 3.9 + cache: pip + - run: pip install --upgrade coverage[toml] + - uses: actions/download-artifact@v3 + with: + name: coverage-data + - name: Combine coverage + run: | + coverage combine + coverage html --skip-covered --skip-empty + + # Report and write to summary. + coverage report | sed 's/^/ /' >> $GITHUB_STEP_SUMMARY + + # Report again and fail if under 100%. + # coverage report --fail-under=100 + - name: Upload HTML report + uses: actions/upload-artifact@v3 + with: + name: html-report + path: htmlcov diff --git a/.github/workflows/hatch-and-pytest.yml b/.github/workflows/hatch-and-pytest.yml deleted file mode 100644 index e86b9aa4..00000000 --- a/.github/workflows/hatch-and-pytest.yml +++ /dev/null @@ -1,40 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python - -name: Build and Pytest - -on: - push: - branches: [ "main", "release-*", "cat-devel", "mwp-devel", "pedro-devel", "evan-devel" ] - pull_request: - branches: [ "main", "release-*", "cat-devel", "mwp-devel", "pedro-devel", "evan-devel" ] - workflow_dispatch: # needed for "Run" button to show up in action -jobs: - build: - runs-on: ${{ matrix.os }} - environment: hatch build - - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - python-version: ["3.9", "3.10", "3.11", "3.12"] - - steps: - - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install flake8 pytest - pip install -r requirements.txt - pip install -e . - - name: Build with hatch - run: | - hatch build -c - - name: Test with pytest - run: | - pytest diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml deleted file mode 100644 index 3e5f8cc2..00000000 --- a/.github/workflows/pre-commit.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: pre-commit - -on: - pull_request: - push: - branches: [main, release*] - - -jobs: - pre-commit: - env: - SKIP: ruff - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - # must match the version in .pre-commit-config.yaml:default_language_version.python - python-version: '3.9' - - uses: pre-commit/action@v3.0.0 diff --git a/.github/workflows/pyinstaller.yml b/.github/workflows/pyinstaller.yml deleted file mode 100644 index d7ddcfc1..00000000 --- a/.github/workflows/pyinstaller.yml +++ /dev/null @@ -1,38 +0,0 @@ - -name: Package GUI with Pyinstaller - -on: - push: - branches: [ "cat-devel" ] - pull_request: - branches: [ "cat-devel" ] - -jobs: - build: - runs-on: ${{ matrix.os }} - environment: hatch build - - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - python-version: ["3.9", "3.10", "3.11", "3.12"] - - steps: - - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - pip install -e . - - name: Build with hatch - run: | - hatch build -c - - name: Package GUI with PyInstaller - run: | - cd gui - pyinstaller app.py diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 56305228..05c51ae7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,25 +11,22 @@ jobs: environment: release permissions: # IMPORTANT: this permission is mandatory for trusted publishing + # See: https://github.com/pypa/gh-action-pypi-publish#trusted-publishing id-token: write - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest] - python-version: ["3.x"] steps: - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} + - name: Set up Python uses: actions/setup-python@v3 with: - python-version: ${{ matrix.python-version }} + python-version: '3.9' # Should always be the minimum supported Python version + cache: 'pip' + cache-dependency-path': 'requirements.txt' - name: Install dependencies run: | python -m pip install --upgrade pip pip install -r requirements.txt - pip install -e . - name: Build with hatch run: | - hatch build -c + hatch build --clean - name: upload release to PyPI uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml deleted file mode 100644 index b10a84b6..00000000 --- a/.github/workflows/workflow.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: TestWorkflow - -on: - release: - types: [created] - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Run a one-line script - run: echo Hello, world! diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1837eee9..e7b665e4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,39 +1,36 @@ --- # See https://pre-commit.com for more information default_language_version: - python: python3.10 + python: python3.9 # See https://pre-commit.com/hooks.html for more hooks repos: - repo: 'https://github.com/pre-commit/pre-commit-hooks' - rev: v4.4.0 + rev: v4.5.0 hooks: - id: trailing-whitespace exclude: '(notebooks|attic|benchmark|testdata)/.*' - id: end-of-file-fixer exclude: LICENSE - id: check-yaml + - id: check-toml - id: check-added-large-files args: - '--maxkb=1024' - id: debug-statements + - id: detect-private-key - id: mixed-line-ending args: - '--fix=lf' - id: check-docstring-first + - id: check-case-conflict # Check for files with names that would conflict on a case-insensitive filesystem - repo: https://github.com/pycqa/isort rev: 5.12.0 hooks: - id: isort exclude: '(notebooks|attic|benchmark|testdata)/.*' - repo: 'https://github.com/psf/black' - rev: 23.1.0 + rev: 23.11.0 hooks: - id: black exclude: '(notebooks|attic|benchmark|testdata)/.*' -# - repo: https://github.com/jazzband/pip-tools -# rev: 6.12.3 -# hooks: -# - id: pip-compile -# args: -# - '--resolver=backtracking' diff --git a/README.md b/README.md index a6511564..9e6ddad1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ [![Documentation Status](https://readthedocs.org/projects/dysh/badge/?version=latest)](https://dysh.readthedocs.io/en/latest/?badge=latest) +[![pre-commit.ci Status](https://results.pre-commit.ci/badge/github/GreenBankObservatory/dysh/main.svg)](https://results.pre-commit.ci/latest/github/GreenBankObservatory/dysh/main) +[![CI Workflow Build Status](https://github.com/GreenBankObservatory/dysh/actions/workflows/ci.yml/badge.svg)](https://github.com/GreenBankObservatory/dysh/actions/workflows/ci.yml) # dysh diff --git a/pyproject.toml b/pyproject.toml index 66427432..25b5ee35 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,6 +35,7 @@ dependencies = [ [project.optional-dependencies] dev = [ + "coverage[toml]", "ipdb", "numpydoc", "pytest", @@ -81,7 +82,7 @@ docs-build = "sphinx-build {root}/docs/source {root}/docs/build -b html {args}" # run via: $ hatch run test: