Skip to content

Convert to composite run steps action #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/lint-shell.yml
Original file line number Diff line number Diff line change
@@ -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
50 changes: 37 additions & 13 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
10 changes: 0 additions & 10 deletions Dockerfile

This file was deleted.

45 changes: 45 additions & 0 deletions action-setup.sh
Original file line number Diff line number Diff line change
@@ -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"
29 changes: 27 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 3 additions & 0 deletions compilesketches/tests/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[run]
omit =
*/.venv/*