Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Commit

Permalink
Merge branch 'git-developer-fix-appimage' into python3
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryochan7 committed Nov 7, 2023
2 parents 5c45ca7 + 58e336c commit 87b7d88
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 0 deletions.
102 changes: 102 additions & 0 deletions .github/workflows/appimage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Build and publish AppImages

env:
BASE_OS: ubuntu
BASE_CODENAME: jammy
APT_PUBKEY: 871920D1991BC93C

on:
pull_request:
push:
branches: [ 'main' ]
release:
types: published

jobs:
build:
runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
platform:
- linux/amd64
- linux/arm64

steps:
- uses: actions/checkout@v4
- uses: rlespinasse/github-slug-action@v4

- name: Setup qemu for docker
uses: docker/setup-qemu-action@v2
if: matrix.platform != 'linux/amd64'

- name: Setup buildx for docker
uses: docker/setup-buildx-action@v2

- name: Compile in docker
uses: docker/build-push-action@v4
with:
platforms: ${{ matrix.platform }}
outputs: build
build-args: |
BASE_OS
BASE_CODENAME
- name: Prepare environment to build AppImage
env:
TARGET_PLATFORM: ${{ matrix.platform }}
shell: bash
run: |
set -eua
if [ -r build/.build-metadata.env ]; then
. build/.build-metadata.env
rm build/.build-metadata.env
fi
APPIMAGE_SOURCE=build
APPIMAGE_VERSION="${GITHUB_REF_SLUG}"
APPIMAGE_APT_ARCH="${TARGETARCH}"
APPIMAGE_APT_DISTRO="${BASE_CODENAME}"
APPIMAGE_APT_PUBKEY="${APT_PUBKEY}"
APPIMAGE_ARCH="${TARGETMACHINE}"
printenv | grep ^APPIMAGE_ >>"${GITHUB_ENV}"
- name: Build AppImage
uses: AppImageCrafters/[email protected]

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: appimages
path: |
./*.AppImage
./*.AppImage.zsync
if-no-files-found: error

release:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest

needs:
- build

permissions:
contents: write

steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: appimages
path: assets
- name: Create checksum for release assets
shell: bash
run: |
algo="${SHA_ALGORITHM:-256}"
find assets -type f | while read -r asset; do
shasum --binary --algorithm "${algo}" "${asset}" >"${asset}.sha${algo}"
done
- name: Upload artifacts to GitHub release
uses: softprops/action-gh-release@v1
with:
files: assets/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ appimage/

dist/
sccontroller.egg-info/
!.github
131 changes: 131 additions & 0 deletions AppImageBuilder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
version: 1

script:
- |
if [ "{{APPIMAGE_SOURCE}}" != "${TARGET_APPDIR}" ]; then
mv "{{APPIMAGE_SOURCE}}" "${TARGET_APPDIR}"
fi
# Manual installation of squashfs-tools is required
# until https://github.com/AppImageCrafters/build-appimage/issues/5 is fixed
if ! command -v mksquashfs >/dev/null; then
apt-get update && apt-get install -y --no-install-recommends squashfs-tools
fi
AppDir:
app_info:
id: org.ryochan7.sc-controller
name: sc-controller
version: "{{APPIMAGE_VERSION}}"
icon: sc-controller
exec: usr/bin/python3
exec_args: -c "import os, sys; os.execvp('$APPDIR/usr/bin/scc', ['$APPDIR/usr/bin/scc'] + (sys.argv[1:] if len(sys.argv) > 1 else ['gui']))" $@

after_bundle: |
set -eu
# appimage-builder expects .desktop file to start with appinfo-id
desktop="$(find "${TARGET_APPDIR}/usr" -name sc-controller.desktop)"
sed -i "s:Exec=.*:Exec=./usr/bin/scc gui:g" "${desktop}"
ln -sr "${desktop}" "${TARGET_APPDIR}/usr/share/applications/org.ryochan7.sc-controller.desktop"
# appimage-builder expects utf-8 encoding when patching shebangs,
# but pygettext3 has iso-8859-1 encoding
find "${TARGET_APPDIR}/usr/bin" -name 'pygettext*' | while read -r file; do
encoding="ISO-8859-1"
if file -bi "${file}" | grep -iq "${encoding}"; then
<"${file}" iconv -f "${encoding}" -t utf-8 -o "${file}"
sed -i -E '1,2 s|^(\s*#.*coding[=:]\s*)([[:alnum:].-]+)|\1utf-8|g' "${file}"
fi
done
apt:
arch:
- "{{APPIMAGE_APT_ARCH}}"
sources:
- sourceline: deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ {{APPIMAGE_APT_DISTRO}} main universe
key_url: http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x{{APPIMAGE_APT_PUBKEY}}
- sourceline: deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ {{APPIMAGE_APT_DISTRO}}-updates main universe
- sourceline: deb [arch=amd64] http://security.ubuntu.com/ubuntu/ {{APPIMAGE_APT_DISTRO}}-security main universe
- sourceline: deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ {{APPIMAGE_APT_DISTRO}} main universe
- sourceline: deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ {{APPIMAGE_APT_DISTRO}}-updates main universe
- sourceline: deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ {{APPIMAGE_APT_DISTRO}}-security main universe

include:
- gir1.2-rsvg-2.0
- libbluetooth3
- librsvg2-common
- python3-evdev
- python3-gi-cairo
- python3-pylibacl
- python3-vdf
- binutils # required for detection of bluetooth library
- coreutils # provides /usr/bin/env
- shared-mime-info # required for gui if host provides no MIME info, e.g. when XDG_DATA_DIRS is missing
exclude:
- gcc* # development
- libgcc* # development
- libstdc* # development
- libtirpc* # development
- libuuid* # development
- libattr* # filesystem
- libblkid* # filesystem
- libmount* # filesystem
- libbz* # codec
- libjpeg* # codec
- liblzma* # codec
- libtiff* # codec
- libxml* # codec
- libwebp* # codec
- media-types # codec
- libpixman* # X
- libxext* # X
- libxrender* # X
- libfontconfig* # fonts
- libfreetype* # fonts
- libfribidi* # i18n
- libicu* # i18n
- libgmp* # arithmetics
- libmpdec* # arithmetics
- libncurses* # terminal
- libreadline* # terminal
- readline* # terminal
- libssl* # security
- "*crypt*" # security
- "*krb*" # security
- libdb* # database
- "*sqlite*" # database
- libnsl* # network


files:
exclude:
- usr/bin/*gold* # alternative for ld
- usr/bin/*gp-display-html* # since Ubuntu Lunatic, requires perl
- usr/lib/*/gconv # unicode
- usr/lib/*/gdk-pixbuf-2.0/*/loaders/libpixbufloader-[!s]*.so # only svg is required
- usr/lib/*/glib-2.0
- usr/lib/python*/cgi.py
- usr/lib/python*/email
- usr/lib/python*/test
- usr/lib/python*/unittest
- usr/share/doc
- usr/share/glib-2.0
- usr/share/gtk-doc
- usr/share/icu
- usr/share/locale
- usr/share/man
- usr/share/python3/runtime.d
- usr/share/thumbnailers

