From 298f5cbc2b595f922ad1bdc22b664a4e93c73f58 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Tue, 22 Aug 2023 10:20:21 +0200 Subject: [PATCH] feat: pkg for RHEL --- .github/workflows/pkg-installer.yml | 85 +++++++++++++++++++++++++++ package/homebrew.spec | 90 +++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 package/homebrew.spec diff --git a/.github/workflows/pkg-installer.yml b/.github/workflows/pkg-installer.yml index 947906d08f100..91a4921a6f4dd 100644 --- a/.github/workflows/pkg-installer.yml +++ b/.github/workflows/pkg-installer.yml @@ -8,6 +8,12 @@ on: paths: - .github/workflows/pkg-installer.yml - package/**/* + - package/* + pull_request: + paths: + - .github/workflows/build-pkg.yml + - package/**/* + - package/* release: types: - published @@ -217,3 +223,82 @@ jobs: run: gh release upload --repo Homebrew/brew "${GITHUB_REF//refs\/tags\//}" "${{ needs.build.outputs.installer_path }}" + build-rpm: + # if: github.repository_owner == 'Homebrew' + runs-on: ubuntu-latest + container: + image: almalinux:8 + permissions: + # To write assets to GitHub release + contents: write + env: + HOMEBREW_NO_ANALYTICS_THIS_RUN: 1 + HOMEBREW_NO_ANALYTICS_MESSAGE_OUTPUT: 1 + steps: + - name: Install build dependencies + run: dnf install -y git rpm-build + + - name: Checkout Homebrew + uses: actions/checkout@v3 + with: + path: brew + fetch-depth: 0 + ref: ${{ github.event.pull_request.head.sha || github.ref }} + + - name: Get Homebrew version from Git + id: print-version + run: | + TAG="$(git -C brew describe --tags --abbrev=0)" + echo "version=${TAG}" >> "${GITHUB_OUTPUT}" + echo "commits=$(git -C brew rev-list $TAG..HEAD --count)" >> "${GITHUB_OUTPUT}" + + - name: Setup build environment + run: | + echo "%_topdir ${{ github.workspace }}/rpmbuild" > "$HOME/.rpmmacros" + mkdir -p "${{ github.workspace }}/rpmbuild/"{SOURCES,SPECS,BUILD,BUILDROOT,RPMS,SRPMS} + cp brew/package/homebrew.spec "${{ github.workspace }}/rpmbuild/SPECS/" + + - name: Create source tar + run: | + tar czvf ${{ github.workspace }}/rpmbuild/SOURCES/brew.tar.gz brew/. + + - name: Build Homebrew package + run: | + rpmbuild -ba ${{ github.workspace }}/rpmbuild/SPECS/homebrew.spec \ + --define='git_version ${{ steps.print-version.outputs.version }}' \ + --define='git_rev ${{ steps.print-version.outputs.commits }}' + + - name: Install package + run: | + dnf module reset ruby -y + dnf module enable ruby:2.6 -y + dnf install -y ${{ github.workspace }}/rpmbuild/RPMS/*/homebrew-*.rpm + + - run: ls -al /home/linuxbrew/.linuxbrew/ + - run: | + git config --global --add safe.directory /home/linuxbrew/.linuxbrew + git -C "/home/linuxbrew/.linuxbrew/" status + + - name: Create test user + run: useradd --shell /sbin/nologin test-user + + - name: Evaluate install + run: | + sudo -u "test-user" sh -c "eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv) && brew config && brew doctor" + + - name: Upload installer to GitHub Actions + uses: actions/upload-artifact@v3 + with: + name: Homebrew ${{ steps.print-version.outputs.version }} rpms + path: "${{ github.workspace }}/rpmbuild/*RPMS/*/homebrew-${{ steps.print-version.outputs.version }}*.rpm" + + # - name: Install gh + # run: brew install gh + + # - name: Upload installer to GitHub release + # if: startsWith(github.ref, 'refs/tags/') + # env: + # GH_TOKEN: ${{ github.token }} + # run: gh release upload --repo Homebrew/brew + # "${GITHUB_REF//refs\/tags\//}" + # Homebrew-${{ steps.print-version.outputs.version }}.pkg diff --git a/package/homebrew.spec b/package/homebrew.spec new file mode 100644 index 0000000000000..ac3787e233c75 --- /dev/null +++ b/package/homebrew.spec @@ -0,0 +1,90 @@ +%{!?git_version: %global git_version 0.0.1} +%{!?git_rev: %global git_rev 0} +%define homebrew_user linuxbrew +%define homebrew_directory /home/%{homebrew_user}/.%{homebrew_user} +%define brew_repo https://github.com/Homebrew/brew + +Summary: Homebrew package manager +Name: homebrew +Version: %{git_version} +Release: %{git_rev} +License: BSD-2-clause +Group: Development/Tools +Source: %{brew_repo}/archive/refs/tags/%{git_version}.tar.gz#/brew.tar.gz + +# See: https://github.com/Homebrew/install/blob/master/install.sh#L211-L214 +BuildRequires: git + +Autoreq: no +Requires: procps-ng +Requires: file +Requires: gcc +Requires: git >= 2.7.0 +Requires: glibc >= 2.13 +Requires: ruby >= 2.6.0 + +%description +The Missing Package Manager for macOS (or Linux) + +%global debug_package %{nil} +%global _missing_build_ids_terminate_build 0 +%global __brp_mangle_shebangs /usr/bin/true + +%prep +%autosetup -n brew + +%build +git remote set-url origin %{brew_repo} || git remote add origin %{brew_repo} + +%install +install -d "$RPM_BUILD_ROOT%{homebrew_directory}" +cp -r bin "$RPM_BUILD_ROOT%{homebrew_directory}" +cp -r completions "$RPM_BUILD_ROOT%{homebrew_directory}" +cp -r manpages "$RPM_BUILD_ROOT%{homebrew_directory}" +cp -r docs "$RPM_BUILD_ROOT%{homebrew_directory}" +cp -r package "$RPM_BUILD_ROOT%{homebrew_directory}" +cp -r .git "$RPM_BUILD_ROOT%{homebrew_directory}" +cp -r .github "$RPM_BUILD_ROOT%{homebrew_directory}" +cp -r .gitignore "$RPM_BUILD_ROOT%{homebrew_directory}" +cp -r .shellcheckrc "$RPM_BUILD_ROOT%{homebrew_directory}" +cp -r .sublime "$RPM_BUILD_ROOT%{homebrew_directory}" +cp -r .vscode "$RPM_BUILD_ROOT%{homebrew_directory}" +cp -r .devcontainer "$RPM_BUILD_ROOT%{homebrew_directory}" +cp -r .dockerignore "$RPM_BUILD_ROOT%{homebrew_directory}" +cp -r .editorconfig "$RPM_BUILD_ROOT%{homebrew_directory}" +cp -r .vale.ini "$RPM_BUILD_ROOT%{homebrew_directory}" +cp -r Dockerfile "$RPM_BUILD_ROOT%{homebrew_directory}" +cp -r *.md "$RPM_BUILD_ROOT%{homebrew_directory}" +cp -r *.txt "$RPM_BUILD_ROOT%{homebrew_directory}" +cp -rd Library "$RPM_BUILD_ROOT%{homebrew_directory}" + +pushd "$RPM_BUILD_ROOT%{homebrew_directory}" +mkdir -vp Cellar Frameworks etc include lib opt sbin share var/homebrew/linked + +%check +export HOMEBREW_NO_ANALYTICS_THIS_RUN=1 +export HOMEBREW_NO_ANALYTICS_MESSAGE_OUTPUT=1 +sudo -u "%{homebrew_user}" %{homebrew_directory}/bin/brew config +sudo -u "%{homebrew_user}" %{homebrew_directory}/bin/brew doctor + +%pre +getent passwd %{homebrew_user} >/dev/null || \ + useradd -r -d %{homebrew_directory} -s /sbin/nologin \ + -c "The Homebrew default user" %{homebrew_user} + +%post +chown -R "%{homebrew_user}:%{homebrew_user}" %{homebrew_directory} + +%preun +if [ $1 == 0 ];then + userdel %{homebrew_user} +fi + +%files +%{homebrew_directory} +%license %{homebrew_directory}/LICENSE.txt +%doc %{homebrew_directory}/CHANGELOG.md +%doc %{homebrew_directory}/CONTRIBUTING.md +%doc %{homebrew_directory}/README.md + +%changelog