From 12cc36f17714acec146cbed54d9c5f6a5040b8f5 Mon Sep 17 00:00:00 2001 From: Joel McCracken Date: Thu, 26 Dec 2024 21:19:10 -0500 Subject: [PATCH] wrap cds so pwd is restored --- ws_tool/lib/properties.bash | 69 +++++++++++++------ ws_tool/my_config/config.sh | 3 +- ws_tool/my_config/run_setup.sh | 5 +- ws_tool/test/ci.sh | 20 ++++++ ws_tool/test/installation_process.bats | 6 +- ws_tool/test/properties.bats | 2 + ws_tool/test/test_config/config.sh | 7 ++ ws_tool/test/test_config/settings.ci_macos.sh | 1 + .../test/test_config/settings.ci_ubuntu.sh | 1 + ws_tool/test/test_config/settings.sh | 8 +++ ws_tool/ws | 2 + ws_tool/ws_install.sh | 2 + 12 files changed, 99 insertions(+), 27 deletions(-) create mode 100644 ws_tool/test/ci.sh create mode 100644 ws_tool/test/test_config/config.sh create mode 100644 ws_tool/test/test_config/settings.ci_macos.sh create mode 100644 ws_tool/test/test_config/settings.ci_ubuntu.sh create mode 100644 ws_tool/test/test_config/settings.sh diff --git a/ws_tool/lib/properties.bash b/ws_tool/lib/properties.bash index 1b5ce8c7..e6cdbd02 100644 --- a/ws_tool/lib/properties.bash +++ b/ws_tool/lib/properties.bash @@ -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() { @@ -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"}" @@ -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 } @@ -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() { @@ -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; +} diff --git a/ws_tool/my_config/config.sh b/ws_tool/my_config/config.sh index 88d4b70d..0f6fad7f 100644 --- a/ws_tool/my_config/config.sh +++ b/ws_tool/my_config/config.sh @@ -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 diff --git a/ws_tool/my_config/run_setup.sh b/ws_tool/my_config/run_setup.sh index b10dfea7..3d4d000a 100644 --- a/ws_tool/my_config/run_setup.sh +++ b/ws_tool/my_config/run_setup.sh @@ -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 diff --git a/ws_tool/test/ci.sh b/ws_tool/test/ci.sh new file mode 100644 index 00000000..184f9278 --- /dev/null +++ b/ws_tool/test/ci.sh @@ -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 diff --git a/ws_tool/test/installation_process.bats b/ws_tool/test/installation_process.bats index 70a414fa..638b4358 100644 --- a/ws_tool/test/installation_process.bats +++ b/ws_tool/test/installation_process.bats @@ -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" @@ -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") @@ -65,4 +66,5 @@ EOF run "${WORKSTATION_DIR}/ws_tool/ws" bootstrap assert_success + ) } diff --git a/ws_tool/test/properties.bats b/ws_tool/test/properties.bats index 5514d00f..0d738a70 100644 --- a/ws_tool/test/properties.bats +++ b/ws_tool/test/properties.bats @@ -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" { diff --git a/ws_tool/test/test_config/config.sh b/ws_tool/test/test_config/config.sh new file mode 100644 index 00000000..6e6d3fe7 --- /dev/null +++ b/ws_tool/test/test_config/config.sh @@ -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) diff --git a/ws_tool/test/test_config/settings.ci_macos.sh b/ws_tool/test/test_config/settings.ci_macos.sh new file mode 100644 index 00000000..ad6c38a7 --- /dev/null +++ b/ws_tool/test/test_config/settings.ci_macos.sh @@ -0,0 +1 @@ +WORKSTATION_NAME=ci_macos diff --git a/ws_tool/test/test_config/settings.ci_ubuntu.sh b/ws_tool/test/test_config/settings.ci_ubuntu.sh new file mode 100644 index 00000000..358a4f59 --- /dev/null +++ b/ws_tool/test/test_config/settings.ci_ubuntu.sh @@ -0,0 +1 @@ +WORKSTATION_NAME=ci_ubuntu diff --git a/ws_tool/test/test_config/settings.sh b/ws_tool/test/test_config/settings.sh new file mode 100644 index 00000000..c269d0de --- /dev/null +++ b/ws_tool/test/test_config/settings.sh @@ -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 diff --git a/ws_tool/ws b/ws_tool/ws index 3902728d..020b4fda 100755 --- a/ws_tool/ws +++ b/ws_tool/ws @@ -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" diff --git a/ws_tool/ws_install.sh b/ws_tool/ws_install.sh index d4f2cf20..32638691 100755 --- a/ws_tool/ws_install.sh +++ b/ws_tool/ws_install.sh @@ -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" +)