Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Create bootstrap CI check #52

Merged
merged 14 commits into from
Nov 8, 2024
Merged
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
22 changes: 22 additions & 0 deletions .github/workflows/bootstrap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: Bootstrap
permissions: read-all
on: # yamllint disable-line rule:truthy
pull_request:
branches: [main]

jobs:
bootstrap:
strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- name: Bootstrap
env:
BRANCH: ${{ github.head_ref }}
run: |
curl -L https://raw.githubusercontent.com/martimlobao/dotfiles/"${BRANCH}"/bootstrap.sh \
| bash -s -- -b "${BRANCH}" -y
2 changes: 2 additions & 0 deletions .github/workflows/lint_pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
uses: luizm/action-sh-checker@master
env:
SHFMT_OPTS: -s
with:
sh_checker_checkbashisms_enable: true
yamllint:
name: Run yamllint
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bash <(curl -L dot.lobao.io)
To run the script without interactive prompts, run the following command:

```bash
curl -L http://dot.lobao.io | bash -s -- --yes
curl -L http://dot.lobao.io | bash -s -- -y
```

### 1Password requirements
Expand All @@ -42,7 +42,7 @@ curl -L http://dot.lobao.io | bash -s -- --yes
- `op://Private/Charles/registered name` and `op://Private/Charles/license key` to register Charles
- SSH keys for AWS

## Thanks
## Thanks and inspiration

Several people and repositories have contributed to or been a source of inspiration for this repository:

Expand Down
3 changes: 2 additions & 1 deletion apps.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ shfmt = "formula" # Autoformat shell script source code
trunk-io = "cask" # Developer experience toolkit used to check, test, merge, and monitor code
visual-studio-code = "cask" # Open-source code editor
warp = "cask" # Rust-based terminal
yamllint = "formula" # Linter for YAML files

[work]
awscli = "formula" # Official Amazon AWS command-line interface
aws-sso-cli = "formula" # Securely manage AWS API credentials using AWS SSO
awscli = "formula" # Official Amazon AWS command-line interface
tunnelblick = "cask" # Free and open-source OpenVPN client

[fonts]
Expand Down
32 changes: 28 additions & 4 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,43 @@
set -euo pipefail

DOTPATH=${HOME}/.dotfiles
BRANCH=""
YES=false
while getopts b:y flag; do
case "${flag}" in
b) BRANCH=${OPTARG} ;;
y) YES=true ;;
*) echo "Invalid option: -${OPTARG}" && exit 1 ;;
esac
done

echo -e "\033[1;34m🥾 Bootstrapping dotfiles\033[0m"

if [[ ! -d ${DOTPATH} ]]; then
git clone https://github.com/martimlobao/dotfiles.git "${DOTPATH}"
echo -e "\033[1;32m✅ Cloned ${DOTPATH}\033[0m"
if [[ -z ${BRANCH} ]]; then
echo -e "\033[1;33m🔗 Cloning dotfiles...\033[0m"
git clone https://github.com/martimlobao/dotfiles.git "${DOTPATH}"
echo -e "\033[1;32m✅ Cloned Dotfiles to ${DOTPATH}\033[0m"
else
echo -e "\033[1;33m🔗 Cloning dotfiles on branch ${BRANCH}...\033[0m"
git clone https://github.com/martimlobao/dotfiles.git --branch "${BRANCH}" "${DOTPATH}"
echo -e "\033[1;32m✅ Cloned Dotfiles to ${DOTPATH} on branch ${BRANCH}\033[0m"
fi
else
echo -e "\033[1;34m✅ Dotfiles already downloaded to ${DOTPATH}\033[0m"
if [[ -z ${BRANCH} ]]; then
echo -e "\033[1;34m✅ Dotfiles already downloaded to ${DOTPATH}\033[0m"
else
echo -e "\033[1;34m✅ Dotfiles already downloaded to ${DOTPATH}, checking out branch ${BRANCH}\033[0m"
cd "${DOTPATH}"
git stash
git checkout "${BRANCH}"
git pull origin "${BRANCH}"
fi
fi

cd "${DOTPATH}"

if [[ ${1-} == "--yes" ]] || [[ ${1-} == "-y" ]]; then
if [[ ${YES} == true ]]; then
./run.sh -y
else
./run.sh
Expand Down
7 changes: 6 additions & 1 deletion linkme/.functions
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#!/usr/bin/env bash

# Print installed apps in apps.toml
function apps() {
bat -P "${DOTPATH}/apps.toml"
}

# Run .install.sh
function appsync() {
function syncapps() {
bash "${DOTPATH}/install.sh"
}

Expand Down
13 changes: 11 additions & 2 deletions linkme/.zprofile
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Homebrew
eval "$(/opt/homebrew/bin/brew shellenv)"
if [[ ${CI} == "true" ]]; then
# Exit on error for CI
set -e
fi

# Homebrew on macOS or Linux
if [[ "$(uname)" == "Darwin" ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
else
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi

# Add uv to PATH
export PATH="$HOME/.local/bin:$PATH"
2 changes: 1 addition & 1 deletion linkme/.zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ZSH_THEME="robbyrussell"

# Uncomment one of the following lines to change the auto-update behavior
# zstyle ':omz:update' mode disabled # disable automatic updates
zstyle ':omz:update' mode auto # update automatically without asking
zstyle ':omz:update' mode auto # update automatically without asking
# zstyle ':omz:update' mode reminder # just remind me to update when it's time

# Uncomment the following line to change how often to auto-update (in days).
Expand Down
40 changes: 33 additions & 7 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ root=$(realpath "${DOTPATH:-$(dirname "$(realpath "$0")")}")
# Source the bash_traceback.sh file
source "${root}/bash_traceback.sh"

###############################################################################
# OS and architecture detection #
###############################################################################
os="$(uname)"
# If os is neither Linux or Darwin, exit 1
if [[ ${os} != 'Darwin' ]] && [[ ${os} != 'Linux' ]]; then
echo -e "❌ \033[1;31mError: Unsupported OS: ${os}\033[0m"
exit 1
fi
echo -e "\033[1;33m💻 OS detected:\033[0m ${os}"

archname="$(arch)"
echo -e "\033[1;33m💻 Arch detected:\033[0m ${archname}"

###############################################################################
# Install Homebrew #
###############################################################################
Expand All @@ -26,13 +40,11 @@ echo -e "\033[1;33m🚀 Running dotsync.sh...\033[0m"
sleep 1
./dotsync.sh "${1-}"

###############################################################################
# Local settings and variables #
###############################################################################
echo
echo -e "\033[1;33m🚀 Running local.sh...\033[0m"
sleep 1
./local.sh "${1-}"
# Linux is not supported after this point
if [[ ${os} == "Linux" ]]; then
echo -e "\033[1;33m ⛔️ Warning: Linux is not supported after this point.\033[0m"
exit 0
fi

###############################################################################
# macOS preferences #
Expand All @@ -41,6 +53,20 @@ sleep 1
# echo -e "\033[1;33m🚀 Running macos.sh...\033[0m"
# sudo ./macos.sh

# CI is not supported after this point
if [[ ${GITHUB_ACTIONS} == "true" ]]; then
echo -e "\033[1;33m ⛔️ Warning: macOS is not supported in CI after this point.\033[0m"
exit 0
fi

###############################################################################
# Local settings and variables #
###############################################################################
echo
echo -e "\033[1;33m🚀 Running local.sh...\033[0m"
sleep 1
./local.sh "${1-}"

###############################################################################
# Install apps and software #
###############################################################################
Expand Down