Skip to content

Commit f31b227

Browse files
authored
Merge pull request #14 from per1234/composite-run-steps
Convert to composite run steps action
2 parents 106113e + 99a1a92 commit f31b227

File tree

6 files changed

+136
-25
lines changed

6 files changed

+136
-25
lines changed

.github/workflows/lint-shell.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Lint shell scripts
2+
3+
on:
4+
push:
5+
paths:
6+
- '.github/workflows/lint-shell.yml'
7+
- '**.sh'
8+
pull_request:
9+
paths:
10+
- '.github/workflows/lint-shell.yml'
11+
- '**.sh'
12+
13+
jobs:
14+
lint:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v2
20+
21+
# Recursively lint all shell scripts in the repository
22+
# See: https://github.com/azohra/shell-linter/blob/latest/README.md
23+
- name: ShellCheck
24+
uses: azohra/shell-linter@latest

.github/workflows/test-python.yml

+37-13
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ on:
44
pull_request:
55
paths:
66
- '.github/workflows/test-python.yml'
7+
- 'action-setup.sh'
78
- 'compilesketches/**'
89

910
push:
1011
paths:
1112
- '.github/workflows/test-python.yml'
13+
- 'action-setup.sh'
1214
- 'compilesketches/**'
1315

14-
# The actions/setup-python action will periodically break the workflow by dropping the Python version we have pinned
15-
# Better to catch that before it causes confusion for a contributor
16+
# Catch issues resulting from new patch releases of Python in the APT repository
1617
schedule:
1718
# run every Tuesday at 3 AM UTC
1819
- cron: "0 3 * * 2"
@@ -32,29 +33,52 @@ jobs:
3233
env:
3334
PYTHON_PROJECT_PATH: ${GITHUB_WORKSPACE}/compilesketches
3435
PYTHON_PROJECT_TESTS_PATH: ${GITHUB_WORKSPACE}/compilesketches/tests
36+
COVERAGE_DATA_FILENAME: coverage.xml
3537

3638
steps:
3739
- name: Checkout
3840
uses: actions/checkout@v2
3941

40-
- name: Set up Python
41-
uses: actions/setup-python@v1
42-
with:
43-
python-version: '3.8.6'
42+
- name: Run the set up script
43+
id: setup
44+
run: |
45+
"${{ github.workspace }}/action-setup.sh"
4446
45-
- name: Install dependencies
47+
- name: Install test dependencies
4648
run: |
47-
python -m pip install --upgrade pip
48-
pip install --requirement "${{ env.PYTHON_PROJECT_TESTS_PATH }}/requirements.txt"
49+
source "${{ steps.setup.outputs.python-venv-activate-script-path }}"
50+
"${{ steps.setup.outputs.python-command }}" \
51+
-m \
52+
pip install \
53+
--requirement "${{ env.PYTHON_PROJECT_TESTS_PATH }}/requirements.txt"
4954
50-
- name: Run Python unit tests and report code coverage
55+
- name: Run Python unit tests and record code coverage data
5156
run: |
57+
source "${{ steps.setup.outputs.python-venv-activate-script-path }}"
5258
export PYTHONPATH="${{ env.PYTHON_PROJECT_PATH }}"
53-
coverage run --source="${{ env.PYTHON_PROJECT_PATH }}" --module pytest "${{ env.PYTHON_PROJECT_TESTS_PATH }}"
54-
# Display code coverage report in workflow run log
55-
coverage report
59+
"${{ steps.setup.outputs.python-command }}" \
60+
-m \
61+
coverage run \
62+
--rcfile="${{ env.PYTHON_PROJECT_TESTS_PATH }}/.coveragerc" \
63+
--source="${{ env.PYTHON_PROJECT_PATH }}" \
64+
--module \
65+
pytest "${{ env.PYTHON_PROJECT_TESTS_PATH }}"
66+
# Generate coverage data file for consumption by `codecov/codecov-action`.
67+
# Otherwise that action generates the file using the system Python environment, which doesn't work.
68+
"${{ steps.setup.outputs.python-command }}" \
69+
-m \
70+
coverage xml \
71+
-o "${{ github.workspace }}/${{ env.COVERAGE_DATA_FILENAME }}"
72+
73+
- name: Display code coverage report
74+
run: |
75+
source "${{ steps.setup.outputs.python-venv-activate-script-path }}"
76+
"${{ steps.setup.outputs.python-command }}" \
77+
-m \
78+
coverage report
5679
5780
- name: Upload coverage report to Codecov
5881
uses: codecov/codecov-action@v1
5982
with:
83+
file: ${{ env.COVERAGE_DATA_FILENAME }}
6084
fail_ci_if_error: true

