Skip to content

Commit

Permalink
wrap cds so pwd is restored
Browse files Browse the repository at this point in the history
  • Loading branch information
joelmccracken committed Dec 27, 2024
1 parent 5c5c67a commit 12cc36f
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 27 deletions.
69 changes: 48 additions & 21 deletions ws_tool/lib/properties.bash
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,13 @@ prop_ws_check_workstation_dir_fix() {
# somehow figure out another way to do this?
TMPINST="$(mktemp -d "${TMPDIR:-/tmp}/ws-install-XXXXXXXXX")"
# installer of ws tool/project
cd "$TMPINST"
curl -L https://github.com/joelmccracken/workstation/archive/${WORKSTATION_VERSION}.tar.gz | tar zx
(
cd "$TMPINST";
curl -L https://github.com/joelmccracken/workstation/archive/${WORKSTATION_VERSION}.tar.gz | tar zx;

mkdir -p "$WORKSTATION_DIR"
mv "${TMPINST}"/workstation-*/{,.[^.]}* "$WORKSTATION_DIR"
mkdir -p "$WORKSTATION_DIR";
mv "${TMPINST}"/workstation-*/{,.[^.]}* "$WORKSTATION_DIR";
)
}

prop_ws_check_workstation_repo() {
Expand All @@ -164,11 +166,13 @@ prop_ws_check_workstation_repo() {
}

prop_ws_check_workstation_repo_fix() {
cd "$WORKSTATION_DIR"
git init .
git remote add origin "$WORKSTATION_REPO_GIT_ORIGIN"
git fetch
git reset --mixed "origin/$WORKSTATION_VERSION"
(
cd "$WORKSTATION_DIR";
git init .;
git remote add origin "$WORKSTATION_REPO_GIT_ORIGIN";
git fetch;
git reset --mixed "origin/$WORKSTATION_VERSION";
)
}

: "${WORKSTATION_DOTFILES_TRACK_GIT_DIR:=".git-dotfiles"}"
Expand All @@ -184,8 +188,10 @@ prop_ws_dotfiles_git_track() {

prop_ws_dotfiles_git_track_fix() {
export GIT_DIR="$WORKSTATION_DOTFILES_TRACK_GIT_DIR"
cd "$HOME"
git init
(
cd "$HOME";
git init
)
return 0
}

Expand Down Expand Up @@ -214,16 +220,22 @@ prop_ws_config_exists_fix() {
src_dir="$workstation_initial_config_dir_arg";
fi
mkdir -p "$WORKSTATION_CONFIG_DIR"
# not perfect, but not worth making much more complicated
cd "$src_dir"
for f in *; do
if [[ -e "$WORKSTATION_CONFIG_DIR/$f" ]]; then
echo "$WORKSTATION_CONFIG_DIR/$f: aleady exists, skipping"
else
echo "copying file to $WORKSTATION_CONFIG_DIR/$f"
cp -r "$f" "$WORKSTATION_CONFIG_DIR/$f";
fi
done

# hack, because if a relative dir is used for $workstation_initial_config_dir_arg
# we want it to go back...
(
cd "$ws_initial_pwd";
cd "$src_dir";
# not perfect, but not worth making much more complicated
for f in *; do
if [[ -e "$WORKSTATION_CONFIG_DIR/$f" ]]; then
echo "$WORKSTATION_CONFIG_DIR/$f: aleady exists, skipping"
else
echo "copying file to $WORKSTATION_CONFIG_DIR/$f"
cp -r "$f" "$WORKSTATION_CONFIG_DIR/$f";
fi
done
)
}

prop_ws_current_settings_symlink() {
Expand Down Expand Up @@ -269,3 +281,18 @@ prop_ws_current_settings_symlink_fix() {

ln -s "$src_settings_file" "$current_settings_file"
}

prop_ws_nix_daemon_installed() {
if which nix > /dev/null ; then
echo "nix command found"
echo 0
else
echo "nix command not found" 1>&3
echo 1
fi
}

: "${WORKSTATION_NIX_PM_VERSION:=nix-2.11.1}"
prop_ws_nix_daemon_installed_fix() {
sh <(curl -L https://releases.nixos.org/nix/$WORKSTATION_NIX_PM_VERSION/install) --daemon;
}
3 changes: 1 addition & 2 deletions ws_tool/my_config/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

workstation_props_angrist=()
workstation_props_angrist+=(prop_ws_current_settings_symlink)

workstation_props_angrist+=(prop_ws_nix_daemon_installed)

workstation_props_dotfiles_gitdir=".git-dotfiles"


workstation_props_dotfiles_angrist() {
ln_dotfile bashrc
ln_dotfile ghci
Expand Down
5 changes: 3 additions & 2 deletions ws_tool/my_config/run_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ rm -rf $HOME/.config/workstation

unset WORKSTATION_DIR
export WORKSTATION_NAME=angrist
export WORKSTATION_VERSION=workcomp
export WORKSTATION_VERSION
WORKSTATION_VERSION="$(git log -n 1 --format="%H")"

bash ws_install.sh

~/.config/workstation/workstation_source/ws_tool/ws bootstrap -n angrist --initial-config-dir ./my_config
~/.config/workstation/workstation_source/ws_tool/ws bootstrap -n angrist --initial-config-dir /my_config
20 changes: 20 additions & 0 deletions ws_tool/test/ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env sh

set -xeuo pipefail

rm -rf $HOME/.config/workstation

unset WORKSTATION_DIR
export WORKSTATION_VERSION="$GITHUB_SHA"

bash ws_install.sh

~/.config/workstation/workstation_source/ws_tool/ws bootstrap -n angrist --initial-config-dir ./my_config



if [ "$RUNNER_OS" == "macOS" ]; then
bash bootstrap-workstation.sh ci-macos $WORKSTATION_BOOTSTRAP_COMMIT
else
bash bootstrap-workstation.sh ci-ubuntu $WORKSTATION_BOOTSTRAP_COMMIT
fi
6 changes: 4 additions & 2 deletions ws_tool/test/installation_process.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ setup (){

# below we use the stuff from this project checkout however to test it
# HACK get the tool to actually run code from current local checkout
{ cd "$PROJECT_ROOT";
( cd "$PROJECT_ROOT";
git ls-files | while read -r gitfile; do
cp -r "$gitfile" "$WORKSTATION_DIR/$gitfile"
done;
}
)
# export WORKSTATION_DIR="${PROJECT_ROOT}"

cat <<-EOF > "${WORKSTATION_CONFIG_DIR}/settings.sh"
Expand All @@ -44,6 +44,7 @@ EOF
export WORKSTATION_DIR="${WORKSTATION_CONFIG_DIR}/workstation_source"
export WORKSTATION_VERSION=workcomp

(
cd "$(_mktemp "ws-installer-dl-dir")"
do_ws_install() {
bash <(curl "https://raw.githubusercontent.com/joelmccracken/workstation/refs/heads/${WORKSTATION_VERSION}/ws_tool/ws_install.sh")
Expand All @@ -65,4 +66,5 @@ EOF
run "${WORKSTATION_DIR}/ws_tool/ws" bootstrap

assert_success
)
}
2 changes: 2 additions & 0 deletions ws_tool/test/properties.bats
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,13 @@ setup (){
run prop_ws_config_exists
assert_success

(
cd "$workstation_initial_config_dir_arg"
for f in *; do
# utter insanity
assert [ "$(cat $f)" == "$(cat "$WORKSTATION_CONFIG_DIR/$f")" ]
done
)
}

@test "prop_ws_config_exists config already in place" {
Expand Down
7 changes: 7 additions & 0 deletions ws_tool/test/test_config/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
workstation_props_dotfiles_gitdir=".git-dotfiles"

workstation_props_ci_ubuntu=()
workstation_props_ci_ubuntu+=(prop_ws_current_settings_symlink)

workstation_props_ci_macos=()
workstation_props_ci_macos+=(prop_ws_current_settings_symlink)
1 change: 1 addition & 0 deletions ws_tool/test/test_config/settings.ci_macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WORKSTATION_NAME=ci_macos
1 change: 1 addition & 0 deletions ws_tool/test/test_config/settings.ci_ubuntu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WORKSTATION_NAME=ci_ubuntu
8 changes: 8 additions & 0 deletions ws_tool/test/test_config/settings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export WORKSTATION_CONFIG_DIR=$HOME/.config/workstation
export WORKSTATION_DIR=$WORKSTATION_CONFIG_DIR/workstation_source

workstation_names=(ci_macos ci_ubuntu);
workstation_descriptions_ci_macos="profile for macos on CI"
workstation_descriptions_ci_ubuntu="profile for ubuntu on CI"

[ -f "${WORKSTATION_CONFIG_DIR}/settings.current.sh" ] && . "settings.current.sh" || return 0
2 changes: 2 additions & 0 deletions ws_tool/ws
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

ws_script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

ws_initial_pwd="$PWD"

# set -x

. "${ws_script_dir}/lib/settings.bash"
Expand Down
2 changes: 2 additions & 0 deletions ws_tool/ws_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

TMPINST=$(mktemp -d "${TMPDIR:-/tmp}/ws-install.XXXXXXXXX")
# installer of ws tool/project
(
cd "$TMPINST"
curl -L https://github.com/joelmccracken/workstation/archive/${WORKSTATION_VERSION}.tar.gz | tar zx

mkdir -p "$WORKSTATION_DIR"
mv "${TMPINST}"/workstation-*/{,.[^.]}* "$WORKSTATION_DIR"
)

0 comments on commit 12cc36f

Please sign in to comment.