Skip to content

Commit

Permalink
add install and fix workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
nqyy committed May 26, 2024
1 parent 953332b commit 77f4059
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 11 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install pip
run: python -m ensurepip --upgrade

- name: Install dependencies
- name: Run install script
run: |
python -m pip install --upgrade pip
python -m pip install hatch
chmod +x ./scripts/install.sh
./scripts/install.sh
- name: Cache packages
uses: actions/cache@v3
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ jobs:
with:
python-version: 3.11

- name: Install Pip
run: python -m ensurepip --upgrade

- name: Install Hatch
run: python -m pip install hatch
- name: Run install script
run: |
chmod +x ./scripts/install.bash
./scripts/install.bash
- name: Cache packages
uses: actions/cache@v3
Expand Down
97 changes: 97 additions & 0 deletions install.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/usr/bin/env bash

# Function to check for "-y" flag to skip prompts
for arg; do
if [ "$arg" = "-y" ]; then
# Set an environment variable when -y is present
export SKIP_PROMPT=true
else
export SKIP_PROMPT=false
fi
done

# Package installation functions
mbd_install_linux_packages() {
sudo apt-get update
if dpkg -s python3 python3-pip python3-venv libcairo2-dev libgirepository1.0-dev libffi-dev portaudio19-dev python3-gi python3-gi-cairo gir1.2-gtk-3.0 libgirepository1.0-dev >/dev/null 2>&1; then
echo "All required linux packages are already installed."
else
echo "Installing required packages without prompt..."
sudo apt-get install -y python3 python3-pip python3-venv
sudo apt-get install -y libcairo2-dev libgirepository1.0-dev
sudo apt-get install -y libffi-dev
sudo apt-get install -y portaudio19-dev
sudo apt install -y python3-gi python3-gi-cairo gir1.2-gtk-3.0
sudo apt-get install -y libgirepository1.0-dev
CFLAGS="-march=native" pip install pyaudio
python3 -m pip install hatch
fi
}

mbd_install_macos_packages() {
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
if command -v brew >/dev/null; then
echo "Homebrew is already installed."
else
echo "Installing Homebrew..."
NONINTERACTIVE=$SKIP_PROMPT /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
if brew list hatch cairo pygobject3 libffi >/dev/null 2>&1; then
echo "All required macos packages are already installed."
else
echo "Installing required packages..."
brew update
brew install hatch
brew install cairo
brew install pygobject3
brew install libffi
brew install portaudio

PKG_CONFIG_PATH="$(brew --prefix libffi)/lib/pkgconfig:$PKG_CONFIG_PATH"
export PKG_CONFIG_PATH
LDFLAGS="-L$(brew --prefix libffi)/lib"
export LDFLAGS
CPPFLAGS="-I$(brew --prefix libffi)/include"
export CPPFLAGS
fi
}

# Detect the operating system
OS=$(uname -s)

if [[ $OS == "Linux" ]]; then
if [[ "$SKIP_PROMPT" = false ]]; then
read -rp "Install required Linux packages? (y/n) " response
if [[ $response =~ ^[Yy]$ ]]; then
mbd_install_linux_packages
else
echo "Skipping linux package installation."
fi
else
mbd_install_linux_packages
fi

elif [[ $OS == "Darwin" ]]; then
if [[ "$SKIP_PROMPT" = false ]]; then
read -rp "Install required macOS packages? (y/n) " response
if [[ $response =~ ^[Yy]$ ]]; then
mbd_install_macos_packages
else
echo "Skipping package installation."
fi
else
mbd_install_macos_packages
fi
else
# Unsupported operating system
echo "Unsupported operating system: $OS"
exit 1
fi

if [[ -z "$CI" ]]; then
# shellcheck disable=SC1091
hatch run echo "Sourcing environment..."
source .mbodied/envs/mbodied/bin/activate
else
echo "CI environment detected. Skipping sourcing of environment."
fi

0 comments on commit 77f4059

Please sign in to comment.