From 42f6968121c6e6ee08b0c23620a5ab1f6a2d648b Mon Sep 17 00:00:00 2001 From: nitin sanghi Date: Wed, 24 Jun 2026 15:53:07 +0530 Subject: [PATCH 1/2] Created hab plan file for mac os Signed-off-by: nitin sanghi --- habitat/aarch64-darwin/plan.sh | 138 +++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 habitat/aarch64-darwin/plan.sh diff --git a/habitat/aarch64-darwin/plan.sh b/habitat/aarch64-darwin/plan.sh new file mode 100644 index 00000000..00ceb482 --- /dev/null +++ b/habitat/aarch64-darwin/plan.sh @@ -0,0 +1,138 @@ +export HAB_BLDR_CHANNEL="base-2025" +export HAB_REFRESH_CHANNEL="base-2025" +ruby_pkg="core/ruby3_4" +pkg_name="chef-cli" +pkg_origin="chef" +pkg_maintainer="The Chef Maintainers " +pkg_description="A streamlined development and deployment workflow for Chef platform." +pkg_license=('Apache-2.0') +pkg_bin_dirs=(bin) +pkg_build_deps=( + core/git + core/clang + core/make + core/cmake +) +pkg_deps=(${ruby_pkg} core/coreutils core/libarchive) + +pkg_svc_user=root + +pkg_version() { + cat "$SRC_PATH/VERSION" +} + +do_before() { + update_pkg_version +} + +do_unpack() { + mkdir -pv "$HAB_CACHE_SRC_PATH/$pkg_dirname" + cp -RT "$PLAN_CONTEXT"/../.. "$HAB_CACHE_SRC_PATH/$pkg_dirname/" +} + +do_setup_environment() { + push_runtime_env GEM_PATH "${pkg_prefix}/vendor" + set_runtime_env APPBUNDLER_ALLOW_RVM "true" # prevent appbundler from clearing out the carefully constructed runtime GEM_PATH + set_runtime_env LANG "en_US.UTF-8" + set_runtime_env LC_CTYPE "en_US.UTF-8" +} + +do_prepare() { + build_line "Setting up build environment for native extensions" + export PATH="$(pkg_path_for core/cmake)/bin:$(pkg_path_for core/make)/bin:$(pkg_path_for core/clang)/bin:$PATH" + export CC="$(pkg_path_for core/clang)/bin/clang" + export CXX="$(pkg_path_for core/clang)/bin/clang++" +} + +do_build() { + cd "$HAB_CACHE_SRC_PATH/$pkg_dirname" || exit_with "unable to cd to source directory" 1 + + export GEM_HOME="$pkg_prefix/vendor" + export HOME="$HAB_CACHE_SRC_PATH/$pkg_dirname" + export GEM_SPEC_CACHE="$HAB_CACHE_SRC_PATH/$pkg_dirname/.gem/specs" + mkdir -p "$GEM_SPEC_CACHE" + export PATH="$(pkg_path_for core/cmake)/bin:$(pkg_path_for core/make)/bin:$(pkg_path_for core/clang)/bin:$PATH" + export CC="$(pkg_path_for core/clang)/bin/clang" + export CXX="$(pkg_path_for core/clang)/bin/clang++" + + build_line "Setting GEM_PATH=$GEM_HOME" + export GEM_PATH="$GEM_HOME" + bundle config --local without integration deploy maintenance test development profile + bundle config --local jobs 4 + bundle config --local retry 5 + bundle config --local silence_root_warning 1 + bundle install + gem build chef-cli.gemspec + ruby ./cleanup_gem_lockfiles.rb + ruby ./post-bundle-install.rb +} + +do_install() { + cd "$HAB_CACHE_SRC_PATH/$pkg_dirname" || exit_with "unable to cd to source directory" 1 + + # Copy NOTICE to the package directory + if [[ -f "NOTICE" ]]; then + build_line "Copying NOTICE to package directory" + cp "NOTICE" "$pkg_prefix/" + else + build_line "Warning: NOTICE not found in source directory" + fi + + export GEM_HOME="$pkg_prefix/vendor" + export HOME="$HAB_CACHE_SRC_PATH/$pkg_dirname" + export GEM_SPEC_CACHE="$HAB_CACHE_SRC_PATH/$pkg_dirname/.gem/specs" + mkdir -p "$GEM_SPEC_CACHE" + + build_line "Setting GEM_PATH=$GEM_HOME" + export GEM_PATH="$GEM_HOME" + gem install --local chef-cli-*.gem --no-document --ignore-dependencies + + build_line "** generating binstubs for chef-cli with precise version pins" + "${pkg_prefix}/vendor/bin/appbundler" . "$pkg_prefix/bin" chef-cli + + build_line "** patching binstubs to allow running directly" + for binstub in ${pkg_prefix}/bin/*; do + sed -i -e "/require ['\"]rubygems['\"]/r ${PLAN_CONTEXT}/../binstub_patch.rb" "$binstub" + done + + if ! grep -q 'APPBUNDLER_ALLOW_RVM' "${pkg_prefix}/bin/chef-cli"; then + build_line "ERROR: binstub patch injection failed for ${pkg_prefix}/bin/chef-cli" + return 1 + fi + + build_line "** creating wrapper for runtime environment" + mkdir -p "$pkg_prefix/libexec" + mv "$pkg_prefix/bin/chef-cli" "$pkg_prefix/libexec/chef-cli" + cat < "$pkg_prefix/bin/chef-cli" +#!/bin/bash +set -e + +export PATH="$(pkg_path_for ${ruby_pkg})/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:$pkg_prefix/vendor/bin:\$PATH" +export DYLD_LIBRARY_PATH="$(pkg_path_for core/libarchive)/lib:\$DYLD_LIBRARY_PATH" +export GEM_HOME="$pkg_prefix/vendor" +export GEM_PATH="$pkg_prefix/vendor" + +exec $(pkg_path_for ${ruby_pkg})/bin/ruby $pkg_prefix/libexec/chef-cli "\$@" +EOF + chmod -v 755 "$pkg_prefix/bin/chef-cli" + + fix_interpreter "${pkg_prefix}/vendor/bin/*" "$ruby_pkg" bin/ruby + + rm -rf "$GEM_PATH/cache" + rm -rf "$GEM_PATH/bundler" + rm -rf "$GEM_PATH/doc" +} + +do_after() { + build_line "Removing .github directories from vendored gems..." + find "$pkg_prefix/vendor/gems" -type d -name ".github" \ + | while read github_dir; do rm -rf "$github_dir"; done + + build_line "Removing stray Gemfile.lock files from vendored gems..." + find "$pkg_prefix/vendor/gems" -name "Gemfile.lock" -type f -delete +} + +do_strip() { + return 0 +} + From deca432340dc59d47fa4a15924deebeefbc0c76f Mon Sep 17 00:00:00 2001 From: nitin sanghi Date: Thu, 2 Jul 2026 15:50:05 +0530 Subject: [PATCH 2/2] Added the test pipeline Signed-off-by: nitin sanghi --- .github/workflows/habitat-build-darwin.yml | 59 ++++++++++++++++++++++ habitat/aarch64-darwin/plan.sh | 2 +- habitat/tests/test.darwin.sh | 31 ++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/habitat-build-darwin.yml create mode 100755 habitat/tests/test.darwin.sh diff --git a/.github/workflows/habitat-build-darwin.yml b/.github/workflows/habitat-build-darwin.yml new file mode 100644 index 00000000..5ef2d2e4 --- /dev/null +++ b/.github/workflows/habitat-build-darwin.yml @@ -0,0 +1,59 @@ +name: macos_habitat_build + +"on": + pull_request: + branches: [main] + push: + branches: [main] + +permissions: + contents: read + +concurrency: + group: macos-habitat-${{ github.event.pull_request.number || github.run_id }} + cancel-in-progress: true + +jobs: + habitat-plan: + strategy: + fail-fast: false + matrix: + os: [macos-14] + runs-on: ${{ matrix.os }} + timeout-minutes: 120 + env: + HAB_ORIGIN: gha + HAB_BLDR_CHANNEL: base-2025 + HAB_REFRESH_CHANNEL: base-2025 + HAB_AUTH_TOKEN: ${{ secrets.HAB_AUTH_TOKEN }} + HAB_LICENSE: accept-no-persist + HAB_NONINTERACTIVE: "true" + steps: + - uses: actions/checkout@v6 + with: + clean: true + + - name: Install Habitat CLI + run: | + curl https://raw.githubusercontent.com/habitat-sh/habitat/main/components/hab/install.sh | sudo -E bash -s -- -t aarch64-darwin + hab license accept + hab --version + + - name: Generate Habitat Origin Key + run: hab origin key generate "$HAB_ORIGIN" + + - name: Build Habitat Package + run: | + git config --global --add safe.directory "$GITHUB_WORKSPACE" + hab pkg build habitat/aarch64-darwin + + - name: Install Habitat Package + run: | + source ./results/last_build.env + echo "Installing: $pkg_ident ($pkg_artifact)" + sudo -E hab pkg install "./results/$pkg_artifact" + + - name: Run test.darwin.sh + run: | + source ./results/last_build.env + sudo -E ./habitat/tests/test.darwin.sh "$pkg_ident" diff --git a/habitat/aarch64-darwin/plan.sh b/habitat/aarch64-darwin/plan.sh index 00ceb482..fcbf1d2d 100644 --- a/habitat/aarch64-darwin/plan.sh +++ b/habitat/aarch64-darwin/plan.sh @@ -18,7 +18,7 @@ pkg_deps=(${ruby_pkg} core/coreutils core/libarchive) pkg_svc_user=root pkg_version() { - cat "$SRC_PATH/VERSION" + cat "$PLAN_CONTEXT/../../VERSION" } do_before() { diff --git a/habitat/tests/test.darwin.sh b/habitat/tests/test.darwin.sh new file mode 100755 index 00000000..8bf60838 --- /dev/null +++ b/habitat/tests/test.darwin.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +set -euo pipefail + +project_root="$(git rev-parse --show-toplevel)" +pkg_ident="$1" + +# print error message followed by usage and exit +error () { + local message="$1" + + echo -e "\nERROR: ${message}\n" >&2 + + exit 1 +} + +[[ -n "$pkg_ident" ]] || error 'no hab package identity provided' + +package_version=$(awk -F / '{print $3}' <<<"$pkg_ident") + +cd "${project_root}" + +echo "--- :mag_right: Testing ${pkg_ident} executables (aarch64-darwin)" +version=$(hab pkg exec "${pkg_ident}" chef-cli -v) +echo "$version" +actual_version=$(echo "$version" | sed -E 's/.*version: ([0-9]+\.[0-9]+\.[0-9]+).*/\1/') +echo "$actual_version" + +if [[ "$actual_version" != *"$package_version"* ]]; then + error "chef-cli version is not the expected version. Expected '$package_version', got '$actual_version'" +fi