Skip to content

Build GNU Bash macOS aarch64 Tarball #8

Build GNU Bash macOS aarch64 Tarball

Build GNU Bash macOS aarch64 Tarball #8

name: Build GNU Bash macOS aarch64 Tarball
on:
schedule:
- cron: "17 3 * * *"
workflow_dispatch:
permissions:
contents: write
jobs:
build-bash-macos-aarch64:
runs-on: macos-15
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect latest Bash version
id: check
run: |
set -euo pipefail
if git ls-remote --exit-code --heads origin pkgs >/dev/null 2>&1; then
git fetch origin pkgs
git worktree add pkgs-worktree -B pkgs origin/pkgs
else
git worktree add --detach pkgs-worktree
(
cd pkgs-worktree
git checkout --orphan pkgs
git rm -rf . >/dev/null 2>&1 || true
)
fi
latest_version="$({
curl -fsSL https://ftp.gnu.org/gnu/bash/
} | grep -Eo 'bash-[0-9]+\.[0-9]+(\.[0-9]+)?\.tar\.gz' \
| sed -E \
's/^bash-([0-9]+\.[0-9]+(\.[0-9]+)?)\.tar\.gz$/\1/' \
| sort -Vu \
| tail -n 1)"
if [ -z "$latest_version" ]; then
echo "Could not determine latest GNU Bash version" >&2
exit 1
fi
pkg_dir="bash/macos-aarch64"
version_file="pkgs-worktree/$pkg_dir/latest-version.txt"
current_version=""
if [ -f "$version_file" ]; then
current_version="$(tr -d '[:space:]' < "$version_file")"
fi
{
echo "latest_version=$latest_version"
source_url="https://ftp.gnu.org/gnu/bash/"
source_url="${source_url}bash-$latest_version.tar.gz"
echo "source_url=$source_url"
echo "pkg_dir=$pkg_dir"
if [ "$latest_version" = "$current_version" ]; then
echo "should_build=false"
else
echo "should_build=true"
fi
} >> "$GITHUB_OUTPUT"
- name: Build macOS aarch64 Bash tarball
id: build
if: steps.check.outputs.should_build == 'true'
run: |
set -euo pipefail
version="${{ steps.check.outputs.latest_version }}"
source_url="${{ steps.check.outputs.source_url }}"
export MACOSX_DEPLOYMENT_TARGET="15.0"
export CC="clang -std=c89 -Wno-return-type"
export CFLAGS="-Os -target arm64-apple-macos15"
export CPPFLAGS="$CFLAGS"
mkdir -p build/src build/pkg/bin
cd build/src
curl -fsSLO "$source_url"
tar -xzf "bash-$version.tar.gz"
cd "bash-$version"
./configure \
--without-bash-malloc \
--with-included-gettext \
--host=aarch64-apple-darwin
make -j"$(sysctl -n hw.ncpu)" bash
strip -x bash
file bash | grep -q 'Mach-O 64-bit executable arm64'
deps="$(otool -L bash | tail -n +2 | awk '{print $1}')"
non_system_deps="$(echo "$deps" \
| grep -Ev '^(/usr/lib/|/System/Library/)' || true)"
if [ -n "$non_system_deps" ]; then
echo "Unexpected non-system dylibs:" >&2
echo "$non_system_deps" >&2
exit 1
fi
install -m 0755 bash ../../pkg/bin/bash
cat > ../../pkg/BUILD-INFO.txt <<INFO
bash_version=$version
target=macos-aarch64
macos_deployment_target=$MACOSX_DEPLOYMENT_TARGET
built_at_utc=$(date -u +%Y-%m-%dT%H:%M:%SZ)
INFO
cd ../../pkg
tarball="bash-$version-macos-aarch64.tar.gz"
tar -czf "../$tarball" bin/bash BUILD-INFO.txt
echo "tarball=$tarball" >> "$GITHUB_OUTPUT"
- name: Publish tarball to pkgs branch
if: steps.check.outputs.should_build == 'true'
run: |
set -euo pipefail
version="${{ steps.check.outputs.latest_version }}"
tarball="${{ steps.build.outputs.tarball }}"
pkg_dir="${{ steps.check.outputs.pkg_dir }}"
cd pkgs-worktree
mkdir -p "$pkg_dir"
find "$pkg_dir" -maxdepth 1 -type f \
-name 'bash-*-macos-aarch64.tar.gz' -delete
cp "../build/$tarball" "$pkg_dir/"
printf '%s\n' "$version" > "$pkg_dir/latest-version.txt"
git config user.name "github-actions[bot]"
git config user.email \
"41898282+github-actions[bot]@users.noreply.github.com"
git add "$pkg_dir"
if git diff --cached --quiet; then
echo "No package changes to publish"
exit 0
fi
git commit -s -m "bash: add $version macos aarch64 build"
git push origin HEAD:pkgs
- name: Report no update
if: steps.check.outputs.should_build != 'true'
run: |
echo "No new GNU Bash release detected for macOS aarch64"