Skip to content

Commit

Permalink
Add github actions workflow for creating deb/rpm packages
Browse files Browse the repository at this point in the history
  • Loading branch information
alex1701c committed Oct 13, 2024
1 parent 31a327a commit 6d1fda4
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 31 deletions.
104 changes: 92 additions & 12 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ on:
pull_request:
branches:
- master
workflow_dispatch:
inputs:
publish-version:
description: "new version that should get published"
required: true
permissions:
contents: write

jobs:
build:
Expand All @@ -16,7 +23,7 @@ jobs:
matrix:
os:
- name: ubuntu
image: invent-registry.kde.org/neon/docker-images/plasma:user
image: ubuntu:24.10
- name: ubuntu
image: ubuntu:24.04
- name: opensuse
Expand All @@ -26,7 +33,7 @@ jobs:
plasma_version: [plasma5, plasma6]
exclude:
- os:
image: invent-registry.kde.org/neon/docker-images/plasma:user
image: ubuntu:24.10
plasma_version: plasma5
- os:
image: ubuntu:24.04
Expand All @@ -36,7 +43,6 @@ jobs:
name: ${{ matrix.os.name }}-${{ matrix.plasma_version }}
container:
image: ${{ matrix.os.image }}
options: --user root
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -54,9 +60,11 @@ jobs:
echo 'APT::Get::Assume-Yes "true";' >> /etc/apt/apt.conf
elif [[ "${{ matrix.os.name }}" == "fedora" ]]; then
echo "defaultyes=True" >> /etc/dnf/dnf.conf
dnf install rpm-build
elif [[ "${{ matrix.os.name }}" == "opensuse" ]]; then
zypper refresh
CMD=$(echo $CMD | sed 's/zypper/zypper --non-interactive/')
zypper install -y rpm-build
else
echo "Unsupported OS: ${{ matrix.os.name }}"
exit 1
Expand All @@ -67,26 +75,98 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0

- name: Create build directory
- name: Get defined project version
shell: bash
run: echo project_version=$(sed -nr 's/set\(CMAKE_PROJECT_VERSION "(.+)"\)/\1/p' CMakeLists.txt) >> $GITHUB_ENV

