diff --git a/.github/workflows/end-to-end.yml b/.github/workflows/end-to-end.yml index 1124d84..62ba49e 100644 --- a/.github/workflows/end-to-end.yml +++ b/.github/workflows/end-to-end.yml @@ -41,31 +41,116 @@ jobs: - name: run-tests run: ./test.sh - # TODO: add this after figuring out a consistent way to create a non-root user without having to create specialised - # dockerfiles for each container type (linuxbrew refuses to install with the root user) - # docker: - # name: "end-to-end-${{ matrix.container }}" - # runs-on: ubuntu-20.04 - # container: ${{ matrix.container }} - # needs: cancel - # strategy: - # matrix: - # container: - # - centos:7 - # - centos:8 - # - debian:9 - # - debian:10 - # - fedora:32 - # - fedora:33 - # - linuxmintd/mint18-amd64 - # - linuxmintd/mint19-amd64 - # - linuxmintd/mint20-amd64 - # steps: - # - name: checkout - # uses: actions/checkout@v2 - # - name: install-bash - # run: ./install.sh bash | tee log.txt && bash -lc 'cat $AM_PROMPT/.sha' - # - name: install-zsh - # run: ./install.sh zsh | tee log.txt && zsh -lc 'cat $AM_PROMPT/.sha' - # - name: run-tests - # run: ./test.sh + win: + name: "end-to-end-${{ matrix.os }}" + runs-on: ${{ matrix.os }} + needs: cancel + strategy: + matrix: + os: + - windows-2019 + defaults: + run: + shell: wsl-bash {0} + steps: + - name: setup-wsl + uses: vampire/setup-wsl@v1 + - name: create-user + run: |- + apt-get update && apt-get install -y gosu sudo + gosu nobody true + + useradd --uid 1000 --user-group --system --create-home --no-log-init --groups tty --shell /bin/bash build + echo 'build ALL=(ALL) NOPASSWD:ALL' >>/etc/sudoers + chown -R build:build /home/build + chmod u=rwx,g=rx,o= /home/build + - name: checkout + uses: actions/checkout@v2 + - name: install-bash + run: |- + gosu build ./install.sh bash | tee log.txt + gosu build bash -lc 'cat $AM_PROMPT/.sha' + - name: install-zsh + run: |- + gosu build ./install.sh zsh | tee log.txt + gosu build zsh -lc 'cat $AM_PROMPT/.sha' + - name: run-tests + run: gosu build ./test.sh + + docker-apt: + name: "end-to-end-${{ matrix.container }}" + runs-on: ubuntu-20.04 + container: ${{ matrix.container }} + needs: cancel + strategy: + matrix: + container: + - debian:9 + - debian:10 + - linuxmintd/mint18-amd64 + - linuxmintd/mint19-amd64 + - linuxmintd/mint20-amd64 + steps: + - name: create-user + run: |- + apt-get update && apt-get install -y gosu sudo + gosu nobody true + + useradd --uid 1000 --user-group --system --create-home --no-log-init --groups tty --shell /bin/bash build + echo 'build ALL=(ALL) NOPASSWD:ALL' >>/etc/sudoers + chown -R build:build /home/build + chmod u=rwx,g=rx,o= /home/build + - name: checkout + uses: actions/checkout@v2 + - name: install-bash + run: |- + gosu build ./install.sh bash | tee log.txt + gosu build bash -lc 'cat $AM_PROMPT/.sha' + - name: install-zsh + run: |- + gosu build ./install.sh zsh | tee log.txt + gosu build zsh -lc 'cat $AM_PROMPT/.sha' + - name: run-tests + run: gosu build ./test.sh + + docker-yum: + name: "end-to-end-${{ matrix.container }}" + runs-on: ubuntu-20.04 + container: ${{ matrix.container }} + needs: cancel + strategy: + matrix: + container: + - centos:7 + - centos:8 + - fedora:32 + - fedora:33 + steps: + - name: create-user + run: |- + gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 + curl -o /usr/local/bin/gosu -SL "https://github.com/tianon/gosu/releases/download/1.11/gosu-amd64" + curl -o /usr/local/bin/gosu.asc -SL "https://github.com/tianon/gosu/releases/download/1.11/gosu-amd64.asc" + gpg --verify /usr/local/bin/gosu.asc + chmod +x /usr/local/bin/gosu + gosu nobody true + + yum update -y + yum install -y sudo + + useradd --uid 1000 --user-group --system --create-home --no-log-init \--groups tty --shell /bin/bash build + echo 'build ALL=(ALL) NOPASSWD:ALL' >>/etc/sudoers + chown -R build:build /home/build + chmod u=rwx,g=rx,o= /home/build + - name: checkout + uses: actions/checkout@v2 + - name: install-bash + run: |- + gosu build ./install.sh bash | tee log.txt + gosu build bash -lc 'cat $AM_PROMPT/.sha' + - name: install-zsh + run: |- + gosu build ./install.sh zsh | tee log.txt + gosu build zsh -lc 'cat $AM_PROMPT/.sha' + - name: run-tests + run: gosu build ./test.sh diff --git a/.releaserc.yml b/.releaserc.yml index 0b877d4..eb9fab8 100644 --- a/.releaserc.yml +++ b/.releaserc.yml @@ -1,7 +1,13 @@ plugins: - "@semantic-release/commit-analyzer" - "@semantic-release/release-notes-generator" - - "@semantic-release/github" + - "@semantic-release/changelog" + - path: "@semantic-release/exec" + prepareCmd: echo ${nextRelease.gitHead} > VERSION + - path: "@semantic-release/github" + assets: + - CHANGELOG.md + - VERSION branches: - master diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..d532e0e --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +b420dd99ffaa647cd1d8e97ad4b1e6914b03a811 \ No newline at end of file diff --git a/install.sh b/install.sh index 685ce4d..dc79153 100755 --- a/install.sh +++ b/install.sh @@ -3,6 +3,7 @@ set -e CLR_SUCCESS="\033[1;32m" # BRIGHT GREEN +CLR_WARN="\033[1;33m" # BRIGHT YELLOW CLR_CLEAR="\033[0m" # DEFAULT COLOR ECHO='echo' @@ -12,6 +13,7 @@ AM_PROMPT="$AM_HOME/prompt" # when not outputing to a tty, add spacing instead of colors if [ ! -t 1 ]; then CLR_SUCCESS="\n------------------------------------------------------------------------------------------------------------------------\n" + CLR_WARN=$CLR_SUCCESS CLR_CLEAR=$CLR_SUCCESS ECHO='printf' fi @@ -116,8 +118,7 @@ __am_prompt_install() { local CURL_OPT="$CURL_OPT -H 'Authorization: token $GITHUB_TOKEN'" fi - local SHA_URI="https://api.github.com/repos/automotivemastermind/prompt/commits/master" - local PROMPT_SHA=$(curl $CURL_OPT $SHA_URI | grep sha | head -n 1 | sed 's#.*\:.*"\(.*\).*",#\1#') + local PROMPT_SHA=$(cat VERSION) local PROMPT_SHA_PATH=$HOME/.am/prompt/.sha local PROMPT_CHANGELOG_URI="https://github.com/automotivemastermind/prompt/blob/$PROMPT_SHA/CHANGELOG.md" diff --git a/src/bash/scripts/eval/set-gcloud-path b/src/bash/scripts/eval/set-gcloud-path index 8df4a88..5aea02a 100755 --- a/src/bash/scripts/eval/set-gcloud-path +++ b/src/bash/scripts/eval/set-gcloud-path @@ -13,7 +13,7 @@ __am_prompt_set_gcloud_path() { fi # add gcloud to the path - export PATH="$HOME/.gcloud/bin":$PATH + export PATH="$HOME/.gcloud/bin:$PATH" fi local GCLOUD_CMD=$(command -v gcloud) diff --git a/src/sh/install/centos.sh b/src/sh/install/centos.sh index 6a6d4e5..375a087 100755 --- a/src/sh/install/centos.sh +++ b/src/sh/install/centos.sh @@ -8,10 +8,8 @@ __am_prompt_install_centos() { $ECHO "${CLR_SUCCESS}installing development tools...${CLR_CLEAR}" $SUDO $YUM groupinstall -y "Development Tools" - for pkg in $PACKAGES; do - $ECHO "${CLR_SUCCESS}installing $pkg...${CLR_CLEAR}" - $SUDO $YUM install -y ${pkg} - done + $ECHO "${CLR_SUCCESS}installing $PACKAGES...${CLR_CLEAR}" + $SUDO $YUM install -y ${PACKAGES} . "$AM_PROMPT/sh/install/linux.sh" } diff --git a/src/sh/install/darwin.sh b/src/sh/install/darwin.sh index 97b5bd4..c1bcfe6 100755 --- a/src/sh/install/darwin.sh +++ b/src/sh/install/darwin.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash set -e @@ -8,14 +8,39 @@ __am_prompt_ensure_rosetta() { if [ "$(uname -m)" = "x86_64" ]; then # install homebrew using defaults - __am_prompt_install_darwin + __am_prompt_install_intel # move on immediately return $? fi + $ECHO ${CLR_WARN} + $ECHO "##############################################################################" + $ECHO + $ECHO " DETECTED APPLE SILICON " + $ECHO + $ECHO " Apple Silicon is not yet officially supported by homebrew. We will install " + $ECHO " homebrew in the following locations: " + $ECHO " - /opt/homebrew : arm64e native (DEFAULT) " + $ECHO " - /usr/local : x86_64 emulation via Rosetta 2 " + $ECHO + $ECHO " The Apple Silicon (arm64e) version will be the default as it will be placed " + $ECHO " on the PATH variable before the native version. This is compatible with more" + $ECHO " formulae at this time. To use the intel (x86_64) version, you can use the " + $ECHO " \`brew-intel\` alias. For example: " + $ECHO + $ECHO " brew-intel install git " + $ECHO + $ECHO " NOTE: Installation will take significantly longer as most formulae will be " + $ECHO " built from source. NOT ALL FORMULA ARE GAURANTEED TO WORK. INCLUDING " + $ECHO " THOSE WE ATTEMPT TO INSTALL BY DEFAULT WITHIN PROMPT! We do this to " + $ECHO " enable these formulae via install as soon as they start working. " + $ECHO + $ECHO "##############################################################################" + $ECHO ${CLR_CLEAR} + # install rosetta 2 - softwareupdate --install-rosetta --agree-to-license + softwareupdate --install-rosetta --agree-to-license 2>/dev/null # create the homebrew directory if [ ! -d "/opt/homebrew" ]; then @@ -27,24 +52,62 @@ __am_prompt_ensure_rosetta() { sudo chown /opt/homebrew $(whoami):staff fi + # install homebrew for apple silicon + __am_prompt_install_arm64 + # install homebrew in rosetta - __am_prompt_install_darwin x86_64 /usr/local + __am_prompt_install_rosetta +} + +__am_prompt_install_intel() { + $ECHO ${CLR_SUCCESS} + $ECHO "##############################################################################" + $ECHO "INSTALLING VIA HOMEBREW FOR INTEL MACS" + $ECHO "##############################################################################" + $ECHO ${CLR_CLEAR} + + if ! type "${BREW_CMD}" 1>/dev/null 2>&1; then + $ECHO "${CLR_SUCCESS}installing homebrew...${CLR_CLEAR}" + /bin/bash -c "CI=true $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh) && /usr/local/bin/brew config" + fi - # install homebrew for apple silicon - __am_prompt_ensure_rosetta $(uname -m) /opt/homebrew + __am_prompt_install_darwin "/usr/local/bin/brew" } -__am_prompt_install_darwin() { - local BREWS='openssl git go nvm python' - local ARCH=${1:-"x86-64"} - local HOMEBREW_PREFIX="${2:-/usr/local}" - local BREW_CMD="${HOMEBREW_PREFIX}/bin/brew" +__am_prompt_install_rosetta() { + $ECHO ${CLR_SUCCESS} + $ECHO "##############################################################################" + $ECHO "INSTALLING VIA HOMEBREW FOR ROSETTA 2 (x86_64)" + $ECHO "##############################################################################" + $ECHO ${CLR_CLEAR} + + if ! type "${BREW_CMD}" 1>/dev/null 2>&1; then + $ECHO "${CLR_SUCCESS}installing homebrew...${CLR_CLEAR}" + arch -x86_64 /bin/bash -c "HOMEBREW_PREFIX=/usr/local CI=true $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh) && /usr/local/bin/brew config" + fi + + __am_prompt_install_darwin "arch -x86_64 /usr/local/bin/brew" +} + +__am_prompt_install_arm64() { + $ECHO ${CLR_SUCCESS} + $ECHO "##############################################################################" + $ECHO "INSTALLING VIA HOMEBREW FOR APPLE SILICON (arm64e)" + $ECHO "##############################################################################" + $ECHO ${CLR_CLEAR} if ! type "${BREW_CMD}" 1>/dev/null 2>&1; then $ECHO "${CLR_SUCCESS}installing homebrew...${CLR_CLEAR}" - arch -${ARCH} /bin/bash -c "HOMEBREW_PREFIX=${HOMEBREW_PREFIX} CI=true $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh) && ${BREW_CMD} config" + arch -x86_64 /bin/bash -c "HOMEBREW_PREFIX=/opt/homebrew CI=true $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh) && /opt/homebrew/bin/brew config" fi + __am_prompt_install_darwin "arch -arm64e /opt/homebrew/bin/brew" +} + +__am_prompt_install_darwin() { + local BREWS='openssl git go nvm python gpg pinentry-mac' + local BREW_CMD=${1:-"/usr/local/bin/brew"} + $ECHO "${CLR_SUCCESS}updating homebrew...${CLR_CLEAR}" ${BREW_CMD} update diff --git a/src/sh/install/debian.sh b/src/sh/install/debian.sh index e8c1587..08051d9 100755 --- a/src/sh/install/debian.sh +++ b/src/sh/install/debian.sh @@ -7,10 +7,8 @@ __am_prompt_install_debian() { $ECHO "${CLR_SUCCESS}updating software repositories...${CLR_CLEAR}" $SUDO apt-get update - for pkg in $PACKAGES; do - $ECHO "${CLR_SUCCESS}installing $pkg...${CLR_CLEAR}" - $SUDO apt-get install -y ${pkg} - done + $ECHO "${CLR_SUCCESS}installing $PACKAGES...${CLR_CLEAR}" + $SUDO apt-get install -y ${PACKAGES} $ECHO "${CLR_SUCCESS}removing unnecessary dependencies...${CLR_CLEAR}" $SUDO apt-get autoremove -y @@ -19,4 +17,3 @@ __am_prompt_install_debian() { } __am_prompt_install_debian - diff --git a/src/sh/install/linux.sh b/src/sh/install/linux.sh index 534fe31..0ae917b 100755 --- a/src/sh/install/linux.sh +++ b/src/sh/install/linux.sh @@ -2,7 +2,7 @@ __am_prompt_install_linux() { - local BREWS='gcc git' + local BREWS='gcc git gpg' if ! type brew 1>/dev/null 2>&1; then $ECHO "${CLR_SUCCESS}installing homebrew...${CLR_CLEAR}" diff --git a/src/sh/profile b/src/sh/profile index 521edff..dbfd1be 100755 --- a/src/sh/profile +++ b/src/sh/profile @@ -70,6 +70,13 @@ fi export HISTCONTROL=ignoredubs +# detect the apple silicon brew path +if [ -f /opt/homebrew/bin/brew ]; then + + # force update the path + export PATH="/opt/homebrew/bin:$PATH" +fi + if type brew 1>/dev/null 2>&1; then export LOCAL_PREFIX=$(brew --prefix) elif [ -d $LOCALAPPDATA/git ]; then @@ -93,7 +100,7 @@ fi # test for prompt bin if [ -d "$AM_PROMPT/user/bin" ]; then # append prompt to path - export PATH="$PATH:$AM_PROMPT/user/bin" + export PATH="$AM_PROMPT/user/bin:$PATH" fi # evaluate eval scripts diff --git a/src/sh/scripts/add-var b/src/sh/scripts/add-var index b677df5..a402989 100755 --- a/src/sh/scripts/add-var +++ b/src/sh/scripts/add-var @@ -30,10 +30,10 @@ __am_prompt_add_var() { local VARIABLE="$1"=\"$2\" local VAR_PATH="$AM_PROMPT/user/variables.sh" - echo 'Adding varable: $VARIABLE' + echo "add-var: adding varable: $VARIABLE" echo >> "$VAR_PATH" echo "$VARIABLE" >> "$VAR_PATH" - . "$VAR_PATH" + source "$VAR_PATH" } __am_prompt_add_var $@ diff --git a/src/sh/scripts/darwin/eval/pandoc-path b/src/sh/scripts/darwin/eval/pandoc-path deleted file mode 100755 index 846a4e7..0000000 --- a/src/sh/scripts/darwin/eval/pandoc-path +++ /dev/null @@ -1,5 +0,0 @@ -#! /usr/bin/env sh - -if type /usr/libexec/path_helper 1>/dev/null 2>&1; then - eval "$(/usr/libexec/path_helper)" -fi diff --git a/src/sh/scripts/darwin/eval/set-brew-path b/src/sh/scripts/darwin/eval/set-brew-path new file mode 100755 index 0000000..3b2de84 --- /dev/null +++ b/src/sh/scripts/darwin/eval/set-brew-path @@ -0,0 +1,11 @@ +#! /usr/bin/env sh + +# -- alias for homebrew versions + +if [ -f /usr/local/bin/brew ]; then + alias brew-intel='arch -x86_64 /usr/local/bin/brew' +fi + +if [ -f /opt/homebrew/bin/brew ]; then + alias brew-arm='arch -arm64e /opt/homebrew/bin/brew' +fi diff --git a/src/sh/scripts/darwin/install-pandoc b/src/sh/scripts/darwin/install-pandoc index 3b9fbb3..6c5e689 100755 --- a/src/sh/scripts/darwin/install-pandoc +++ b/src/sh/scripts/darwin/install-pandoc @@ -6,7 +6,7 @@ __am_prompt_pandoc_install() { brew install pandoc librsvg brew tap homebrew/cask brew cask install basictex - eval "$(/usr/libexec/path_helper)" + . <(/usr/libexec/path_helper -s) echo echo "You will be asked for admin credentials to install tex plugins" diff --git a/src/sh/scripts/eval/set-brew-path b/src/sh/scripts/eval/set-brew-path index 480600e..381ca71 100755 --- a/src/sh/scripts/eval/set-brew-path +++ b/src/sh/scripts/eval/set-brew-path @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash if [ -f "$HOME/.linuxbrew/bin/brew" ]; then eval $("$HOME/.linuxbrew/bin/brew" shellenv) diff --git a/src/sh/scripts/eval/set-gpg-agent b/src/sh/scripts/eval/set-gpg-agent index bd434df..c2445d1 100755 --- a/src/sh/scripts/eval/set-gpg-agent +++ b/src/sh/scripts/eval/set-gpg-agent @@ -1,5 +1,11 @@ #!/usr/bin/env sh +# determine if gpgconf is available on the system +if ! type gpgconf 1>/dev/null 2>&1; then + # move on immediately + return +fi + # determine if this is a tty if [ -t 1 ]; then diff --git a/src/sh/scripts/remove-var b/src/sh/scripts/remove-var index 29de0b7..3a9d46f 100755 --- a/src/sh/scripts/remove-var +++ b/src/sh/scripts/remove-var @@ -5,7 +5,7 @@ if [ ! -z "${AM_PROMPT_DEBUG:-}" ]; then fi __am_prompt_remove_var_usage() { - echo 'remove-var ' + echo 'remove-var ' echo ' name : a name for your variable' } diff --git a/src/sh/scripts/use-shell b/src/sh/scripts/use-shell index 39faebd..330d57d 100755 --- a/src/sh/scripts/use-shell +++ b/src/sh/scripts/use-shell @@ -10,7 +10,9 @@ __am_prompt_use_shell() { exit 1 fi - if type brew 1>/dev/null 2>&1; then + if [ -f /opt/homebrew/bin/brew ]; then + local LOCAL_PREFIX=$(/opt/homebrew/bin/brew --prefix) + elif type brew 1>/dev/null 2>&1; then local LOCAL_PREFIX=$(brew --prefix) elif [ -d $LOCALAPPDATA/git ]; then local LOCAL_PREFIX=$(echo "/$LOCALAPPDATA/git" | sed -e 's/\\/\//g' -e 's/://') diff --git a/src/zsh/install/darwin.sh b/src/zsh/install/darwin.sh index bd79a12..9dc00c0 100755 --- a/src/zsh/install/darwin.sh +++ b/src/zsh/install/darwin.sh @@ -16,22 +16,19 @@ __am_prompt_install_darwin() { fi done - # test to see if the zsh completion dir is specified - if [ ! -z "${ZSH_COMPLETION_DIR:-}" ]; then - - # iterate over each completion - for completion in $ZSH_COMPLETION_DIR/*; do + # set permissions on the site-functions paths + sudo chmod u=rwx,go=rx "$LOCAL_PREFIX/share/zsh" + sudo chown $(whoami) "$LOCAL_PREFIX/share/zsh" - # test for invalid completion - if [ ! -e $completion ]; then + sudo chmod u=rwx,go=rx "$LOCAL_PREFIX/share/zsh/site-functions" + sudo chown $(whoami) "$LOCAL_PREFIX/share/zsh/site-functions" - # let the user know we're removing the invalid completion - $ECHO "${CLR_WARN}removing: $completion as it no longer exists...${CLR_CLEAR}" + # test to see if the zsh completion dir is specified + if [ ! -z "${ZSH_COMPLETION_DIR:-}" ]; then - # remove the completion - rm -f $completion - fi - done + # set permissions on the script directory + sudo chmod u=rwx,go=rx $ZSH_COMPLETION_DIR + sudo chown $(whoami) $ZSH_COMPLETION_DIR fi } diff --git a/src/zsh/scripts/eval/set-completion b/src/zsh/scripts/eval/set-completion index 6b9e5d0..f1aa97e 100755 --- a/src/zsh/scripts/eval/set-completion +++ b/src/zsh/scripts/eval/set-completion @@ -3,14 +3,6 @@ # use case sensitive match followed by case-insensitive match zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' -if type gulp 1>/dev/null 2>&1; then - . <(gulp --completion=zsh) -fi - -if type grunt 1>/dev/null 2>&1; then - . <(grunt --completion=zsh) -fi - if type kubectl 1>/dev/null 2>&1; then . <(kubectl completion zsh) fi diff --git a/test/sh/scripts/set-gpg-agent.test.sh b/test/sh/scripts/set-gpg-agent.test.sh new file mode 100755 index 0000000..df492ff --- /dev/null +++ b/test/sh/scripts/set-gpg-agent.test.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env sh + +set -eu + +echo 'test gpg-agent' +./src/sh/scripts/eval/set-gpg-agent