Skip to content

Commit 6ffb86d

Browse files
committed
Convert to composite run steps action
When the action was created, the only option for non-JavaScript actions was to use a Docker container. However, GitHub recently added a new action type: the "composite run steps action": https://docs.github.com/en/free-pro-team@latest/actions/creating-actions/creating-a-composite-run-steps-action The Docker container approach has the significant advantage of providing a controlled environment for the action to run in, which will not pollute the general environment of the runner for later workflow steps. However it also has a couple disadvantages: - Docker container actions can only execute on runners with a Linux operating system. - The workspace is mounted to a folder in the container named `/github/workspace`. The problem with the first is it prevents testing for other operating systems. Arduino boards platforms have different toolchains and even build properties according to operating system of the machine they are running on. Only testing on a Linux system may result in missing issues that affect the majority of users. Although more still needs to be done to make the action cross-platform, converting to a composite run steps action is the first step toward that goal. The problem with the second is that, in order to be valid, an Arduino sketch folder must match the filename of the primary sketch file. For a sketch in the root of the repository, a sketch author might achieve this to some limited extent by naming the repository to match the primary sketch file name. However, the container volume is not named according to the repository name, so sketches in the root of the repository are not currently supported by the action (except in the unlikely event the sketch happens to be named "workspace"). Even though structuring sketch repositories in this manner is not best practices due to GitHub's popular "Download ZIP" appending the Git ref to the end of the folder name, the purpose of this action is to compile sketches, not legislate repository policy, so it is reasonable to support this use case. The workspace folder in the GitHub Actions runner is named according to the repository name, meaning that converting to a composite run steps action permits use with sketches in the root of the repository.
1 parent 106113e commit 6ffb86d

File tree

3 files changed

+71
-12
lines changed

3 files changed

+71
-12
lines changed

Dockerfile

-10
This file was deleted.

action-setup.sh

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
. "$PYTHON_VENV_ACTIVATE_SCRIPT_PATH"
36+
37+
# Install Python dependencies
38+
"$PYTHON_COMMAND" -m pip install --upgrade pip > /dev/null
39+
"$PYTHON_COMMAND" -m pip install --quiet --requirement "${SCRIPT_PATH}/compilesketches/requirements.txt"
40+
41+
# Set outputs for use in GitHub Actions workflow steps
42+
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-output-parameter
43+
echo "::set-output name=python-command::$PYTHON_COMMAND"
44+
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"

0 commit comments

Comments
 (0)