66 lines
2.2 KiB
YAML
66 lines
2.2 KiB
YAML
name: Setup Build Environment
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
|
|
- name: Init Cache
|
|
uses: actions/cache@v5
|
|
with:
|
|
path: |
|
|
~/.cache/pip
|
|
~/.platformio/.cache
|
|
key: ${{ runner.os }}-pio
|
|
|
|
- name: Install Python
|
|
id: python
|
|
continue-on-error: true
|
|
uses: actions/setup-python@v6
|
|
with:
|
|
python-version: '3.13'
|
|
|
|
# CUSTOM (TeTeHacko): setup-python's build for the runner OS can need a
|
|
# newer CPU than the runner host has ("CPU ISA level is lower than
|
|
# required"); fall back to the image's own python3 in a venv
|
|
- name: Python fallback
|
|
if: steps.python.outcome == 'failure'
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
venv="$RUNNER_TEMP/pyenv"
|
|
if ! python3 -m venv "$venv"; then
|
|
apt-get update -qq
|
|
apt-get install -y -qq python3 python3-venv
|
|
python3 -m venv --clear "$venv"
|
|
fi
|
|
# The image's python is often newer than the wheels on PyPI (detools
|
|
# 0.53.0 has none for 3.14): pip then builds from source and needs the
|
|
# headers, which the image does not ship.
|
|
inc="$("$venv/bin/python" -c 'import sysconfig; print(sysconfig.get_paths()["include"])')"
|
|
if [ ! -e "$inc/Python.h" ]; then
|
|
apt-get update -qq
|
|
apt-get install -y -qq python3-dev
|
|
fi
|
|
echo "$venv/bin" >>"$GITHUB_PATH"
|
|
"$venv/bin/python" --version
|
|
|
|
- name: Install PlatformIO
|
|
shell: bash
|
|
run: |
|
|
pip install --upgrade platformio
|
|
|
|
# a git tag of "room-server-v1.2.3" should set "v1.2.3" as GIT_TAG_VERSION
|
|
- name: Extract Version from Git Tag
|
|
shell: bash
|
|
run: |
|
|
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
|
|
# triggered by a tag push (e.g: refs/tags/companion-v1.2.3)
|
|
GIT_TAG_NAME="${GITHUB_REF#refs/tags/}"
|
|
VERSION_STRING="${GIT_TAG_NAME##*-}"
|
|
else
|
|
# triggered by a workflow dispatch (e.g: refs/heads/main)
|
|
# strip "refs/heads/" prefix and replace any remaining "/" with "-" to protect file paths
|
|
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
|
|
VERSION_STRING=$(echo "$BRANCH_NAME" | tr '/' '-')
|
|
fi
|
|
echo "GIT_TAG_VERSION=${VERSION_STRING}" >> $GITHUB_ENV
|