diff --git a/.github/workflows/lint-shell.yml b/.github/workflows/lint-shell.yml new file mode 100644 index 00000000..d0a6c283 --- /dev/null +++ b/.github/workflows/lint-shell.yml @@ -0,0 +1,24 @@ +name: Lint shell scripts + +on: + push: + paths: + - '.github/workflows/lint-shell.yml' + - '**.sh' + pull_request: + paths: + - '.github/workflows/lint-shell.yml' + - '**.sh' + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + # Recursively lint all shell scripts in the repository + # See: https://github.com/azohra/shell-linter/blob/latest/README.md + - name: ShellCheck + uses: azohra/shell-linter@latest diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index a2658145..22895e0f 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -4,15 +4,16 @@ on: pull_request: paths: - '.github/workflows/test-python.yml' + - 'action-setup.sh' - 'compilesketches/**' push: paths: - '.github/workflows/test-python.yml' + - 'action-setup.sh' - 'compilesketches/**' - # The actions/setup-python action will periodically break the workflow by dropping the Python version we have pinned - # Better to catch that before it causes confusion for a contributor + # Catch issues resulting from new patch releases of Python in the APT repository schedule: # run every Tuesday at 3 AM UTC - cron: "0 3 * * 2" @@ -32,29 +33,52 @@ jobs: env: PYTHON_PROJECT_PATH: ${GITHUB_WORKSPACE}/compilesketches PYTHON_PROJECT_TESTS_PATH: ${GITHUB_WORKSPACE}/compilesketches/tests + COVERAGE_DATA_FILENAME: coverage.xml steps: - name: Checkout uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v1 - with: - python-version: '3.8.6' + - name: Run the set up script + id: setup + run: | + "${{ github.workspace }}/action-setup.sh" - - name: Install dependencies + - name: Install test dependencies run: | - python -m pip install --upgrade pip - pip install --requirement "${{ env.PYTHON_PROJECT_TESTS_PATH }}/requirements.txt" + source "${{ steps.setup.outputs.python-venv-activate-script-path }}" + "${{ steps.setup.outputs.python-command }}" \ + -m \ + pip install \ + --requirement "${{ env.PYTHON_PROJECT_TESTS_PATH }}/requirements.txt" - - name: Run Python unit tests and report code coverage + - name: Run Python unit tests and record code coverage data run: | + source "${{ steps.setup.outputs.python-venv-activate-script-path }}" export PYTHONPATH="${{ env.PYTHON_PROJECT_PATH }}" - coverage run --source="${{ env.PYTHON_PROJECT_PATH }}" --module pytest "${{ env.PYTHON_PROJECT_TESTS_PATH }}" - # Display code coverage report in workflow run log - coverage report + "${{ steps.setup.outputs.python-command }}" \ + -m \ + coverage run \ + --rcfile="${{ env.PYTHON_PROJECT_TESTS_PATH }}/.coveragerc" \ + --source="${{ env.PYTHON_PROJECT_PATH }}" \ + --module \ + pytest "${{ env.PYTHON_PROJECT_TESTS_PATH }}" + # Generate coverage data file for consumption by `codecov/codecov-action`. + # Otherwise that action generates the file using the system Python environment, which doesn't work. + "${{ steps.setup.outputs.python-command }}" \ + -m \ + coverage xml \ + -o "${{ github.workspace }}/${{ env.COVERAGE_DATA_FILENAME }}" + + - name: Display code coverage report + run: | + source "${{ steps.setup.outputs.python-venv-activate-script-path }}" + "${{ steps.setup.outputs.python-command }}" \ + -m \ + coverage report - name: Upload coverage report to Codecov uses: codecov/codecov-action@v1 with: + file: ${{ env.COVERAGE_DATA_FILENAME }} fail_ci_if_error: true diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 45164514..00000000 --- a/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM python:3.8.6 - -# Copies your code file from your action repository to the filesystem path `/` of the container -COPY compilesketches /compilesketches - -# Install python dependencies -RUN pip install -r /compilesketches/requirements.txt - -# Code file to execute when the docker container starts up -ENTRYPOINT ["python", "/compilesketches/compilesketches.py"] diff --git a/action-setup.sh b/action-setup.sh new file mode 100755 index 00000000..4022b68f --- /dev/null +++ b/action-setup.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +# Set up the Python environment for the action's script to run in + +readonly PYTHON_PACKAGE_VERSION='3.8' + +# https://stackoverflow.com/a/29835459 +readonly SCRIPT_PATH="$( + CDPATH='' \ + cd -- "$( + dirname -- "$0" + )" && ( + pwd -P + ) +)" + +readonly PYTHON_COMMAND="python${PYTHON_PACKAGE_VERSION}" +readonly PYTHON_VENV_PATH="${SCRIPT_PATH}/compilesketches/.venv" +readonly PYTHON_VENV_ACTIVATE_SCRIPT_PATH="${PYTHON_VENV_PATH}/bin/activate" + +# Install Python +sudo apt-get install --yes software-properties-common > /dev/null +sudo add-apt-repository --yes ppa:deadsnakes/ppa > /dev/null +sudo apt-get update --yes > /dev/null +sudo apt-get install --yes python${PYTHON_PACKAGE_VERSION} > /dev/null +echo "Using Python version: $("$PYTHON_COMMAND" --version)" + +sudo apt-get install --yes python3-setuptools > /dev/null +sudo apt-get install --yes python${PYTHON_PACKAGE_VERSION}-venv > /dev/null + +# Create Python virtual environment +"$PYTHON_COMMAND" -m venv "$PYTHON_VENV_PATH" + +# Activate Python virtual environment +# shellcheck source=/dev/null +. "$PYTHON_VENV_ACTIVATE_SCRIPT_PATH" + +# Install Python dependencies +"$PYTHON_COMMAND" -m pip install --upgrade pip > /dev/null +"$PYTHON_COMMAND" -m pip install --quiet --requirement "${SCRIPT_PATH}/compilesketches/requirements.txt" + +# Set outputs for use in GitHub Actions workflow steps +# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-output-parameter +echo "::set-output name=python-command::$PYTHON_COMMAND" +echo "::set-output name=python-venv-activate-script-path::$PYTHON_VENV_ACTIVATE_SCRIPT_PATH" diff --git a/action.yml b/action.yml index d0966048..7bbb4c7b 100644 --- a/action.yml +++ b/action.yml @@ -43,5 +43,30 @@ inputs: required: true runs: - using: 'docker' - image: 'Dockerfile' + using: composite + steps: + - name: Run the set up script + id: setup + shell: bash + run: | + # Group action setup log output + echo "::group::Action set up" + "${{ github.action_path }}/action-setup.sh" + echo "::endgroup::" + + - name: Run script + shell: bash + env: + INPUT_CLI-VERSION: ${{ inputs.cli-version }} + INPUT_FQBN: ${{ inputs.fqbn }} + INPUT_LIBRARIES: ${{ inputs.libraries }} + INPUT_PLATFORMS: ${{ inputs.platforms }} + INPUT_SKETCH-PATHS: ${{ inputs.sketch-paths }} + INPUT_VERBOSE: ${{ inputs.verbose }} + INPUT_GITHUB-TOKEN: ${{ inputs.github-token }} + INPUT_ENABLE-DELTAS-REPORT: ${{ inputs.enable-deltas-report }} + INPUT_ENABLE-WARNINGS-REPORT: ${{ inputs.enable-warnings-report }} + INPUT_SKETCHES-REPORT-PATH: ${{ inputs.sketches-report-path }} + run: | + source "${{ steps.setup.outputs.python-venv-activate-script-path }}" + "${{ steps.setup.outputs.python-command }}" "${{ github.action_path }}/compilesketches/compilesketches.py" diff --git a/compilesketches/tests/.coveragerc b/compilesketches/tests/.coveragerc new file mode 100644 index 00000000..9ca48dd2 --- /dev/null +++ b/compilesketches/tests/.coveragerc @@ -0,0 +1,3 @@ +[run] +omit = + */.venv/*