Skip to content

Commit

Permalink
More Homebrew .pkg improvements
Browse files Browse the repository at this point in the history
- test on more macOS versions and improve the test names
- add a more resilient and less disruptive version of changing `git`'s
 `safe.directory` configuration
  • Loading branch information
MikeMcQuaid committed Oct 4, 2023
1 parent bb39727 commit 5c5ac49
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
19 changes: 15 additions & 4 deletions .github/workflows/pkg-installer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,25 @@ jobs:
path: Homebrew-${{ steps.homebrew-version.outputs.version }}.pkg
test:
needs: build
name: "test (${{matrix.name}})"
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
# Intel (free)
- runner: macos-latest
# Apple Silicon (paid)
- runner: macos-latest-xlarge
# Intel
- runner: macos-12
name: macos-12-x86_64
- runner: macos-13
name: macos-13-x86_64
# Apple Silicon
- runner: macos-13-xlarge
name: macos-13-arm64
# TODO: add when available
# - runner: macos-14
# name: macos-14-x86_64
# - runner: macos-14-xlarge
# name: macos-14-arm64
steps:
- name: Download installer from GitHub Actions
uses: actions/download-artifact@v3
Expand Down
29 changes: 27 additions & 2 deletions package/scripts/postinstall
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,35 @@ fi
# add Git to path
export PATH="/Library/Developer/CommandLineTools/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:${PATH}"

# helpers for setting/unsetting Git's safe directory setting
set_git_safe_directory() {
if git config --global --get-all safe.directory | grep -q "${1}"
then
return
fi
SET_GIT_SAFE_DIRECTORY="${1}"
git config --global --add safe.directory "${1}"
}
unset_git_safe_directory() {
if [[ -z "${SET_GIT_SAFE_DIRECTORY-}" ]]
then
return
fi

git config --global --unset safe.directory "${1}" || git config --global --unset-all safe.directory
if [[ ${SET_GIT_SAFE_DIRECTORY-} == "${1}" ]]
then
unset SET_GIT_SAFE_DIRECTORY
fi
}

# reset Git repository
cd "${homebrew_directory}"
git config --global --add safe.directory "${homebrew_directory}"
set_git_safe_directory "${homebrew_directory}"
git reset --hard
git checkout --force master
git branch | grep -v '\*' | xargs -n 1 git branch --delete --force || true
git config --global --unset safe.directory "${homebrew_directory}"
unset_git_safe_directory "${homebrew_directory}"

# move to /usr/local if on x86_64
if [[ $(uname -m) == "x86_64" ]]
Expand All @@ -36,8 +58,11 @@ then
then
cp -pRL "${homebrew_directory}/.git" "/usr/local/Homebrew/"
mv "${homebrew_directory}/cache_api" "/usr/local/Homebrew/"

set_git_safe_directory /usr/local/Homebrew
git -C /usr/local/Homebrew reset --hard
git -C /usr/local/Homebrew checkout --force master
unset_git_safe_directory /usr/local/Homebrew
else
mkdir -vp /usr/local/bin
mv "${homebrew_directory}" "/usr/local/Homebrew/"
Expand Down

0 comments on commit 5c5ac49

Please sign in to comment.