From 3746d117805a173573626af0805a89d00e2d6de1 Mon Sep 17 00:00:00 2001 From: mstechly Date: Thu, 8 Sep 2022 10:18:48 -0400 Subject: [PATCH] Squashed 'subtrees/z_quantum_actions/' changes from 5d4c008..5b664df 5b664df Removed code associated with codecov. 5bfa0bc ci: Windows Support (#30) f19a9ee Show offline code coverage report in 'TestCoverage' workflow (#28) git-subtree-dir: subtrees/z_quantum_actions git-subtree-split: 5b664dfaa021497c8745b92cb7a42f21e81f2575 --- Makefile | 39 ++++++++++++++++++++++++++------- actions/coverage/action.yml | 34 ---------------------------- workflow-templates/coverage.yml | 36 +++++++++++++++++++++++------- 3 files changed, 59 insertions(+), 50 deletions(-) delete mode 100644 actions/coverage/action.yml diff --git a/Makefile b/Makefile index adffcdc..4fbe5f8 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ ################################################################################ # © Copyright 2021-2022 Zapata Computing Inc. ################################################################################ -TOP_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) +TOP_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) include $(TOP_DIR)/variables.mk # This target will list the possible valid targets available. @@ -12,9 +12,22 @@ default: @grep -E '^\w+(\-default)?:' $(TOP_DIR)/$(firstword $(MAKEFILE_LIST)) \ | sed -r 's/-default//g; /default/d ; s/(.*)/\t make \1/g ; s/:.*$$//g' - export VENV_NAME := my_little_venv -PYTHON := $(shell PATH="${VENV_NAME}/bin:${PATH}" python3 -c 'import sys; print(sys.executable)') +ifeq ($(OS), Windows_NT) + VENV_BINDIR := Scripts + PYTHON_EXE := python.exe + # A workaround for Windows and Bash: + # By default, PATH will give the Windows Path, but we need to get the Path for the shell we'll be using + SHELL_PATH := $(shell env echo $$PATH) + PYTHON := $(shell env PATH="${VENV_NAME}/${VENV_BINDIR}:${SHELL_PATH}" ${PYTHON_EXE} -c 'import sys; print(sys.executable)') + # Convert a Windows path to a Unix path for Windows Github Actions + PYTHON := /$(subst \,/,$(subst :\,/,$(PYTHON))) +else + VENV_BINDIR := bin + PYTHON_EXE := python3 + PYTHON := $(shell env PATH="${VENV_NAME}/${VENV_BINDIR}:${PATH}" ${PYTHON_EXE} -c 'import sys; print(sys.executable)') +endif + REPO := $(shell git config --get remote.origin.url) PYTHON_MOD := $(shell find src -maxdepth 3 -mindepth 3 -type d | sed '/.*cache/d; s/src\/python\/// ; s/\//./') PACKAGE_NAME := "foo" @@ -59,9 +72,9 @@ dev-default: clean # `python3` here as it's more explicit, because $(PYTHON) would evaluate to # something else after executing this task, which might be confusing. github_actions-default: - python3 -m venv ${VENV_NAME} && \ - ${VENV_NAME}/bin/python3 -m pip install --upgrade pip && \ - ${VENV_NAME}/bin/python3 -m pip install -e '.[dev]' + ${PYTHON_EXE} -m venv ${VENV_NAME} + "${VENV_NAME}/${VENV_BINDIR}/${PYTHON_EXE}" -m pip install --upgrade pip + "${VENV_NAME}/${VENV_BINDIR}/${PYTHON_EXE}" -m pip install -e '.[dev]' # flake8p is a wrapper library that runs flake8 from config in pyproject.toml # we can now use it instead of flake8 to lint the code @@ -81,15 +94,25 @@ isort-default: clean test-default: $(PYTHON) -m pytest tests + +# Option explanation: +# - '--cov=src' - turn on measuring code coverage. It outputs the results in a +# '.coverage' binary file. It's passed to other commands like +# 'python -m coverage report' coverage-default: $(PYTHON) -m pytest \ --cov=src \ --cov-fail-under=$(MIN_COVERAGE) tests \ --no-cov-on-fail \ - --cov-report xml \ && echo Code coverage Passed the $(MIN_COVERAGE)% mark! +# Reads the code coverage stats from '.coverage' file and prints a textual, +# human-readable report to stdout. +show-coverage-text-report-default: + $(PYTHON) -m coverage report --show-missing + + style-default: flake8p mypy black isort @echo This project passes style! @@ -100,7 +123,7 @@ build-system-deps-default: : get-next-version-default: github_actions - ${VENV_NAME}/bin/python3 subtrees/z_quantum_actions/bin/get_next_version.py $(PACKAGE_NAME) + $(PYTHON) subtrees/z_quantum_actions/bin/get_next_version.py $(PACKAGE_NAME) # This is what converts the -default targets into base target names. # Do not remove!!! diff --git a/actions/coverage/action.yml b/actions/coverage/action.yml deleted file mode 100644 index a94fcc1..0000000 --- a/actions/coverage/action.yml +++ /dev/null @@ -1,34 +0,0 @@ -inputs: - codecov_secret: - description: | - Should be copy of secrets.CODECOV_TOKEN from calling environment. - required: true - -runs: - using: "composite" - steps: - - # Load a specific version of Python - - name: Setup python - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python }} - architecture: x64 - - - name: Install deps - shell: bash - run: make github_actions - env: - SSH_AUTH_SOCK: /tmp/ssh_agent.sock - - - name: Run test coverage - shell: bash - run: make coverage - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v2 - env: - CODECOV_TOKEN: ${{ inputs.codecov_secret }} - with: - files: ./.coverage,./coverage.xml - fail_ci_if_error: trueyml diff --git a/workflow-templates/coverage.yml b/workflow-templates/coverage.yml index bca9e27..398011a 100644 --- a/workflow-templates/coverage.yml +++ b/workflow-templates/coverage.yml @@ -17,25 +17,45 @@ on: jobs: # The job ID has to match repo settings for PR required checks TestCoverage: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} - # Run jobs for a couple of Python versions. + # Run jobs for a couple of Python versions and OSes. strategy: matrix: + os: ["ubuntu-latest", "windows-latest"] python: ["3.8", "3.9", "3.10"] - name: TestCoverage - Python ${{ matrix.python }} + name: Coverage - Python ${{ matrix.python }} - ${{ matrix.os }} steps: - uses: actions/checkout@v2 + # Load a specific version of Python + - name: Setup python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python }} + architecture: x64 + # ------------------------------------------------------------------------ # Loads private SSH key to the SSH agent. Allows to install dependencies # from private git repos, but requires setting `secrets.SSH_PRIVATE_KEY` # in repo settings. # ------------------------------------------------------------------------ - # - uses: ./subtrees/z_quantum_actions/actions/ssh_setup - # with: - # ssh_key: ${{ secrets.SSH_PRIVATE_KEY }} - - - uses: ./subtrees/z_quantum_actions/actions/coverage + - uses: ./subtrees/z_quantum_actions/actions/ssh_setup + with: + ssh_key: ${{ secrets.SSH_PRIVATE_KEY }} + + - name: Install deps + shell: bash + run: make github_actions + env: + SSH_AUTH_SOCK: /tmp/ssh_agent.sock + + - name: Run tests and gather coverage stats + shell: bash + run: make coverage + + - name: Print code coverage report + shell: bash + run: make show-coverage-text-report