diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bed0e2f..f04a745 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,7 +30,7 @@ on: required: false default: "false" pull_request: - branches: [ main ] + branches: [ main, develop ] permissions: contents: write @@ -323,93 +323,47 @@ jobs: build-rhel: needs: [run-unit-tests-linux, run-unit-tests-windows] if: ${{ github.event_name == 'pull_request' || contains(github.event.inputs.jobs, 'build-rhel') }} + permissions: + contents: read + packages: read env: DISTRO_TYPE: rhel runs-on: ubuntu-latest + container: + image: ghcr.io/jmr-dev/android-file-handler-adb:v0.1.0 steps: - name: Checkout code uses: actions/checkout@v4 with: ref: ${{ github.event.inputs.branch || github.head_ref || github.ref }} - - name: Update OS and install Docker + - name: Build RHEL package run: | set -euo pipefail - sudo apt-get update - # Remove possible conflicting containerd packages that can block docker.io installation - sudo apt-get remove -y --purge containerd containerd.io || true - sudo apt-get autoremove -y || true - # Try installing docker.io from distro packages - if ! sudo apt-get install -y --no-install-recommends ca-certificates curl gnupg lsb-release docker.io git build-essential; then - echo "apt install docker.io failed; falling back to Docker convenience script" - # Fallback: use Docker's official convenience script - curl -fsSL https://get.docker.com | sudo sh - fi - sudo usermod -aG docker $USER || true + export CI_CD=true + export DISTRO_TYPE=rhel + poetry install --no-interaction + poetry run python scripts/build_package_linux.py - - name: Pull Fedora container image - run: | - docker pull fedora:latest - - - name: Start Fedora container (background) and mount repo - run: | - # Run container with workspace mounted - docker run -d --name rhel-build -v "$PWD":/workspace -w /workspace fedora:latest sleep infinity - - - name: Prepare container build environment (dnf, pyenv, python, poetry, fpm) - run: | - set -euo pipefail - # Update the Fedora image and install build deps - docker exec rhel-build bash -lc "dnf -y update && dnf -y install gcc make zlib-devel bzip2 bzip2-devel readline-devel sqlite-devel openssl-devel libffi-devel wget tar git curl ruby rubygems rpm-build redhat-rpm-config gcc-c++ patch which xz-devel" - - # Install pyenv into the container (if not present) - docker exec rhel-build bash -lc "[ -d \"/root/.pyenv\" ] || git clone https://github.com/pyenv/pyenv.git /root/.pyenv && mkdir -p /root/.pyenv/plugins && [ -d \"/root/.pyenv/plugins/python-build\" ] || git clone https://github.com/pyenv/pyenv-build.git /root/.pyenv/plugins/python-build" - - # Install Python 3.12 via pyenv and set global using explicit pyenv binary path - # Use single quotes so $PYENV_ROOT and $PATH are expanded inside the container's shell - docker exec rhel-build bash -lc 'export PYENV_ROOT="/root/.pyenv"; export PATH="$PYENV_ROOT/bin:$PATH"; /root/.pyenv/bin/pyenv install -s 3.12.0; /root/.pyenv/bin/pyenv global 3.12.0; /root/.pyenv/bin/pyenv rehash' - - # Install Poetry inside the container using the official installer (install to /root/.local/bin) - # Use single quotes so PATH is evaluated inside the container shell rather than the runner - docker exec rhel-build bash -lc 'export PATH="/root/.pyenv/shims:/root/.pyenv/bin:$PATH"; curl -sSL https://install.python-poetry.org | python3 - --yes' - - # Verify Poetry is available via explicit path if not on PATH - docker exec rhel-build bash -lc "/root/.local/bin/poetry --version || echo 'Poetry not found in /root/.local/bin'" - - # Install fpm (Ruby gem) and ensure rpm build tools exist - docker exec rhel-build bash -lc "dnf -y install ruby rubygems make && gem install --no-document -v \"${FPM_VERSION}\" fpm" - - - name: Build inside container using Poetry - run: | - set -euo pipefail - # Use poetry inside the container to build package layouts. Use explicit paths so the runner shell - # doesn't expand $HOME; expansion should occur inside the container. - docker exec rhel-build bash -lc 'export PATH="/root/.local/bin:/root/.pyenv/shims:/root/.pyenv/bin:$PATH"; export CI_CD=true; export DISTRO_TYPE=rhel; cd /workspace && /root/.local/bin/poetry install --no-interaction && /root/.local/bin/poetry run python scripts/build_package_linux.py' - - - name: Package RHEL (fpm) inside container + - name: Package RHEL (fpm) shell: bash run: | - # Run the entire packaging flow inside the Fedora container so Poetry, PATH and arrays are evaluated in-container. - docker exec rhel-build bash -lc ' - set -euo pipefail - VERSION="$(/root/.local/bin/poetry version -s)" - PKG_DIR="pkg_dist_rhel" - mkdir -p dist || true - echo "Packaging from $PKG_DIR (version=$VERSION)" - ls -la "$PKG_DIR" || true + set -euo pipefail + VERSION="$(poetry version -s)" + PKG_DIR="pkg_dist_rhel" + mkdir -p dist + echo "Packaging from $PKG_DIR (version=$VERSION)" + ls -la "$PKG_DIR" || true - ICON_PATH="$PKG_DIR/usr/share/icons/hicolor/256x256/apps/android-file-handler.png" - PKG_ITEMS=( "usr/bin/android-file-handler" "usr/share/applications/android-file-handler.desktop" ) - if [ -f "$ICON_PATH" ]; then - PKG_ITEMS+=( "usr/share/icons/hicolor/256x256/apps/android-file-handler.png" ) - else - echo "Note: icon not present, packaging without icon" - fi + ICON_PATH="$PKG_DIR/usr/share/icons/hicolor/256x256/apps/android-file-handler.png" + PKG_ITEMS=( "usr/bin/android-file-handler" "usr/share/applications/android-file-handler.desktop" ) + if [ -f "$ICON_PATH" ]; then + PKG_ITEMS+=( "usr/share/icons/hicolor/256x256/apps/android-file-handler.png" ) + else + echo "Note: icon not present, packaging without icon" + fi - # Run fpm inside the container to produce an RPM - cd /workspace - exec fpm -s dir -t rpm -n android-file-handler -v "$VERSION" --architecture x86_64 --prefix /usr/bin --after-install scripts/rhel_postinst.sh -p "dist/android-file-handler-${VERSION}.x86_64.rpm" -C "$PKG_DIR" "${PKG_ITEMS[@]}" - ' + fpm -s dir -t rpm -n android-file-handler -v "$VERSION" --architecture x86_64 --prefix /usr/bin --after-install scripts/rhel_postinst.sh -p "dist/android-file-handler-${VERSION}.x86_64.rpm" -C "$PKG_DIR" "${PKG_ITEMS[@]}" - name: Upload RHEL artifacts uses: actions/upload-artifact@v4 @@ -421,7 +375,7 @@ jobs: - create-release: + do-release: needs: [run-unit-tests-linux, run-unit-tests-windows, build-windows, build-debian, build-arch, build-rhel] if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.DO_RELEASE == 'true' && needs.build-windows.result == 'success' && needs.build-debian.result == 'success' && needs.build-arch.result == 'success' && needs.build-rhel.result == 'success' }} runs-on: ubuntu-latest @@ -430,10 +384,48 @@ jobs: uses: actions/checkout@v4 with: ref: ${{ github.event.inputs.branch || github.head_ref || github.ref }} - + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Configure git + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + - name: Fast-forward main to develop + run: | + set -e + git fetch origin main develop + + # Verify develop is ahead of main + MERGE_BASE=$(git merge-base origin/main origin/develop) + MAIN_SHA=$(git rev-parse origin/main) + + if [ "$MERGE_BASE" != "$MAIN_SHA" ]; then + echo "::error::Main branch has commits not in develop. Cannot fast-forward." + echo "::error::Please merge or rebase main into develop first." + exit 1 + fi + + # Ensure develop is actually ahead + DEVELOP_SHA=$(git rev-parse origin/develop) + if [ "$MAIN_SHA" = "$DEVELOP_SHA" ]; then + echo "Main is already up to date with develop. Nothing to merge." + exit 0 + fi + + # Fast-forward merge develop into main + git checkout main + git merge origin/develop --ff-only + + echo "Successfully fast-forwarded main to develop" + git log origin/main..HEAD --oneline + + git push origin main + - name: Install Poetry uses: snok/install-poetry@v1 - + - name: Get version id: version run: echo "version=$(poetry version -s)" >> $GITHUB_OUTPUT @@ -502,8 +494,8 @@ jobs: AWS_PAGER: "" sync-wiki: - needs: create-release - if: always() && needs.create-release.result == 'success' + needs: do-release + if: always() && needs.do-release.result == 'success' uses: ./.github/workflows/sync-wiki.yml with: branch: ${{ github.event.inputs.branch || github.ref }} diff --git a/scripts/docker/Dockerfile.rhel b/scripts/docker/Dockerfile.rhel new file mode 100644 index 0000000..d769dd6 --- /dev/null +++ b/scripts/docker/Dockerfile.rhel @@ -0,0 +1,74 @@ +# Dockerfile for RHEL/Fedora build environment +# Automates all setup steps from the build-rhel workflow job +# +# Usage: +# docker build -f scripts/docker/Dockerfile.rhel -t android-file-handler-rhel-builder . +# docker run -v $(pwd):/workspace -w /workspace android-file-handler-rhel-builder + +FROM fedora:latest + +# Set build argument for fpm version (can be overridden at build time) +ARG FPM_VERSION=1.16.0 + +# Install system dependencies +RUN dnf -y update && \ + dnf -y install \ + gcc \ + make \ + zlib-devel \ + bzip2 \ + bzip2-devel \ + readline-devel \ + sqlite-devel \ + openssl-devel \ + libffi-devel \ + wget \ + tar \ + git \ + curl \ + ruby \ + rubygems \ + rpm-build \ + redhat-rpm-config \ + gcc-c++ \ + patch \ + which \ + xz-devel && \ + dnf clean all + +# Install pyenv +ENV PYENV_ROOT="/root/.pyenv" +ENV PATH="$PYENV_ROOT/bin:$PATH" + +RUN git clone https://github.com/pyenv/pyenv.git /root/.pyenv + +# Install Python 3.12 via pyenv +RUN eval "$(pyenv init -)" && \ + pyenv install 3.12.0 && \ + pyenv global 3.12.0 && \ + pyenv rehash + +# Update PATH to include pyenv shims +ENV PATH="/root/.pyenv/shims:$PATH" + +# Install Poetry +RUN curl -sSL https://install.python-poetry.org | python3 - --yes + +# Add Poetry to PATH +ENV PATH="/root/.local/bin:$PATH" + +# Verify Poetry installation +RUN poetry --version + +# Install fpm +RUN gem install --no-document -v "${FPM_VERSION}" fpm + +# Set working directory +WORKDIR /workspace + +# Set environment variables for build +ENV CI_CD=true +ENV DISTRO_TYPE=rhel + +# Default command runs the build script +CMD ["sh", "-c", "poetry install --no-interaction && poetry run python scripts/build_package_linux.py"]