From ceb07b74252f5962cfefe760e759dc45eca80ba6 Mon Sep 17 00:00:00 2001 From: iTrooz_ Date: Mon, 4 Jul 2022 21:40:22 +0200 Subject: [PATCH] build: Added AUR/ArchLinux support (#566) * store version in file * use version file in release workflow * use new version file in build workflow * ArchLinux build * setup cache for ArchLinux * add version check in release CI * edit step description * update pkgbuild to install correctly * AUR deploy * rename version file to VERSION * install all default plugins in PKGBUILD * Added emojis to build workflow * Added emojis to release workflow * separate update packages and install dependencies in two steps * fix Release CI * add md5Sums to PKGBUILD * make PKGBUILD point to the official repo + set v in tag --- .github/workflows/build.yml | 90 ++++++++++++++++++++++++++++++++++- .github/workflows/release.yml | 54 +++++++++++++++++---- CMakeLists.txt | 3 +- VERSION | 1 + cmake/build_helpers.cmake | 2 - dist/Arch/PKGBUILD | 38 +++++++++++++++ dist/get_deps_archlinux.sh | 2 +- 7 files changed, 176 insertions(+), 14 deletions(-) create mode 100644 VERSION create mode 100644 dist/Arch/PKGBUILD diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f68b1830b..7ae9d1a46 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -240,7 +240,7 @@ jobs: - name: 📜 Set version variable run: | - echo "version=`cat build/version`" >> $GITHUB_ENV + echo "version=`cat VERSION`" >> $GITHUB_ENV #- name: 📦 Bundle Flatpak # run: | @@ -284,3 +284,91 @@ jobs: name: Linux AppImage path: '*.AppImage' + archlinux-build: + name: 🐧 ArchLinux + runs-on: ubuntu-latest + + container: + image: archlinux:base-devel + + steps: + - name: ⬇️ Update all packages + run: | + pacman -Syyu --noconfirm + + - name: ⬇️ Install setup dependencies + run: | + pacman -Syu git ccache --noconfirm + + - name: 🧰 Checkout + uses: actions/checkout@v3 + with: + submodules: recursive + + - name: ⬇️ Install ImHex dependencies + run: | + dist/get_deps_archlinux.sh --noconfirm + + - name: 📜 Restore ccache + uses: actions/cache@v3 + with: + path: | + ~/.cache/ccache + key: archlinux-${{ secrets.CACHE_VERSION }}-build-${{ github.run_id }} + restore-keys: archlinux-${{ secrets.CACHE_VERSION }}-build + + - name: 📜 Restore CMakeCache + uses: actions/cache@v3 + with: + path: | + build/CMakeCache.txt + key: archlinux-${{ secrets.CACHE_VERSION }}-build-${{ hashFiles('**/CMakeLists.txt') }} + + - name: 🛠️ Build + run: | + mkdir -p build + cd build + CC=gcc CXX=g++ cmake \ + -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ + -DCMAKE_INSTALL_PREFIX="/usr" \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DCMAKE_C_FLAGS="-fuse-ld=lld" \ + -DCMAKE_CXX_FLAGS="-fuse-ld=lld" \ + -DRUST_PATH="$HOME/.cargo/bin/" \ + .. + make -j 4 install DESTDIR=installDir + + - name: 📜 Set version variable + run: | + echo "version=`cat VERSION`" >> $GITHUB_ENV + + - name: ✒️ Prepare PKGBUILD + run: | + cp dist/Arch/PKGBUILD build + sed -i 's/%version%/${{env.version}}/g' build/PKGBUILD + + # makepkg doesn't want to run as root, so I had to chmod 777 all over + - name: 📦 Package ArchLinux .pkg.tar.zst + run: | + cd build + + # the name is a small trick to make makepkg recognize it as the source + # else, it would try to download the file from the release + tar -cvf imhex-${{env.version}}-ArchLinux.pkg.tar.zst -C installDir . + + chmod -R 777 . + + sudo -u nobody makepkg + + # Remplace the old file + rm imhex-${{env.version}}-ArchLinux.pkg.tar.zst + mv *.pkg.tar.zst imhex-${{env.version}}-ArchLinux.pkg.tar.zst + + - name: ⬆️ Upload imhex-archlinux.pkg.tar.zst + uses: actions/upload-artifact@v3 + with: + name: ArchLinux .pkg.tar.zst + path: | + build/imhex-${{env.version}}-ArchLinux.pkg.tar.zst + diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0cec7965b..7e3380157 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,20 +11,30 @@ jobs: release: runs-on: ubuntu-latest name: Release - env: - version: ${{ github.event.release.tag_name }} - steps: - - name: Get sources + steps: + - name: 🧰 Checkout uses: actions/checkout@v3 with: path: ImHex submodules: recursive - - name: Create tarball from sources with dependencies + - name: 📜 Verify version and set version variable + run: | + project_version=`cat ImHex/VERSION` + tag_version="${{github.event.release.tag_name}}" + tag_version="${tag_version:1}" + if [ "$project_version" != "$tag_version" ]; then + echo "::warning::$project_version and $tag_version are not the same ! Refusing to populate release" + exit 1 + fi + + echo "version=$project_version" >> $GITHUB_ENV + + - name: 🗜️ Create tarball from sources with dependencies run: tar -cvf Full.Sources.tar.gz ImHex - - name: Download artifacts from latest workflow + - name: ⬇️ Download artifacts from latest workflow uses: dawidd6/action-download-artifact@v2 with: github_token: ${{secrets.GITHUB_TOKEN}} @@ -33,7 +43,7 @@ jobs: workflow_conclusion: success skip_unpack: true - - name: Unzip files when needed + - name: 🗜️ Unzip files when needed run: | for zipfile in ./*.zip do @@ -47,10 +57,36 @@ jobs: fi done - - name: Rename Windows Portable Zip + - name: 🟩 Rename Windows Portable Zip run: mv "Windows Portable.zip" imhex-${{env.version}}-Windows-Portable.zip - - name: Upload everything to release + - name: ⬆️ Upload everything to release uses: softprops/action-gh-release@v1 with: files: '*' + + - name: ✒️ Prepare PKGBUILD + run: | + cp ImHex/dist/Arch/PKGBUILD . + + hash=`md5sum imhex-${{env.version}}-ArchLinux.pkg.tar.zst | cut -d ' ' -f 1` + + sed -i 's/%version%/${{env.version}}/g' PKGBUILD + sed -i "s/(SKIP)/($hash)/g" PKGBUILD + + - name: ⬆️ Publish AUR package + + # I couldn't make the condition in the env directly for some reason + env: + MY_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY }} + if: "${{ env.MY_KEY != '' }}" + + uses: KSXGitHub/github-actions-deploy-aur@v2 + with: + pkgname: imhex-bin + pkgbuild: ./PKGBUILD + commit_username: iTrooz + commit_email: itrooz@protonmail.com + ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }} + commit_message: Bump to version ${{env.version}} + ssh_keyscan_types: rsa,dsa,ecdsa,ed25519 diff --git a/CMakeLists.txt b/CMakeLists.txt index f5b367084..cfddb1061 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,9 @@ cmake_minimum_required(VERSION 3.16) # Updating the version here will update it throughout ImHex as well -set(IMHEX_VERSION "1.18.2") +file(READ "VERSION" IMHEX_VERSION) project(imhex VERSION ${IMHEX_VERSION}) +message("Project version ${IMHEX_VERSION}") set(CMAKE_CXX_STANDARD 20) set(IMHEX_BASE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/VERSION b/VERSION new file mode 100644 index 000000000..753029c3a --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.18.2 \ No newline at end of file diff --git a/cmake/build_helpers.cmake b/cmake/build_helpers.cmake index f4db7069c..c5954466a 100644 --- a/cmake/build_helpers.cmake +++ b/cmake/build_helpers.cmake @@ -228,8 +228,6 @@ macro(createPackage) downloadImHexPatternsFiles("./share/imhex") endif() - write_file(version ${PROJECT_VERSION}) - if (CREATE_BUNDLE) include(PostprocessBundle) diff --git a/dist/Arch/PKGBUILD b/dist/Arch/PKGBUILD new file mode 100644 index 000000000..126af005a --- /dev/null +++ b/dist/Arch/PKGBUILD @@ -0,0 +1,38 @@ +# Maintainer: iTrooz_ +pkgname=imhex-bin +pkgver=%version% +pkgrel=1 +pkgdesc="A Hex Editor for Reverse Engineers, Programmers and people who value their retinas when working at 3 AM. " +arch=("x86_64") +url="https://github.com/WerWolv/ImHex" +repo=$url +license=('GPL 2.0') +groups=() +depends=(glfw mbedtls python freetype2 libglvnd gtk3) +makedepends=(git) +checkdepends=() +optdepends=() +provides=(imhex) +conflicts=(imhex) +replaces=() +backup=() +options=() +source=($repo"/releases/download/v$pkgver/imhex-$pkgver-ArchLinux.pkg.tar.zst") +noextract=() +md5sums=(SKIP) +validpgpkeys=() + +package() { + tar -xf imhex-$pkgver-ArchLinux.pkg.tar.zst + + install -DT $srcdir/usr/bin/imhex $pkgdir/usr/bin/imhex + install -DT $srcdir/usr/lib/libimhex.so $pkgdir/usr/lib/libimhex.so + + for plugin in $srcdir/usr/share/imhex/plugins/*.hexplug; + do + install -DT $plugin $pkgdir/usr/share/imhex/plugins/`basename $plugin` + done + + cp -r $srcdir/usr/share/imhex/{constants,encodings,includes,magic,patterns} $pkgdir/usr/share/imhex + install -d $pkgdir/usr/share/imhex +} diff --git a/dist/get_deps_archlinux.sh b/dist/get_deps_archlinux.sh index 4ce6910ef..70384a019 100755 --- a/dist/get_deps_archlinux.sh +++ b/dist/get_deps_archlinux.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh -pacman -S --needed \ +pacman -S $@ --needed \ cmake \ gcc \ lld \