runtime:
env:
# `usr/lib/python3.*/site-packages` is required in $PYTHONPATH,
# but the python version and hence the actual location is unknown here.
# Fortunately the site-packages directory is on the $PATH, so we add $PATH instead.
# It must precede an existing $PYTHONPATH to work.
PYTHONPATH: "${APPDIR}/usr/lib/python3/dist-packages:${PATH}:${PYTHONPATH}"
SCC_SHARED: "${APPDIR}/usr/share/scc"

AppImage:
arch: "{{APPIMAGE_ARCH}}"
update-information: "gh-releases-zsync|Ryochan7|sc-controller|latest|sc-controller-*-{{APPIMAGE_ARCH}}.AppImage.zsync"
44 changes: 44 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
ARG BASE_OS=ubuntu
ARG BASE_CODENAME=jammy
FROM $BASE_OS:$BASE_CODENAME AS build-stage

# Download build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc librsvg2-bin linux-headers-generic python3-dev python3-setuptools

# Prepare working directory and target
COPY . /work
WORKDIR /work
ARG TARGET=/build/usr

# Build and install
RUN python3 setup.py build --executable "/usr/bin/env python3" && \
python3 setup.py install --single-version-externally-managed --home "${TARGET}" --record /dev/null

# Provide input-event-codes.h as fallback for runtime systems without linux headers
RUN cp -a \
"$(find /usr -type f -name input-event-codes.h -print -quit)" \
"$(find "${TARGET}" -type f -name uinput.py -printf '%h\n' -quit)"

# Create short name symlinks for static libraries
RUN suffix=".cpython-*-$(uname -m)-linux-gnu.so" && \
find "${TARGET}" -type f -path "*/site-packages/*${suffix}" \
| while read -r path; do ln -sfr "${path}" "${path%${suffix}}.so"; done

# Put AppStream metadata to required location according to https://wiki.debian.org/AppStream/Guidelines
RUN metainfo=/build/usr/share/metainfo && \
mkdir -p "${metainfo}" && \
cp -a scripts/sc-controller.appdata.xml "${metainfo}"

# Convert icon to png format (required for icons in .desktop file)
RUN iconpath="${TARGET}/share/icons/hicolor/512x512/apps" && \
mkdir -p "${iconpath}" && \
rsvg-convert --background-color none -o "${iconpath}/sc-controller.png" images/sc-controller.svg

# Store build metadata
ARG TARGETOS TARGETARCH TARGETVARIANT
RUN export "TARGETMACHINE=$(uname -m)" && printenv | grep ^TARGET >>/build/.build-metadata.env

# Keep only files required for runtime
FROM scratch AS export-stage
COPY --from=build-stage /build /

0 comments on commit 87b7d88

Please sign in to comment.