Dockerfile

-10
This file was deleted.

action-setup.sh

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/sh
2+
3+
# Set up the Python environment for the action's script to run in
4+
5+
readonly PYTHON_PACKAGE_VERSION='3.8'
6+
7+
# https://stackoverflow.com/a/29835459
8+
readonly SCRIPT_PATH="$(
9+
CDPATH='' \
10+
cd -- "$(
11+
dirname -- "$0"
12+
)" && (
13+
pwd -P
14+
)
15+
)"
16+
17+
readonly PYTHON_COMMAND="python${PYTHON_PACKAGE_VERSION}"
18+
readonly PYTHON_VENV_PATH="${SCRIPT_PATH}/compilesketches/.venv"
19+
readonly PYTHON_VENV_ACTIVATE_SCRIPT_PATH="${PYTHON_VENV_PATH}/bin/activate"
20+
21+
# Install Python
22+
sudo apt-get install --yes software-properties-common > /dev/null
23+
sudo add-apt-repository --yes ppa:deadsnakes/ppa > /dev/null
24+
sudo apt-get update --yes > /dev/null
25+
sudo apt-get install --yes python${PYTHON_PACKAGE_VERSION} > /dev/null
26+
echo "Using Python version: $("$PYTHON_COMMAND" --version)"
27+
28+
sudo apt-get install --yes python3-setuptools > /dev/null
29+
sudo apt-get install --yes python${PYTHON_PACKAGE_VERSION}-venv > /dev/null
30+
31+
# Create Python virtual environment
32+
"$PYTHON_COMMAND" -m venv "$PYTHON_VENV_PATH"
33+
34+
# Activate Python virtual environment
35+
# shellcheck source=/dev/null
36+
. "$PYTHON_VENV_ACTIVATE_SCRIPT_PATH"
37+
38+
# Install Python dependencies
39+
"$PYTHON_COMMAND" -m pip install --upgrade pip > /dev/null
40+
"$PYTHON_COMMAND" -m pip install --quiet --requirement "${SCRIPT_PATH}/compilesketches/requirements.txt"
41+
42+
# Set outputs for use in GitHub Actions workflow steps
43+
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-output-parameter
44+
echo "::set-output name=python-command::$PYTHON_COMMAND"
45+
echo "::set-output name=python-venv-activate-script-path::$PYTHON_VENV_ACTIVATE_SCRIPT_PATH"

action.yml

+27-2
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,30 @@ inputs:
4343
required: true
4444

4545
runs:
46-
using: 'docker'
47-
image: 'Dockerfile'
46+
using: composite
47+
steps:
48+
- name: Run the set up script
49+
id: setup
50+
shell: bash
51+
run: |
52+
# Group action setup log output
53+
echo "::group::Action set up"
54+
"${{ github.action_path }}/action-setup.sh"
55+
echo "::endgroup::"
56+
57+
- name: Run script
58+
shell: bash
59+
env:
60+
INPUT_CLI-VERSION: ${{ inputs.cli-version }}
61+
INPUT_FQBN: ${{ inputs.fqbn }}
62+
INPUT_LIBRARIES: ${{ inputs.libraries }}
63+
INPUT_PLATFORMS: ${{ inputs.platforms }}
64+
INPUT_SKETCH-PATHS: ${{ inputs.sketch-paths }}
65+
INPUT_VERBOSE: ${{ inputs.verbose }}
66+
INPUT_GITHUB-TOKEN: ${{ inputs.github-token }}
67+
INPUT_ENABLE-DELTAS-REPORT: ${{ inputs.enable-deltas-report }}
68+
INPUT_ENABLE-WARNINGS-REPORT: ${{ inputs.enable-warnings-report }}
69+
INPUT_SKETCHES-REPORT-PATH: ${{ inputs.sketches-report-path }}
70+
run: |
71+
source "${{ steps.setup.outputs.python-venv-activate-script-path }}"
72+
"${{ steps.setup.outputs.python-command }}" "${{ github.action_path }}/compilesketches/compilesketches.py"

compilesketches/tests/.coveragerc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[run]
2+
omit =
3+
*/.venv/*

0 commit comments

Comments
 (0)