Skip to content

Fix install script's check for previous installation #189

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

Merged
merged 3 commits into from
Dec 20, 2021
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
75 changes: 75 additions & 0 deletions .github/workflows/test-install-script.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,78 @@ jobs:
shell: bash
run: |
"${PWD}/bin/${{ env.TOOL_NAME }}" --version | grep "^nightly-"

path-suggestions:
needs: configure
strategy:
fail-fast: false

matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest

runs-on: ${{ matrix.os }}

steps:
- name: Set install path environment variables
shell: bash
run: |
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
FIRST_INSTALLATION_FOLDER="first-installation-folder"
echo "FIRST_INSTALLATION_FOLDER=${FIRST_INSTALLATION_FOLDER}" >> "$GITHUB_ENV"
echo "FIRST_BINDIR=${{ runner.temp }}/${FIRST_INSTALLATION_FOLDER}" >> "$GITHUB_ENV"
SECOND_INSTALLATION_FOLDER="second-installation-folder"
echo "SECOND_INSTALLATION_FOLDER=${SECOND_INSTALLATION_FOLDER}" >> "$GITHUB_ENV"
echo "SECOND_BINDIR=${{ runner.temp }}/${SECOND_INSTALLATION_FOLDER}" >> "$GITHUB_ENV"

- name: Download script artifact
uses: actions/download-artifact@v2
with:
name: ${{ env.SCRIPT_ARTIFACT_NAME }}

- name: Make script executable
run: chmod u+x "${{ github.workspace }}/${{ env.SCRIPT_NAME }}"

- name: Check script output without previous installation in PATH
shell: sh
env:
BINDIR: ${{ env.FIRST_BINDIR }}
run: |
mkdir -p "${{ env.BINDIR }}"
"${{ github.workspace }}/${{ env.SCRIPT_NAME }}" | \
grep \
-F \
'${{ env.TOOL_NAME }} not found. You might want to add "${{ env.FIRST_BINDIR }}" to your $PATH'

- name: Add first installation to PATH
shell: bash
run: |
# See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#adding-a-system-path
echo "${{ env.FIRST_BINDIR }}" >> "$GITHUB_PATH"

- name: Check script output with previous installation in PATH (non-Windows)
if: runner.os != 'Windows'
shell: sh
env:
BINDIR: ${{ env.SECOND_BINDIR }}
run: |
mkdir -p "${{ env.BINDIR }}"
"${{ github.workspace }}/${{ env.SCRIPT_NAME }}" | \
grep \
-F \
'${{ env.TOOL_NAME }} was found at ${{ env.FIRST_BINDIR }}/${{ env.TOOL_NAME }}. Please prepend "${{ env.BINDIR }}" to your $PATH'

# ${{ runner.temp }} is a Windows style path on the windows runner, but the script output uses the equivalent POSIX style path.
# So a regex is used for the output check on Windows.
- name: Check script output with previous installation in PATH (Windows)
if: runner.os == 'Windows'
shell: sh
env:
BINDIR: ${{ env.SECOND_BINDIR }}
run: |
mkdir -p "${{ env.BINDIR }}"
"${{ github.workspace }}/${{ env.SCRIPT_NAME }}" | \
grep \
'${{ env.TOOL_NAME }} was found at .*/${{ env.FIRST_INSTALLATION_FOLDER }}/${{ env.TOOL_NAME }}\. Please prepend ".*/${{ env.SECOND_INSTALLATION_FOLDER }}" to your \$PATH'
12 changes: 6 additions & 6 deletions other/installation-script/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,19 @@ bye() {

testVersion() {
set +e
EXECUTABLE_PATH="$(command -v $PROJECT_NAME)"
if [ "$?" = "1" ]; then
# $PATH is intentionally a literal in this message.
# shellcheck disable=SC2016
echo "$PROJECT_NAME not found. You might want to add \"$EFFECTIVE_BINDIR\" to your "'$PATH'
else
if EXECUTABLE_PATH="$(command -v $PROJECT_NAME)"; then
# Convert to resolved, absolute paths before comparison
EXECUTABLE_REALPATH="$(cd -- "$(dirname -- "$EXECUTABLE_PATH")" && pwd -P)"
EFFECTIVE_BINDIR_REALPATH="$(cd -- "$EFFECTIVE_BINDIR" && pwd -P)"
if [ "$EXECUTABLE_REALPATH" != "$EFFECTIVE_BINDIR_REALPATH" ]; then
# $PATH is intentionally a literal in this message.
# shellcheck disable=SC2016
echo "An existing $PROJECT_NAME was found at $EXECUTABLE_PATH. Please prepend \"$EFFECTIVE_BINDIR\" to your "'$PATH'" or remove the existing one."
fi
else
# $PATH is intentionally a literal in this message.
# shellcheck disable=SC2016
echo "$PROJECT_NAME not found. You might want to add \"$EFFECTIVE_BINDIR\" to your "'$PATH'
fi

set -e
Expand Down