feat: baking version into CI #22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build .deb Package for Raspberry Pi | |
| on: | |
| push: | |
| branches: [master] | |
| permissions: | |
| contents: write | |
| env: | |
| PKG_NAME: intercom-client | |
| PKG_ARCH: arm64 | |
| PKG_DEPENDS: "libgstreamer1.0-0, gstreamer1.0-plugins-base, gstreamer1.0-plugins-good, libv4l-0" | |
| jobs: | |
| test: | |
| name: Run tests | |
| runs-on: ubuntu-22.04-arm | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v7 | |
| with: | |
| enable-cache: true | |
| cache-dependency-glob: uv.lock | |
| - name: Install dependencies | |
| run: uv sync | |
| - name: Run tests | |
| run: uv run pytest | |
| build: | |
| name: Build .deb | |
| needs: test | |
| runs-on: ubuntu-22.04-arm | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v7 | |
| with: | |
| enable-cache: true | |
| cache-dependency-glob: uv.lock | |
| - name: Install project dependencies | |
| run: uv sync | |
| - name: Install Nuitka | |
| run: uv pip install nuitka | |
| - name: Cache Nuitka build output | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| dist/ | |
| build/ | |
| main.build/ | |
| main.dist/ | |
| main.onefile-build/ | |
| key: nuitka-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('uv.lock', 'main.py', 'intercomclient/**/*.py') }} | |
| - name: Build native binary with Nuitka | |
| run: > | |
| uv run python -m nuitka | |
| --standalone | |
| --onefile | |
| --output-filename=intercom-client | |
| --output-dir=dist | |
| --include-package=intercomclient | |
| --include-package=aiortc | |
| --include-package=av | |
| --include-package=cv2 | |
| --include-package=numpy | |
| --include-package=websockets | |
| --include-package=requests | |
| --include-package=jsonschema | |
| --include-package=boto3 | |
| --include-package=botocore | |
| --include-package=cryptography | |
| --include-package=cffi | |
| --include-package=jmespath | |
| --include-package=transparenc_sdk | |
| --include-package-data=opencv_python.libs | |
| --include-package-data=cv2 | |
| main.py | |
| - name: Build .deb package | |
| run: | | |
| set -euo pipefail | |
| APP_VERSION=$(cat VERSION) | |
| # Debian package versions can't contain '+'; '~' sorts correctly as pre-release | |
| PKG_VERSION=$(echo "$APP_VERSION" | tr '+' '~') | |
| PKG_DIR="dist/${PKG_NAME}_${PKG_VERSION}_${PKG_ARCH}" | |
| DEB_FILE="${PKG_DIR}.deb" | |
| mkdir -p "${PKG_DIR}/usr/local/bin" | |
| mkdir -p "${PKG_DIR}/lib/systemd/system" | |
| mkdir -p "${PKG_DIR}/etc/intercom-client" | |
| mkdir -p "${PKG_DIR}/DEBIAN" | |
| cp dist/intercom-client "${PKG_DIR}/usr/local/bin/" | |
| chmod 755 "${PKG_DIR}/usr/local/bin/intercom-client" | |
| cat > "${PKG_DIR}/DEBIAN/control" <<EOF | |
| Package: ${PKG_NAME} | |
| Version: ${PKG_VERSION} | |
| Section: net | |
| Priority: optional | |
| Architecture: ${PKG_ARCH} | |
| Depends: ${PKG_DEPENDS} | |
| Maintainer: Intercom Team | |
| Description: Intercom Pi client for WebRTC live streaming | |
| Raspberry Pi client that connects to the intercom signaling server | |
| and streams live video via WebRTC. | |
| EOF | |
| cat > "${PKG_DIR}/etc/intercom-client/env" <<EOF | |
| # Intercom Client Configuration | |
| # Set your environment variables here — these are sourced by the systemd service. | |
| # | |
| # OAUTH_CLIENT_ID=your_client_id | |
| # OAUTH_CLIENT_SECRET=your_client_secret | |
| # VIDEO_SOURCE=0 | |
| # TOKEN_FILE_PATH=/home/pi/.config/intercom-client/tokens.json | |
| # WEBSOCKET_API_BASE_URL=wss://your-server.com/ws/live_stream | |
| # HTTP_API_BASE_URL=https://your-server.com | |
| EOF | |
| cat > "${PKG_DIR}/lib/systemd/system/intercom-client.service" <<EOF | |
| [Unit] | |
| Description=Intercom Pi Client | |
| After=network-online.target | |
| Wants=network-online.target | |
| [Service] | |
| Type=simple | |
| User=pi | |
| Group=pi | |
| EnvironmentFile=-/etc/intercom-client/env | |
| ExecStart=/usr/local/bin/intercom-client | |
| Restart=on-failure | |
| RestartSec=10 | |
| [Install] | |
| WantedBy=multi-user.target | |
| EOF | |
| dpkg-deb --build "${PKG_DIR}" | |
| echo "--- Built package ---" | |
| ls -lh "${DEB_FILE}" | |
| echo "" | |
| echo "--- Package contents ---" | |
| dpkg-deb --contents "${DEB_FILE}" | |
| echo "" | |
| echo "--- Package info ---" | |
| dpkg-deb --info "${DEB_FILE}" | |
| - name: Upload .deb artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: intercom-client-deb | |
| path: dist/intercom-client_*.deb | |
| retention-days: 30 | |
| - name: Log in to private Docker registry | |
| run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login docker.kmanning.ie:5000 -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin | |
| - name: Build and push Docker image | |
| run: | | |
| IMAGE=docker.kmanning.ie:5000/intercom-python-client | |
| APP_VERSION=$(cat VERSION) | |
| DOCKER_TAG=$(echo "$APP_VERSION" | tr '+' '-') | |
| docker build \ | |
| --build-arg APP_VERSION="$APP_VERSION" \ | |
| -f Dockerfile \ | |
| -t "$IMAGE:latest" \ | |
| -t "$IMAGE:${{ github.sha }}" \ | |
| -t "$IMAGE:$DOCKER_TAG" \ | |
| . | |
| docker push "$IMAGE:latest" | |
| docker push "$IMAGE:${{ github.sha }}" | |
| docker push "$IMAGE:$DOCKER_TAG" |