Skip to content

Commit

Permalink
feat(ci): set daemon version from setuptools-scm
Browse files Browse the repository at this point in the history
  • Loading branch information
git-developer committed Oct 5, 2024
1 parent e366980 commit 726042d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 44 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/appimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 50
- uses: rlespinasse/github-slug-action@v4
- uses: proudust/gh-describe@v2
id: ghd

- name: Setup qemu for docker
uses: docker/setup-qemu-action@v3
Expand All @@ -61,12 +61,12 @@ jobs:
- name: Compile in docker
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ matrix.target.platform }}
outputs: build
build-args: |
BASE_OS=${{ matrix.base.os }}
BASE_CODENAME=${{ matrix.base.codename }}
GIT_DESCRIPTION=${{ steps.ghd.outputs.describe }}
- name: Prepare environment to build AppImage
env:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ appimage/
dist/
sccontroller.egg-info/
!.github
scc/_version.py
25 changes: 1 addition & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ RUN <<EOR
apt-get update
apt-get install -y --no-install-recommends \
gcc \
git \
librsvg2-bin \
linux-headers-generic \
python3-dev \
Expand All @@ -39,35 +40,11 @@ EOR
COPY . /work
WORKDIR /work
ARG TARGET=/build
ARG DAEMON_VERSION
ARG GIT_DESCRIPTION

# Build and install
RUN <<EOR
set -eu

##
# Converts the output of `git describe` to a valid python version (PEP 440),
# e.g. `v0.4.9.2` to `0.4.9.2` or `ver0.4.8.11-3-123-g030686f` to `0.4.8.11.3.123+g030686f`
##
convert_git_description_to_pep440() {
description="${1}"
hash="${description##*-g}"
version="$(printf %s "${description%-g*}" | tr -c -s [0-9.] .)"
version="${version#.}"
version="${version%.}"
if [ "${hash}" != "${description}" ]; then
version="${version}+g${hash}"
fi
printf '%s\n' "${version}"
}
if [ -z "${DAEMON_VERSION-}" ] && [ "${GIT_DESCRIPTION-}" ]; then
DAEMON_VERSION="$(convert_git_description_to_pep440 "${GIT_DESCRIPTION}")"
fi
if [ "${DAEMON_VERSION-}" ]; then
sed -i -E "s/^ *DAEMON_VERSION *= *.+/DAEMON_VERSION = \"${DAEMON_VERSION}\"/" scc/constants.py
fi

python -m build --wheel
python -m venv .env
. .env/bin/activate
Expand Down
35 changes: 19 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
# TODO migrate files from setup.py - https://setuptools.pypa.io/en/latest/userguide/miscellaneous.html

[build-system]
requires = ["setuptools>=60", "wheel"]
requires = ["setuptools>=60", "setuptools-scm>=8.0", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "sccontroller"
version = "0.4.9.5" # Replace with DAEMON_VERSION or vice versa?
dynamic = ["version"]
description = "User-mode driver, mapper and GTK3 based GUI for Steam Controller, DS4 and similar controllers."
authors = [{name = "C0rn3j", email = "[email protected]"}]
license = {text = "GPL-2.0-only"}
Expand All @@ -22,6 +22,21 @@ classifiers = [
requires-python = ">=3.8"
#platforms = ["Linux"]

# https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#creating-executable-scripts
[project.gui-scripts]
sc-controller = "scc.bin.sc_controller:main"

[project.scripts]
scc-daemon = "scc.bin.scc_daemon:main"
scc = "scc.bin.scc:main"
scc-osd-dialog = "scc.bin.scc_osd_dialog:main"
scc-osd-keyboard = "scc.bin.scc_osd_keyboard:main"
scc-osd-launcher = "scc.bin.scc_osd_launcher:main"
scc-osd-menu = "scc.bin.scc_osd_menu:main"
scc-osd-message = "scc.bin.scc_osd_message:main"
scc-osd-radial-menu = "scc.bin.scc_osd_radial_menu:main"
scc-osd-show-bindings = "scc.bin.scc_osd_show_bindings:main"

[tool.setuptools]
packages = [
"scc",
Expand All @@ -37,20 +52,8 @@ packages = [
"scc.gui.creg"
]

# https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#creating-executable-scripts
[project.gui-scripts]
sc-controller = "scc.bin.sc_controller:main"

[project.scripts]
scc-daemon = "scc.bin.scc_daemon:main"
scc = "scc.bin.scc:main"
scc-osd-dialog = "scc.bin.scc_osd_dialog:main"
scc-osd-keyboard = "scc.bin.scc_osd_keyboard:main"
scc-osd-launcher = "scc.bin.scc_osd_launcher:main"
scc-osd-menu = "scc.bin.scc_osd_menu:main"
scc-osd-message = "scc.bin.scc_osd_message:main"
scc-osd-radial-menu = "scc.bin.scc_osd_radial_menu:main"
scc-osd-show-bindings = "scc.bin.scc_osd_show_bindings:main"
[tool.setuptools_scm]
version_file = "scc/_version.py"

[tool.ruff]
# Target non-EOL releases at minimum, or later if needed
Expand Down
3 changes: 2 additions & 1 deletion scc/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
# THE SOFTWARE.

from enum import IntEnum
from scc._version import __version__

"""
If SC-Controller is updated while daemon is running, DAEMON_VERSION send by
daemon will differ one one expected by UI and daemon will be forcefully restarted.
"""
DAEMON_VERSION = "0.4.9.5"
DAEMON_VERSION = __version__

HPERIOD = 0.02
LPERIOD = 0.5
Expand Down

0 comments on commit 726042d

Please sign in to comment.