Files
meshcore-tth/.github/actions/setup-build-environment/action.yml
T
2026-11-30 19:54:58 +01:00

61 lines
2.3 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
# CUSTOM (TeTeHacko): no actions/setup-python (upstream: '3.13'). Its
# Python for Ubuntu 26.04, the runner image, is built for x86-64-v3 and
# grg-runner (Xeon E5-2630L v2) has only v2: "CPU ISA level is lower than
# required" on every run. The image's own python3 runs anywhere and the
# build needs no particular 3.x, so the build runs in a venv of it.
- name: Install Python
shell: bash
run: |
set -euo pipefail
SUDO="$(command -v sudo || true)"
venv="$RUNNER_TEMP/pyenv"
if ! python3 -m venv "$venv"; then
$SUDO apt-get update -qq
$SUDO 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
$SUDO apt-get update -qq
$SUDO 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