-
Notifications
You must be signed in to change notification settings - Fork 12
138 lines (136 loc) · 5.79 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: ci
on:
pull_request:
push:
branches: [main]
workflow_dispatch:
jobs:
check:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-14, ubuntu-latest]
steps:
- name: Add Homebrew to $PATH
if: runner.os == 'Linux'
run: |
# mitigate https://github.com/actions/runner-images/issues/6283
echo "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" >>"$GITHUB_PATH"
- uses: actions/checkout@v4
- name: Install Prettier
run: npm i -g prettier@'^3'
- name: Check web code formatting with Prettier
run: prettier --check .
- name: Install formatters with Homebrew
run: brew install shfmt taplo
- name: Check shell script formatting with shfmt
run: shfmt -d -i 2 .
- name: Install ShellCheck (https://github.com/koalaman/shellcheck) on macOS
if: runner.os == 'macOS'
run: brew install bash shellcheck
- name: Check shell script formatting with ShellCheck
run: |
shopt -s globstar nullglob
set -- **/*.{sh,bash}
if [ -n "$1" ]; then
echo "Checking $@"
shellcheck "$@"
else
echo "No shell scripts for ShellCheck to check."
fi
shell: bash
env:
SHELLCHECK_OPTS: -e SC1071 -e SC1090 -e SC1091
- name: Check TOML formatting with Taplo
run: |
taplo check .taplo.toml
taplo check --schema https://starship.rs/config-schema.json .config/starship.toml
taplo fmt --check **/*.toml
test:
if: github.event_name != 'push'
needs: [check]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-14, ubuntu-latest]
timeout-minutes: 100
env:
STRAP_CI: 1
STRAP_DEBUG: 1
STRAP_DOTFILES_BRANCH: ${{ github.ref }}
STRAP_GIT_EMAIL: [email protected]
STRAP_GIT_NAME: GitHub Actions
STRAP_GITHUB_USER: br3ndonland
steps:
- name: Add Homebrew to $PATH
if: runner.os == 'Linux'
run: |
# mitigate https://github.com/actions/runner-images/issues/6283
echo "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" >>"$GITHUB_PATH"
- name: Set bootstrap script URL
run: |
STRAP_SCRIPT_URL="https://raw.githubusercontent.com/$STRAP_GITHUB_USER/dotfiles/$STRAP_DOTFILES_BRANCH/bootstrap.sh"
echo "STRAP_SCRIPT_URL=$STRAP_SCRIPT_URL"
echo "STRAP_SCRIPT_URL=$STRAP_SCRIPT_URL" >>"$GITHUB_ENV"
- name: Clean up Homebrew
run: |
command -v brew &>/dev/null && brew test-bot --only-cleanup-before ||
echo "Homebrew not found."
- name: Clean up macOS
if: runner.os == 'macOS'
run: |
sudo rm -rf /usr/local/Caskroom /usr/local/Homebrew /usr/local/bin/brew \
/usr/local/.??* /Applications/Xcode.app /Library/Developer/CommandLineTools
- name: Create a non-admin user account
run: |
username=standard-user
if ${{ runner.os == 'Linux' }}; then
sudo adduser --disabled-password --gecos "" $username
home_prefix=/home
elif ${{ runner.os == 'macOS' }}; then
# TODO: admin user is being created
sudo sysadminctl -addUser $username
home_prefix=/Users
fi
echo "NON_ADMIN_USER=$username" >>"$GITHUB_ENV"
echo "NON_ADMIN_USER_HOME=$home_prefix/$username" >>"$GITHUB_ENV"
- name: >
Run bootstrap.sh with a non-admin non-sudo user without Homebrew installed
(Homebrew installation requires sudo, so this step should error)
id: bootstrap-non-admin-non-sudo
run: |
sudo \
--preserve-env=STRAP_CI,STRAP_DEBUG,STRAP_DOTFILES_BRANCH,STRAP_GIT_EMAIL,STRAP_GIT_NAME,STRAP_GITHUB_USER,STRAP_SCRIPT_URL \
-u "$NON_ADMIN_USER" bash -c '/usr/bin/env bash -c "$(curl -fsSL ${{ env.STRAP_SCRIPT_URL }})"'
working-directory: ${{ env.NON_ADMIN_USER_HOME }}
continue-on-error: true
- run: |
echo "Homebrew installation requires sudo, so non-admin non-sudo should fail"
exit 1
if: steps.bootstrap-non-admin-non-sudo.outcome == 'success'
- name: Run bootstrap.sh with a non-admin sudo user without Homebrew installed
run: |
# TODO: need macOS command for adding sudo
# sudo usermod -aG sudo "$NON_ADMIN_USER"
SUDOERS_FILE="/etc/sudoers.d/$NON_ADMIN_USER"
echo "$NON_ADMIN_USER ALL=(ALL) NOPASSWD:ALL" | sudo tee "$SUDOERS_FILE"
sudo chmod 0440 "$SUDOERS_FILE"
sudo \
--preserve-env=STRAP_CI,STRAP_DEBUG,STRAP_DOTFILES_BRANCH,STRAP_GIT_EMAIL,STRAP_GIT_NAME,STRAP_GITHUB_USER,STRAP_SCRIPT_URL \
-u "$NON_ADMIN_USER" bash -c '/usr/bin/env bash -c "$(curl -fsSL ${{ env.STRAP_SCRIPT_URL }})"'
working-directory: ${{ env.NON_ADMIN_USER_HOME }}
- name: Run bootstrap.sh
run: /usr/bin/env bash -c "$(curl -fsSL $STRAP_SCRIPT_URL)"
- name: Rerun bootstrap.sh to test idempotence
run: bash "$HOME/.dotfiles/bootstrap.sh"
- name: Rerun bootstrap.sh with a non-admin user after Homebrew has been installed
run: |
sudo \
--preserve-env=STRAP_CI,STRAP_DEBUG,STRAP_DOTFILES_BRANCH,STRAP_GIT_EMAIL,STRAP_GIT_NAME,STRAP_GITHUB_USER,STRAP_SCRIPT_URL \
-u "$NON_ADMIN_USER" bash -c '/usr/bin/env bash "${{ env.NON_ADMIN_USER_HOME }}/.dotfiles/bootstrap.sh"'
working-directory: ${{ env.NON_ADMIN_USER_HOME }}
- name: Check Homebrew configuration
run: brew config
- name: Check for potential problems with brew doctor
run: brew doctor || echo "Potential problems detected. See output for details."