diff --git a/.github/actions/build-sphinx/action.yml b/.github/actions/build-sphinx/action.yml deleted file mode 100644 index a38fe4b..0000000 --- a/.github/actions/build-sphinx/action.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: "Build Sphinx Documentation" -description: "Build and upload HTML documentation to artifact storage." - -inputs: - python-version: - description: "Python version to use when building documentation." - default: "3.11" - artifact-name: - description: "Artifact name to use when uploading the compiled documentation" - default: "github-pages" - -runs: - using: "composite" - steps: - - name: Set up Python ${{ inputs.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ inputs.python-version }} - - - name: Install Poetry - uses: snok/install-poetry@v1 - with: - virtualenvs-create: false - - - name: Install dependencies - shell: bash - run: poetry install --with docs - - - name: Build Docs - shell: bash - working-directory: docs - run: make html SPHINXOPTS="-W" - - - name: Upload artifact - uses: actions/upload-pages-artifact@v1 - with: - name: ${{ inputs.artifact-name }} - path: docs/build/html diff --git a/.github/actions/run-tests/action.yml b/.github/actions/run-tests/action.yml deleted file mode 100644 index 35b0b33..0000000 --- a/.github/actions/run-tests/action.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: "Run Application Tests" -description: "Execute the application test suite." - -inputs: - python-version: - required: true - description: "Python version to use when running tests." - coverage-output: - required: false - description: "Optionally export test coverage to the given XML file path." - -runs: - using: "composite" - steps: - - name: Set up Python ${{ inputs.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ inputs.python-version }} - - - name: Install Poetry - uses: snok/install-poetry@v1 - with: - virtualenvs-create: false - - - name: Install package dependencies - shell: bash - run: poetry install --with tests - - - name: Run tests with coverage - shell: bash - run: | - pip install coverage - coverage run -m unittest discover - coverage report --omit="tests/*" - - - name: Export test coverage - if: ${{ inputs.coverage-output }} - shell: bash - run: - coverage xml --omit="tests/*" -o ${{ inputs.coverage-output }} diff --git a/.github/workflows/DocumentationBuild.yml b/.github/workflows/DocumentationBuild.yml index 57d2c4d..7cdb0c1 100644 --- a/.github/workflows/DocumentationBuild.yml +++ b/.github/workflows/DocumentationBuild.yml @@ -5,9 +5,6 @@ on: workflow_call: pull_request: -permissions: - contents: read - jobs: build: name: Build Documentation @@ -16,5 +13,26 @@ jobs: - name: Checkout project source uses: actions/checkout@v3 - - name: Build Docs - uses: ./.github/actions/build-sphinx + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + virtualenvs-create: false + + - name: Install dependencies + shell: bash + run: poetry install --with docs + + - name: Build docs + shell: bash + working-directory: docs + run: make html SPHINXOPTS="-W" + + - name: Upload docs to artifact storage + uses: actions/upload-pages-artifact@v1 + with: + path: docs/build/html diff --git a/.github/workflows/DocumentationPublish.yml b/.github/workflows/DocumentationPublish.yml index d9422e0..68badbf 100644 --- a/.github/workflows/DocumentationPublish.yml +++ b/.github/workflows/DocumentationPublish.yml @@ -9,8 +9,8 @@ permissions: id-token: write jobs: - build-docs: - needs: run-tests + build: + name: Build uses: ./.github/workflows/DocumentationBuild.yml secrets: inherit diff --git a/.github/workflows/PackagePublish.yml b/.github/workflows/PackagePublish.yml index f5c2bcd..c2bb331 100644 --- a/.github/workflows/PackagePublish.yml +++ b/.github/workflows/PackagePublish.yml @@ -6,30 +6,36 @@ on: permissions: contents: read + packages: read pages: write id-token: write jobs: run-tests: - name: Run Tests - runs-on: ubuntu-latest - strategy: - matrix: - python-version: [ "3.8", "3.9", "3.10", "3.11" ] - - steps: - - name: Checkout source - uses: actions/checkout@v3 + name: Tests + uses: ./.github/workflows/PackageTest.yml + secrets: inherit - - name: Run Tests - uses: ./.github/actions/run-tests - with: - python-version: ${{ matrix.python-version }} - - build-distribution: - name: Build Source Distribution + build-docs: + name: Docs needs: run-tests + uses: ./.github/workflows/DocumentationBuild.yml + secrets: inherit + + publish-package: + name: Publish Distribution + needs: [ build-docs ] runs-on: ubuntu-latest + environment: ${{ matrix.environment }} + + strategy: + fail-fast: false + matrix: + include: + - host: https://py00.crc.pitt.edu + environment: publish-h2p + - host: https://upload.pypi.org/legacy/ + environment: publish-pypi steps: - name: Checkout source @@ -62,39 +68,6 @@ jobs: path: dist retention-days: 7 - build-docs: - name: Build Documentation - needs: run-tests - runs-on: ubuntu-latest - steps: - - name: Checkout project source - uses: actions/checkout@v3 - - - name: Run tests - uses: ./.github/actions/build-sphinx - - publish-package: - name: Publish Distribution - needs: [ build-distribution, build-docs ] - runs-on: ubuntu-latest - environment: ${{ matrix.environment }} - - strategy: - fail-fast: false - matrix: - include: - - host: https://py00.crc.pitt.edu - environment: publish-h2p - - host: https://upload.pypi.org/legacy/ - environment: publish-pypi - - steps: - - name: Download distribution from artifact storage - uses: actions/download-artifact@v3 - with: - name: package-build - path: dist - - name: Publish package uses: pypa/gh-action-pypi-publish@release/v1 with: diff --git a/.github/workflows/PackageTest.yml b/.github/workflows/PackageTest.yml index 13a48e1..d9b1e8e 100644 --- a/.github/workflows/PackageTest.yml +++ b/.github/workflows/PackageTest.yml @@ -12,31 +12,58 @@ jobs: strategy: fail-fast: false matrix: - python-version: [ "3.8", "3.9", "3.10", "3.11" ] + slurm_version: + - 20.02.5.1 + - 20.11.9.1 + - 22.05.2.1 + python_version: + - 3.8 + - 3.9 + + container: + image: ghcr.io/pitt-crc/test-env:${{ matrix.slurm_version }} + credentials: + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} steps: + - name: Setup environment + run: /usr/local/bin/entrypoint.sh + - name: Checkout repository uses: actions/checkout@v3 - - name: Run tests - uses: ./.github/actions/run-tests - with: - python-version: ${{ matrix.python-version }} - coverage-output: coverage.xml + - name: Install poetry + run: pip install poetry + + - name: Install dependencies + run: | + poetry env use python${{ matrix.python_version }} + poetry install --with tests + + - name: Run tests with coverage + run: | + poetry run coverage run -m unittest discover + poetry run coverage report --omit="tests/*" + poetry run coverage xml --omit="tests/*" -o coverage.xml # Report partial coverage results to codacy for the current python version - name: Report partial coverage results + if: github.event_name != 'release' + shell: bash run: bash <(curl -Ls https://coverage.codacy.com/get.sh) report --partial -l Python -r coverage.xml env: CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }} # Tell codacy we are done reporting test coverage report-code-coverage: - name: Report Code Coverage - runs-on: ubuntu-latest + name: Report Coverage + if: github.event_name != 'release' needs: run-tests + runs-on: ubuntu-latest steps: - name: Finish reporting coverage + shell: bash run: bash <(curl -Ls https://coverage.codacy.com/get.sh) final env: CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }} @@ -44,9 +71,9 @@ jobs: # Use this job for branch protection rules report-test-status: name: Report Test Status - runs-on: ubuntu-latest - needs: run-tests if: always() + needs: run-tests + runs-on: ubuntu-latest steps: - name: Check build status if: ${{ contains(needs.*.result, 'failure') }} diff --git a/apps/__init__.py b/apps/__init__.py index f7cd78c..4145b04 100644 --- a/apps/__init__.py +++ b/apps/__init__.py @@ -2,4 +2,8 @@ import importlib.metadata -__version__ = importlib.metadata.version('crc_wrappers') +try: + __version__ = importlib.metadata.version('quota-notifier') + +except importlib.metadata.PackageNotFoundError: # pragma: no cover + __version__ = '0.0.0' diff --git a/apps/crc_scancel.py b/apps/crc_scancel.py index e29e196..dbc0c0b 100755 --- a/apps/crc_scancel.py +++ b/apps/crc_scancel.py @@ -5,8 +5,8 @@ prompt to confirm users are canceling the correct job. """ +import getpass from argparse import Namespace -from os import environ from ._base_parser import BaseParser from .utils.system_info import Shell, SlurmInfo @@ -15,7 +15,7 @@ class CrcScancel(BaseParser): """Cancel a Slurm job submitted by the current user.""" - user = environ['USER'] + user = getpass.getuser() def __init__(self) -> None: """Define arguments for the command line interface""" diff --git a/apps/crc_squeue.py b/apps/crc_squeue.py index e4436ce..5b9146b 100755 --- a/apps/crc_squeue.py +++ b/apps/crc_squeue.py @@ -1,7 +1,7 @@ """A simple wrapper around the Slurm ``squeue`` command.""" +import getpass from argparse import Namespace -from os import environ from time import sleep from ._base_parser import BaseParser @@ -36,7 +36,7 @@ def build_slurm_command(self, args: Namespace) -> str: """ # Variables for building shell commands - user = f"-u {environ['USER']}" + user = f"-u {getpass.getuser()}" # Build the base command command_options = ["squeue -M all"] diff --git a/pyproject.toml b/pyproject.toml index d3457d2..9440cdf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,6 +46,12 @@ crc-usage = "apps.crc_usage:CrcUsage.execute" python = "^3.8.0" dataset = "1.6.0" +[tool.poetry.group.tests] +optional = true + +[tool.poetry.group.tests.dependencies] +coverage="*" + [tool.poetry.group.docs] optional = true diff --git a/tests/test_crc_squeue.py b/tests/test_crc_squeue.py index d96b6e6..f226171 100644 --- a/tests/test_crc_squeue.py +++ b/tests/test_crc_squeue.py @@ -1,6 +1,6 @@ """Tests for the ``crc-squeue`` application.""" -from os import environ +import getpass from unittest import TestCase from apps.crc_squeue import CrcSqueue @@ -27,7 +27,7 @@ def test_all_option(self) -> None: """Test the ``--all`` argument disables ``-u`` in the piped slurm command""" app = CrcSqueue() - slurm_user_argument = "-u {0}".format(environ['USER']) + slurm_user_argument = f'-u {getpass.getuser()}' # The application should default to showing information for the current user args, _ = app.parse_known_args([''])