Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/habitat-build-darwin.yml
Original file line number Diff line number Diff line change
@@ -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"
138 changes: 138 additions & 0 deletions habitat/aarch64-darwin/plan.sh
Original file line number Diff line number Diff line change
@@ -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 <humans@chef.io>"
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 "$PLAN_CONTEXT/../../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 <<EOF > "$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
}

31 changes: 31 additions & 0 deletions habitat/tests/test.darwin.sh
Original file line number Diff line number Diff line change
@@ -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
Loading