- name: Update Version in CMakeLists
if: inputs.publish-version
shell: bash
run: |
mkdir -p build
cd build
publish_version="${{ inputs.publish-version }}"
if ! [[ $publish_version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Invalid version format for publish-version: $publish_version. It must be in the format x.y.z."
exit 1
fi
if [ "$(printf "%s\n%s" "${{ env.project_version }}" "$publish_version" | sort -V | head -n1)" != "${{ env.project_version }}" ] || [ "${{ env.project_version }}" == "$publish_version" ]; then
echo "CMake version ${{ env.project_version }} is not smaller than publish-version $publish_version."
exit 1
fi
sed -i -E "s/(set\s*\(\s*CMAKE_PROJECT_VERSION\s*\")[0-9]+\.[0-9]+\.[0-9]+(\")/\1${publish_version}\2/" CMakeLists.txt
- name: Create build directory
run: mkdir -p build

- name: Build and install
working-directory: build/
shell: bash
run: |
cd build
CMAKE_ARGS=".. -DCMAKE_BUILD_TYPE=Release -DCPACK_OS=${{ matrix.os.name }}"
if [[ "${{ matrix.plasma_version }}" == "plasma6" ]]; then
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_WITH_QT6=ON
CMAKE_ARGS="$CMAKE_ARGS -DBUILD_WITH_QT6=ON"
else
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_WITH_QT6=OFF
CMAKE_ARGS="$CMAKE_ARGS -DBUILD_WITH_QT6=OFF"
fi
cmake --build .
echo cmake $CMAKE_ARGS
cmake $CMAKE_ARGS
cmake --build . -j2
cmake --install .
- name: Run tests
working-directory: build/
run: ctest -V

- name: CPack
if: inputs.publish-version
working-directory: build
id: cpack
shell: bash
run: |
cpack | tee cpack.out
filepath=$(sed -nr 's/.*package: (.+) generated\./\1/p' cpack.out)
echo "filepath=$filepath" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@v4
if: inputs.publish-version
with:
name: ${{ matrix.os.name }}-${{ matrix.plasma_version }}
path: ${{ steps.cpack.outputs.filepath }}

release:
runs-on: ubuntu-latest
needs: build
if: inputs.publish-version
steps:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- name: Update Version in CMakeLists
run: |
cd build
ctest -V
sed -i -E "s/(set\s*\(\s*CMAKE_PROJECT_VERSION\s*\")[0-9]+\.[0-9]+\.[0-9]+(\")/\1${{ inputs.publish-version }}\2/" CMakeLists.txt
- uses: actions/download-artifact@v4
with:
path: binaries
- name: Collect files
id: collect_artifacts
shell: bash
run: |
files=$(find binaries -type f | paste -sd "," -)
echo "uploaded_files=$files" >> "$GITHUB_OUTPUT"
- name: Create Tag
shell: bash
run: |
git config --global user.name 'alex1701c'
git config --global user.email '[email protected]'
git commit -am "New release ${{ inputs.publish-version }}"
git tag -a "${{ inputs.publish-version }}" -m "Release version ${{ inputs.publish-version }}"
git push
git push --tags
- uses: ncipollo/release-action@v1
with:
artifacts: ${{ steps.collect_artifacts.outputs.uploaded_files }}
tag: ${{ inputs.publish-version }}
generateReleaseNotes: true

28 changes: 11 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.16)

project(emojirunner)
set(CMAKE_PROJECT_VERSION "3.0.2")

set(QT_MIN_VERSION 5.15.0)
set(KF_MIN_VERSION 5.105.0)
Expand Down Expand Up @@ -40,27 +41,20 @@ set(CPACK_RPM_PACKAGE_ARCHITECTURE "x86_64")
set(CPACK_RPM_PACKAGE_LICENSE "LGPL 3")

# Then names of dependencies and paths might differ
if (CPACK_DEBIAN) # -DCPACK_DEBIAN=true -DKDE_INSTALL_QTPLUGINDIR=/usr/lib/x86_64-linux-gnu/qt5/plugins
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libkf5runner5 (>= ${KF5Runner_VERSION}), libxdo3 (>= 3.20160805.1)")
set(CPACK_DEBIAN_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Debian.deb")
set(KRUNNER_VERSION "${KF${QT_MAJOR_VERSION}Runner_VERSION}")
set(CPACK_PACKAGE_FILE_NAME ${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_OS}-plasma${QT_MAJOR_VERSION})
if (CPACK_OS STREQUAL "ubuntu")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libkf${QT_MAJOR_VERSION}runner${QT_MAJOR_VERSION} (>=${KRUNNER_VERSION}), libxdo3 (>= 3.20)")
set(CPACK_GENERATOR "DEB")
elseif(CPACK_FEDORA) # -DCPACK_FEDORA=true -DKDE_INSTALL_QTPLUGINDIR=/usr/lib64/qt5/plugins
set(CPACK_RPM_PACKAGE_REQUIRES "kf5-krunner >= ${KF5Runner_VERSION}; libxdo3 >= 3.20160805.1")
set(CPACK_RPM_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Fedora.rpm")
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/usr/lib64/qt5;/usr/lib64/qt5/plugins;/usr/lib64/qt5/plugins/kf5;/usr/lib64/qt5/plugins/kf5/krunner;/usr/share/kservices5;/usr/share/icons")
elseif(CPACK_OS STREQUAL "fedora")
set(CPACK_RPM_PACKAGE_REQUIRES "kf${QT_MAJOR_VERSION}-krunner >= ${KRUNNER_VERSION}, libxdo >= 3.20")
set(CPACK_GENERATOR "RPM")
elseif(CPACK_OPENSUSE) # -DCPACK_OPENSUSE=true -DKDE_INSTALL_QTPLUGINDIR=/usr/lib64/qt5/plugins
set(CPACK_RPM_PACKAGE_REQUIRES "libKF5Runner5 >= ${KF5Runner_VERSION}")
set(CPACK_RPM_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-OpenSUSE.rpm")
elseif(CPACK_OS STREQUAL "opensuse")
set(CPACK_RPM_PACKAGE_REQUIRES "kf${QT_MAJOR_VERSION}-krunner >= ${KRUNNER_VERSION}")
set(CPACK_GENERATOR "RPM")
else()
unset(CPACK_PACKAGE_FILE_NAME)
endif()
# We always have to explicitely set the generator when using cpack, otherwise
# the different paths of the distros might get messed up
unset(CPACK_DEBIAN CACHE)
unset(CPACK_FEDORA CACHE)
unset(CPACK_OPENSUSE CACHE)



# These scripts will kill krunner and when it is invoked next time the plugins will be loaded
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/postinst;${CMAKE_CURRENT_SOURCE_DIR}/postrm")
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ sudo zypper install git cmake kf6-extra-cmake-modules kf6-ki18n-devel kf6-krunne

Plasma5:
```bash install-fedora-plasma5
sudo dnf install git cmake extra-cmake-modules kf5-ki18n-devel kf5-krunner-devel gettext xdotool kf5-kcmutils-devel
sudo dnf install git cmake extra-cmake-modules gettext kf5-ki18n-devel kf5-krunner-devel kf5-kcmutils-devel libxdo-devel
```
Plasma6:
```bash install-fedora-plasma6
sudo dnf install git cmake extra-cmake-modules kf6-ki18n-devel kf6-krunner-devel kf6-kcmutils-devel gettext xdotool
sudo dnf install git cmake gettext extra-cmake-modules kf6-ki18n-devel kf6-krunner-devel kf6-kcmutils-devel libxdo-devel
```

</details>
Expand Down

0 comments on commit 6d1fda4

Please sign in to comment.